2
0

utils.py 944 B

12345678910111213141516171819202122232425262728293031
  1. LANGUAGE_TAG = {
  2. "c++" : "// C++",
  3. "c" : "// C",
  4. "c#" : "// C#",
  5. "go" : "// Go",
  6. "java" : "// Java",
  7. "javascript" : "// JavaScript",
  8. "kotlin" : "// Kotlin",
  9. "php" : "// PHP",
  10. "python" : "# Python",
  11. "rust" : "// Rust",
  12. "ruby" : "# Ruby",
  13. "typescript" : "// TypeScript",
  14. }
  15. def code_generation_end(code, language):
  16. if language.lower() == 'python':
  17. end_words = ["\ndef", "\nclass", "\nif", "\n#", "\nprint", "\nassert"]
  18. for w in end_words:
  19. if w in code:
  20. return True
  21. return False
  22. def cleanup_code(code, language):
  23. if language.lower() == "python":
  24. end_words = ["\ndef", "\nclass", "\nif", "\n#", "\nprint", "\nassert"]
  25. for w in end_words:
  26. if w in code:
  27. code = code[:code.rfind(w)].rstrip()
  28. return code