MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / scan

Function scan

lesson6-Segmentation/json.hpp:7380–7466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7378 }
7379
7380 token_type scan()
7381 {
7382 // initially, skip the BOM
7383 if (position.chars_read_total == 0 && !skip_bom())
7384 {
7385 error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
7386 return token_type::parse_error;
7387 }
7388
7389 // read next character and ignore whitespace
7390 skip_whitespace();
7391
7392 // ignore comments
7393 while (ignore_comments && current == '/')
7394 {
7395 if (!scan_comment())
7396 {
7397 return token_type::parse_error;
7398 }
7399
7400 // skip following whitespace
7401 skip_whitespace();
7402 }
7403
7404 switch (current)
7405 {
7406 // structural characters
7407 case '[':
7408 return token_type::begin_array;
7409 case ']':
7410 return token_type::end_array;
7411 case '{':
7412 return token_type::begin_object;
7413 case '}':
7414 return token_type::end_object;
7415 case ':':
7416 return token_type::name_separator;
7417 case ',':
7418 return token_type::value_separator;
7419
7420 // literals
7421 case 't':
7422 {
7423 std::array<char_type, 4> true_literal = {{'t', 'r', 'u', 'e'}};
7424 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
7425 }
7426 case 'f':
7427 {
7428 std::array<char_type, 5> false_literal = {{'f', 'a', 'l', 's', 'e'}};
7429 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
7430 }
7431 case 'n':
7432 {
7433 std::array<char_type, 4> null_literal = {{'n', 'u', 'l', 'l'}};
7434 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
7435 }
7436
7437 // string

Callers

nothing calls this directly

Calls 4

skip_bomFunction · 0.85
skip_whitespaceFunction · 0.85
dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected