genutils.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. #include "genutils.hpp"
  2. #include <set>
  3. #include <string>
  4. static std::set<std::string> reserved{"alignas", "alignof", "and", "and_eq",
  5. "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto",
  6. "bitand", "bitor", "bool", "break", "case", "catch", "char", "char16_t",
  7. "char32_t", "class", "compl", "concept", "const", "constexpr", "const_cast",
  8. "continue", "co_await", "co_return", "co_yield", "decltype", "default",
  9. "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit",
  10. "export", "extern", "false", "float", "for", "friend", "goto", "if",
  11. "import", "inline", "int", "long", "module", "mutable", "namespace", "new",
  12. "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq",
  13. "private", "protected", "public", "register", "reflexpr",
  14. "reinterpret_cast", "requires", "return", "short", "signed", "sizeof",
  15. "static", "static_assert", "static_cast", "struct", "switch",
  16. "synchronized", "template", "this", "thread_local", "throw", "true", "try",
  17. "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual",
  18. "void", "volatile", "wchar_t", "while", "xor", "xor_eq"};
  19. std::string
  20. unreserve(const std::string &s, bool force)
  21. {
  22. auto res(s);
  23. if (!s.empty() && isdigit(s[0]))
  24. res.insert(res.begin(), '_');
  25. else if (reserved.find(s) != reserved.end() || toupper(s) == s || force)
  26. res += "_";
  27. return res;
  28. }