MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / scan_number

Method scan_number

include/behaviortree_cpp/contrib/json.hpp:8341–8664  ·  view source on GitHub ↗

! @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 error

Source from the content-addressed store, hash-verified

8339 locale-dependent converters.
8340 */
8341 token_type scan_number() // lgtm [cpp/use-of-goto]
8342 {
8343 // reset token_buffer to store the number's bytes
8344 reset();
8345
8346 // the type of the parsed number; initially set to unsigned; will be
8347 // changed if minus sign, decimal point or exponent is read
8348 token_type number_type = token_type::value_unsigned;
8349
8350 // state (init): we just found out we need to scan a number
8351 switch (current)
8352 {
8353 case '-':
8354 {
8355 add(current);
8356 goto scan_number_minus;
8357 }
8358
8359 case '0':
8360 {
8361 add(current);
8362 goto scan_number_zero;
8363 }
8364
8365 case '1':
8366 case '2':
8367 case '3':
8368 case '4':
8369 case '5':
8370 case '6':
8371 case '7':
8372 case '8':
8373 case '9':
8374 {
8375 add(current);
8376 goto scan_number_any1;
8377 }
8378
8379 // all other characters are rejected outside scan_number()
8380 default: // LCOV_EXCL_LINE
8381 JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
8382 }
8383
8384scan_number_minus:
8385 // state: we just parsed a leading minus sign
8386 number_type = token_type::value_integer;
8387 switch (get())
8388 {
8389 case '0':
8390 {
8391 add(current);
8392 goto scan_number_zero;
8393 }
8394
8395 case '1':
8396 case '2':
8397 case '3':
8398 case '4':

Callers

nothing calls this directly

Calls 6

resetFunction · 0.85
addFunction · 0.85
ungetFunction · 0.85
getFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected