better character escapes in C code: oct works better than hex, escape line ending...
authorStefan Behnel <scoder@users.berlios.de>
Sun, 10 Aug 2008 18:31:04 +0000 (20:31 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 10 Aug 2008 18:31:04 +0000 (20:31 +0200)
Cython/Utils.py

index 5a23b58e5f83afe11d1be3bc8560e78cecdda797..4ab111b2193e3a78209388062f59f12583ccc7c9 100644 (file)
@@ -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)