Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

68 Zeilen
1.6 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. #include <lol/engine-internal.h>
  11. namespace lol
  12. {
  13. /*
  14. * Safe enum helpers
  15. */
  16. map<int64_t, String> BuildEnumMap(char const *str, char const **custom)
  17. {
  18. map<int64_t, String> ret;
  19. char const *parser = str;
  20. int64_t next_value = 0;
  21. int64_t cur_idx = 0;
  22. for (;;)
  23. {
  24. /* Find name */
  25. while (*parser == ' ' || *parser == ',')
  26. ++parser;
  27. if (!*parser)
  28. break;
  29. /* Parse name */
  30. char const *name = parser;
  31. while (*parser && *parser != ' ' && *parser != ',' && *parser != '=')
  32. ++parser;
  33. char const *name_end = parser;
  34. /* Find the value (if any) */
  35. uint64_t current_value = next_value;
  36. while (*parser == ' ' || *parser == '=')
  37. ++parser;
  38. if (*parser && *parser != ',')
  39. {
  40. #if defined _WIN32
  41. current_value = _strtoi64(parser, nullptr, 0);
  42. #else
  43. current_value = strtoll(parser, nullptr, 0);
  44. #endif
  45. while (*parser && *parser != ' ' && *parser != ',')
  46. ++parser;
  47. }
  48. /* Store in the map */
  49. ret[current_value] = (!custom) ? (String(name, (int)(name_end - name))) : (String(custom[cur_idx]));
  50. next_value = current_value + 1;
  51. cur_idx++;
  52. }
  53. return ret;
  54. }
  55. } /* namespace lol */