From 8a29081dcee9900a8a699c444f25cc1c02143444 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 11 Jan 2010 23:32:06 +0000 Subject: [PATCH] Fix unicode quote handling to work with python3. svn path=/main/trunk/; revision=15195 --- bin/check-implicit-pointer-usage.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/check-implicit-pointer-usage.py b/bin/check-implicit-pointer-usage.py index 179e73d23..ebd4c3629 100755 --- a/bin/check-implicit-pointer-usage.py +++ b/bin/check-implicit-pointer-usage.py @@ -21,7 +21,7 @@ import sys implicit_pattern = re.compile("([^:]*):(\d+): warning: implicit declaration " + "of function [`']([^']*)'") -pointer_pattern = re.compile( +pointer_pattern = ( "([^:]*):(\d+): warning: " + "(" + "(assignment" @@ -32,6 +32,16 @@ pointer_pattern = re.compile( + ") makes pointer from integer without a cast" + "|" + "cast to pointer from integer of different size)") + +if sys.hexversion < 0x3000000: + pointer_pattern = unicode(pointer_pattern, encoding='utf_8') + unicode_quote_open = unicode('\xE2\x80\x98', encoding='utf_8') + unicode_quote_close = unicode('\xE2\x80\x99', encoding='utf_8') +else: + unicode_quote_open = '\u2018' + unicode_quote_close = '\u2019' +pointer_pattern = re.compile(pointer_pattern) + last_implicit_filename = "" last_implicit_linenum = -1 last_implicit_func = "" @@ -40,11 +50,13 @@ while True: if sys.hexversion >= 0x3000000: line = sys.stdin.buffer.readline().decode('utf_8', 'replace') else: - line = sys.stdin.readline() - if line == '': + line = unicode(sys.stdin.readline(), + encoding='utf_8', errors='replace') + if not line: break # translate unicode open/close quotes to ascii ones - line = line.replace("\xE2\x80\x98", "`").replace("\xE2\x80\x99", "'") + line = line.replace(unicode_quote_open, "`") + line = line.replace(unicode_quote_close, "'") m = implicit_pattern.match(line) if m: last_implicit_filename = m.group(1) -- 2.26.2