! @brief scan a number literal This function scans a string according to Sect. 6 of RFC 8259. The function is realized with a deterministic finite state machine derived from the grammar described in RFC 8259. Starting in state "init", the input is read and used to determined the next state. Only state "done" accepts the number. State "error" is a trap state to model errors. In the table b
| 8268 | locale-dependent converters. |
| 8269 | */ |
| 8270 | token_type scan_number() // lgtm [cpp/use-of-goto] |
| 8271 | { |
| 8272 | // reset token_buffer to store the number's bytes |
| 8273 | reset(); |
| 8274 | |
| 8275 | // the type of the parsed number; initially set to unsigned; will be |
| 8276 | // changed if minus sign, decimal point or exponent is read |
| 8277 | token_type number_type = token_type::value_unsigned; |
| 8278 | |
| 8279 | // state (init): we just found out we need to scan a number |
| 8280 | switch (current) |
| 8281 | { |
| 8282 | case '-': |
| 8283 | { |
| 8284 | add(current); |
| 8285 | goto scan_number_minus; |
| 8286 | } |
| 8287 | |
| 8288 | case '0': |
| 8289 | { |
| 8290 | add(current); |
| 8291 | goto scan_number_zero; |
| 8292 | } |
| 8293 | |
| 8294 | case '1': |
| 8295 | case '2': |
| 8296 | case '3': |
| 8297 | case '4': |
| 8298 | case '5': |
| 8299 | case '6': |
| 8300 | case '7': |
| 8301 | case '8': |
| 8302 | case '9': |
| 8303 | { |
| 8304 | add(current); |
| 8305 | goto scan_number_any1; |
| 8306 | } |
| 8307 | |
| 8308 | // all other characters are rejected outside scan_number() |
| 8309 | default: // LCOV_EXCL_LINE |
| 8310 | JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 8311 | } |
| 8312 | |
| 8313 | scan_number_minus: |
| 8314 | // state: we just parsed a leading minus sign |
| 8315 | number_type = token_type::value_integer; |
| 8316 | switch (get()) |
| 8317 | { |
| 8318 | case '0': |
| 8319 | { |
| 8320 | add(current); |
| 8321 | goto scan_number_zero; |
| 8322 | } |
| 8323 | |
| 8324 | case '1': |
| 8325 | case '2': |
| 8326 | case '3': |
| 8327 | case '4': |