| 96 | } |
| 97 | |
| 98 | static f64 parse_number(const char *json) |
| 99 | { |
| 100 | CE_ENSURE(NULL != json); |
| 101 | |
| 102 | TempAllocator512 alloc; |
| 103 | Array<char> number(alloc); |
| 104 | |
| 105 | if (*json == '-') { |
| 106 | array::push_back(number, '-'); |
| 107 | ++json; |
| 108 | } |
| 109 | while (isdigit(*json)) { |
| 110 | array::push_back(number, *json); |
| 111 | ++json; |
| 112 | } |
| 113 | |
| 114 | if (*json == '.') { |
| 115 | array::push_back(number, '.'); |
| 116 | while (*++json && isdigit(*json)) { |
| 117 | array::push_back(number, *json); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (*json == 'e' || *json == 'E') { |
| 122 | array::push_back(number, *json); |
| 123 | ++json; |
| 124 | |
| 125 | if (*json == '-' || *json == '+') { |
| 126 | array::push_back(number, *json); |
| 127 | ++json; |
| 128 | } |
| 129 | while (isdigit(*json)) { |
| 130 | array::push_back(number, *json); |
| 131 | ++json; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | CE_ASSERT(array::size(number) != 0, "Invalid number"); |
| 136 | array::push_back(number, '\0'); |
| 137 | |
| 138 | errno = 0; |
| 139 | f64 val = strtod(array::begin(number), NULL); |
| 140 | CE_ASSERT(errno != ERANGE && errno != EINVAL, "Failed to parse f64: %s", array::begin(number)); |
| 141 | return val; |
| 142 | } |
| 143 | |
| 144 | s32 parse_int(const char *json) |
| 145 | { |
no test coverage detected