TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ scan()

template<typename BasicJsonType , typename InputAdapterType >
token_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan ( )
inline

Definition at line 8116 of file json.hpp.

8117 {
8118 // initially, skip the BOM
8119 if (position.chars_read_total == 0 && !skip_bom())
8120 {
8121 error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
8122 return token_type::parse_error;
8123 }
8124
8125 // read next character and ignore whitespace
8126 skip_whitespace();
8127
8128 // ignore comments
8129 while (ignore_comments && current == '/')
8130 {
8131 if (!scan_comment())
8132 {
8133 return token_type::parse_error;
8134 }
8135
8136 // skip following whitespace
8137 skip_whitespace();
8138 }
8139
8140 switch (current)
8141 {
8142 // structural characters
8143 case '[':
8144 return token_type::begin_array;
8145
8146 case ']':
8147 return token_type::end_array;
8148
8149 case '{':
8150 return token_type::begin_object;
8151
8152 case '}':
8153 return token_type::end_object;
8154
8155 case ':':
8156 return token_type::name_separator;
8157
8158 case ',':
8159 return token_type::value_separator;
8160
8161 // literals
8162 case 't':
8163 {
8164 std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
8165 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8166 }
8167
8168 case 'f':
8169 {
8170 std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
8171 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8172 }
8173
8174 case 'n':
8175 {
8176 std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
8177 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8178 }
8179
8180 // string
8181 case '\"':
8182 return scan_string();
8183
8184 // number
8185 case '-':
8186 case '0':
8187 case '1':
8188 case '2':
8189 case '3':
8190 case '4':
8191 case '5':
8192 case '6':
8193 case '7':
8194 case '8':
8195 case '9':
8196 return scan_number();
8197
8198 // end of input (the null byte is needed when parsing from
8199 // string literals)
8200 case '\0':
8201 case std::char_traits<char_type>::eof():
8202 return token_type::end_of_input;
8203
8204 // error
8205 default:
8206 error_message = "invalid literal";
8207 return token_type::parse_error;
8208 }
8209 }
const bool ignore_comments
whether comments should be ignored (true) or signaled as errors (false)
Definition: json.hpp:8216
char_int_type current
the current character
Definition: json.hpp:8219
bool skip_bom()
skip the UTF-8 byte order mark
Definition: json.hpp:8093
const char * error_message
a description of occurred lexer errors
Definition: json.hpp:8234
position_t position
the start position of the current token
Definition: json.hpp:8225
token_type scan_number()
scan a number literal
Definition: json.hpp:7566
token_type scan_string()
scan a string literal
Definition: json.hpp:6839
token_type scan_literal(const char_type *literal_text, const std::size_t length, token_type return_type)
Definition: json.hpp:7902
bool scan_comment()
scan a comment
Definition: json.hpp:7441
std::size_t chars_read_total
the total number of characters read
Definition: json.hpp:2594