def formatString(self, text, stats, not_found_replacement = None):
#try:
values = stats['values']
for m in re.finditer("{{([gc]:)?([^}:]*)((:d)|(:1f)|:(\d+)|:(\d+)\.(\d+)f|(:\+d)|(:\+1f))?}}", text):
g, g1, key, g2, sg1, sg2, sg3, sg4a, sg4b, sg5, sg6 = m.group(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
if not key in values:
if not_found_replacement is None:
if d: LOG_NOTE('No key in values of %s (%s)' % (stats.get('_type', 'unknown'), key))
else:
text = text.replace('%s' % g, not_found_replacement)
elif g1 is None:
if g2 is None:
text = text.replace('{{%s}}' % key, self.applyMacros(values[key]))
elif sg1:
text = text.replace('{{%s:d}}' % key, self.applyMacros(values[key], 0))
elif sg2:
text = text.replace('{{%s:1f}}' % key, self.applyMacros(values[key], 1))
elif sg3:
xx = int(sg3)
text = text.replace('{{%s:%d}}' % (key, xx), self.applyMacros2(values[key], xx))
elif sg4a:
xx, yy = int(sg4a), int(sg4b)
text = text.replace('{{%s:%d.%df}}' % (key, xx, yy), self.applyMacros2(values[key], xx, yy))
elif sg5:
text = text.replace('{{%s:+d}}' % key, self.applyMacros(values[key], 0, '+'))
elif sg6:
text = text.replace('{{%s:+1f}}' % key, self.applyMacros(values[key], 1, '+'))
elif g1=="g:":
text = text.replace('{{g:%s}}' % key, stats['gradient'][key])
elif g1=="c:":
text = text.replace('{{c:%s}}' % key, stats['palette'][key])
#except:
# LOG_CURRENT_EXCEPTION()
#finally:
return text
评论列表
文章目录