Implement encoding LLVM strings.

This commit is contained in:
cfreksen 2017-10-30 01:32:35 +01:00
parent 7cd2560956
commit 0536c7e683
No known key found for this signature in database
GPG Key ID: EAC13EE101008978
1 changed files with 14 additions and 3 deletions

17
ll.py
View File

@ -217,6 +217,17 @@ def gdecl2s(gdecl):
.format(gdecl.name, ty2s(gdecl.ty), ginit2s(gdecl.body)))
def ll_encode(s):
# TODO
return s
def ll_encode(string):
res_l = []
for c in string:
code = ord(c)
if code <= 31 or code == 127:
res_l.append('\{:02X}'.format(code))
elif c == '\\':
res_l.append('\\\\')
elif c == '"':
res_l.append('\\22')
else:
res_l.append(c)
return ''.join(res_l)