JSON.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "Assert.h"
  2. #include "JSON.h"
  3. #include "Types.h"
  4. namespace crown
  5. {
  6. /// This function is EPIC. Love it. Now.
  7. //-----------------------------------------------------------------------------
  8. CE_EXPORT void JSON::next(const char* str, const char c, bool force_reset)
  9. {
  10. static char* current_str = (char*)str;
  11. static size_t index = 0;
  12. static char current = str[index];
  13. if (current_str != str || force_reset == true)
  14. {
  15. current_str = (char*)str;
  16. index = 0;
  17. current = str[index];
  18. }
  19. if (c && c != current)
  20. {
  21. CE_ASSERT(false, "Expected '%c' got '%c'", c, current);
  22. }
  23. index++;
  24. current = str[index];
  25. }
  26. //-----------------------------------------------------------------------------
  27. CE_EXPORT bool JSON::parse_bool(const char* token)
  28. {
  29. CE_ASSERT_NOT_NULL(token);
  30. switch(token[0])
  31. {
  32. case 't':
  33. {
  34. next(token, 't');
  35. next(token, 'r');
  36. next(token, 'u');
  37. next(token, 'e');
  38. return true;
  39. }
  40. case 'f':
  41. {
  42. next(token, 'f');
  43. next(token, 'a');
  44. next(token, 'l');
  45. next(token, 's');
  46. next(token, 'e');
  47. return false;
  48. }
  49. default:
  50. {
  51. CE_ASSERT(false, "Current token is not a boolean");
  52. }
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. CE_EXPORT int32_t JSON::parse_int(const char* token)
  57. {
  58. // uint32_t index = 0;
  59. // uint32_t start = index;
  60. // uint32_t end = -1;
  61. // while(token[index] != '\0' || end == -1)
  62. // {
  63. // switch(token[index])
  64. // {
  65. // case '-':
  66. // {
  67. // }
  68. // case '0':
  69. // case '1':
  70. // case '2':
  71. // case '3':
  72. // case '4':
  73. // case '5':
  74. // case '6':
  75. // case '7':
  76. // case '8':
  77. // case '9':
  78. // {
  79. // index++;
  80. // }
  81. // case '\t':
  82. // case '\r':
  83. // case '\n':
  84. // case ' ':
  85. // case ',':
  86. // case '}':
  87. // case ']':
  88. // {
  89. // end = index - 1;
  90. // }
  91. // }
  92. // }
  93. }
  94. //-----------------------------------------------------------------------------
  95. CE_EXPORT float JSON::parse_float(const char* token)
  96. {
  97. }
  98. // //-----------------------------------------------------------------------------
  99. // void JSON::parse_string(const char* token, List<char>& str)
  100. // {
  101. // }
  102. // //-----------------------------------------------------------------------------
  103. // void JSON::parse_array(const char* token, List<const char*>& array)
  104. // {
  105. // }
  106. // //-----------------------------------------------------------------------------
  107. // void JSON::parse_object(const char* token, Dictionary<const char* key, const char* val>& dict)
  108. // {
  109. // }
  110. } // namespace crown