1
0

int_switch_to_dict_literal.py 556 B

123456789101112131415
  1. import re
  2. case_pattern = re.compile(r"case\s(?P<name>[^:]*):\s*.*?new GUIContent\((?P<val>\"[^\"]*\")\);")
  3. name_pattern = re.compile(r"\{(?P<key>[^,]*),\s(?P<tmp>\d*)\}")
  4. with open("input.txt", "r", encoding="utf-8") as f:
  5. with open("result.txt", "w", encoding="utf-8") as fo:
  6. helper = {}
  7. t = f.read()
  8. for m in name_pattern.finditer(t):
  9. helper[m.group("tmp")] = m.group("key")
  10. for m in case_pattern.finditer(t):
  11. k = helper[m.group("name")]
  12. fo.write(f"[{k}] = {m.group('val')},\n")