Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

72 строки
1.7 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. namespace lol
  15. {
  16. /*
  17. * Safe enum helpers
  18. */
  19. Map<int64_t, String> BuildEnumMap(char const *str, char const **custom)
  20. {
  21. Map<int64_t, String> ret;
  22. char const *parser = str;
  23. int64_t next_value = 0;
  24. int64_t cur_idx = 0;
  25. for (;;)
  26. {
  27. /* Find name */
  28. while (*parser == ' ' || *parser == ',')
  29. ++parser;
  30. if (!*parser)
  31. break;
  32. /* Parse name */
  33. char const *name = parser;
  34. while (*parser && *parser != ' ' && *parser != ',' && *parser != '=')
  35. ++parser;
  36. char const *name_end = parser;
  37. /* Find the value (if any) */
  38. uint64_t current_value = next_value;
  39. while (*parser == ' ' || *parser == '=')
  40. ++parser;
  41. if (*parser && *parser != ',')
  42. {
  43. #if defined _WIN32
  44. current_value = _strtoi64(parser, nullptr, 0);
  45. #else
  46. current_value = strtoll(parser, nullptr, 0);
  47. #endif
  48. while (*parser && *parser != ' ' && *parser != ',')
  49. ++parser;
  50. }
  51. /* Store in the map */
  52. ret[current_value] = (!custom) ? (String(name, (int)(name_end - name))) : (String(custom[cur_idx]));
  53. next_value = current_value + 1;
  54. cur_idx++;
  55. }
  56. return ret;
  57. }
  58. } /* namespace lol */