From: Stefan Behnel Date: Sun, 10 Aug 2008 18:31:04 +0000 (+0200) Subject: better character escapes in C code: oct works better than hex, escape line ending... X-Git-Tag: 0.9.8.1~72 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fcdc2a7217cab02148f9f92b11f189079936314f;p=cython.git better character escapes in C code: oct works better than hex, escape line ending characters --- diff --git a/Cython/Utils.py b/Cython/Utils.py index 5a23b58e..4ab111b2 100644 --- a/Cython/Utils.py +++ b/Cython/Utils.py @@ -100,7 +100,7 @@ class EncodedString(unicode): # getattr(other, 'encoding', '') == self.encoding def escape_byte_string(s): - s = s.replace('\0', r'\x00') + s = s.replace('\0', r'\000').replace('\x0A', r'\012').replace('\x0C', r'\014') try: s.decode("ASCII") return s @@ -111,7 +111,7 @@ def escape_byte_string(s): for c in s: o = ord(c) if o >= 128: - append('\\x%X' % o) + append('\\%3o' % o) else: append(c) return ''.join(l)