Skip to content
Snippets Groups Projects

Some characters apparently need long 8-byte encoding

Merged Andrzej Lisak requested to merge escaping_fix2 into develop
2 files
+ 16
12
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 15
11
@@ -78,19 +78,23 @@ def escape_characters(text):
@@ -78,19 +78,23 @@ def escape_characters(text):
if ch in SPECIAL_CHARS:
if ch in SPECIAL_CHARS:
dw = SPECIAL_CHARS[ch]
dw = SPECIAL_CHARS[ch]
ret = ret + dw
ret = ret + dw
elif ch.isprintable():
ret = ret + ch
else:
else:
# escaped_value = ch.encode('unicode-escape').decode('utf-8')
ordinal = ord(ch)
ordinal = ord(ch)
hexstr = hex(ordinal)[2:]
if ordinal <= 0x80 and ch.isprintable():
escaped_value = '\\u'
ret = ret + ch
i = len(hexstr)
else:
while i < 4:
hexstr = hex(ordinal)[2:]
escaped_value += '0'
i = len(hexstr)
i += 1
max = 4
escaped_value += hexstr
escaped_value = '\\u'
ret = ret + escaped_value
if i > max:
 
max = 8
 
escaped_value = '\\U'
 
while i < max:
 
escaped_value += '0'
 
i += 1
 
escaped_value += hexstr
 
ret = ret + escaped_value
ret = ret + "'"
ret = ret + "'"
return ret
return ret
Loading