| Index: tools/js2c.py
|
| diff --git a/tools/js2c.py b/tools/js2c.py
|
| index d91513311429a87b3fe5731d82feac6ddecfb493..b676d662e773e281830f6471b04284ec62cefe1c 100755
|
| --- a/tools/js2c.py
|
| +++ b/tools/js2c.py
|
| @@ -145,10 +145,12 @@ class TextMacro:
|
| self.args = args
|
| self.body = body
|
| def expand(self, mapping):
|
| - result = self.body
|
| - for key, value in mapping.items():
|
| - result = result.replace(key, value)
|
| - return result
|
| + # Keys could be substrings of earlier values. To avoid unintended
|
| + # clobbering, apply all replacements simultaneously.
|
| + any_key_pattern = "|".join(re.escape(k) for k in mapping.iterkeys())
|
| + def replace(match):
|
| + return mapping[match.group(0)]
|
| + return re.sub(any_key_pattern, replace, self.body)
|
|
|
| class PythonMacro:
|
| def __init__(self, args, fun):
|
|
|