MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / scan_number

Method scan_number

Source/Utils/json.hpp:6840–7163  ·  view source on GitHub ↗

! @brief scan a number literal This function scans a string according to Sect. 6 of RFC 7159. The function is realized with a deterministic finite state machine derived from the grammar described in RFC 7159. Starting in state "init", the input is read and used to determined the next state. Only state "done" accepts the numb

Source from the content-addressed store, hash-verified

6838 locale-dependent converters.
6839 */
6840 token_type scan_number() // lgtm [cpp/use-of-goto]
6841 {
6842 // reset token_buffer to store the number's bytes
6843 reset();
6844
6845 // the type of the parsed number; initially set to unsigned; will be
6846 // changed if minus sign, decimal point or exponent is read
6847 token_type number_type = token_type::value_unsigned;
6848
6849 // state (init): we just found out we need to scan a number
6850 switch (current)
6851 {
6852 case '-':
6853 {
6854 add(current);
6855 goto scan_number_minus;
6856 }
6857
6858 case '0':
6859 {
6860 add(current);
6861 goto scan_number_zero;
6862 }
6863
6864 case '1':
6865 case '2':
6866 case '3':
6867 case '4':
6868 case '5':
6869 case '6':
6870 case '7':
6871 case '8':
6872 case '9':
6873 {
6874 add(current);
6875 goto scan_number_any1;
6876 }
6877
6878 // all other characters are rejected outside scan_number()
6879 default: // LCOV_EXCL_LINE
6880 JSON_ASSERT(false); // LCOV_EXCL_LINE
6881 }
6882
6883 scan_number_minus:
6884 // state: we just parsed a leading minus sign
6885 number_type = token_type::value_integer;
6886 switch (get())
6887 {
6888 case '0':
6889 {
6890 add(current);
6891 goto scan_number_zero;
6892 }
6893
6894 case '1':
6895 case '2':
6896 case '3':
6897 case '4':

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected