提交 27c1ed7b authored 作者: Ian Goodfellow's avatar Ian Goodfellow

new function in strutil for making C code look nice even though it was generated…

new function in strutil for making C code look nice even though it was generated programmatically with the wrong indentation
上级 96a8432a
......@@ -13,3 +13,32 @@ def renderString(string, dict):
i+=1
assert False
return finalCode
#
def pretty_format(string):
lines = string.split('\n')
lines = [ strip_leading_white_space(line) for line in lines ]
indent = 0
for i in xrange(len(lines)):
indent -= lines[i].count('}')
if indent < 0:
indent = 0
#
lines[i] = (' '*indent) + lines[i]
indent += lines[i].count('{')
#
rval = '\n'.join(lines)
return rval
#
def strip_leading_white_space(line):
while len(line) >0 and (line[0]==' ' or line[0]=='\t'):
line = line[1:]
#
return line
#
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论