♻️ pull code into function
This commit is contained in:
parent
3bb43ecd51
commit
88122467bd
2 changed files with 100 additions and 90 deletions
|
@ -2003,51 +2003,7 @@ class binary_reader
|
|||
|
||||
case 'H':
|
||||
{
|
||||
// get size of following number string
|
||||
std::size_t size{};
|
||||
auto res = get_ubjson_size_value(size);
|
||||
if (JSON_HEDLEY_UNLIKELY(!res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
// get number string
|
||||
std::vector<char> number_vector;
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
number_vector.push_back(static_cast<char>(current));
|
||||
}
|
||||
|
||||
// parse number string
|
||||
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
|
||||
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia), false);
|
||||
const auto result_number = number_lexer.scan();
|
||||
const auto number_string = number_lexer.get_token_string();
|
||||
const auto result_remainder = number_lexer.scan();
|
||||
|
||||
using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
||||
{
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
|
||||
switch (result_number)
|
||||
{
|
||||
case token_type::value_integer:
|
||||
return sax->number_integer(number_lexer.get_number_integer());
|
||||
case token_type::value_unsigned:
|
||||
return sax->number_unsigned(number_lexer.get_number_unsigned());
|
||||
case token_type::value_float:
|
||||
return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
|
||||
default:
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
return get_ubjson_high_precision_number();
|
||||
}
|
||||
|
||||
case 'C': // char
|
||||
|
@ -2226,6 +2182,55 @@ class binary_reader
|
|||
// Note, no reader for UBJSON binary types is implemented because they do
|
||||
// not exist
|
||||
|
||||
bool get_ubjson_high_precision_number()
|
||||
{
|
||||
// get size of following number string
|
||||
std::size_t size{};
|
||||
auto res = get_ubjson_size_value(size);
|
||||
if (JSON_HEDLEY_UNLIKELY(!res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
// get number string
|
||||
std::vector<char> number_vector;
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
number_vector.push_back(static_cast<char>(current));
|
||||
}
|
||||
|
||||
// parse number string
|
||||
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
|
||||
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia), false);
|
||||
const auto result_number = number_lexer.scan();
|
||||
const auto number_string = number_lexer.get_token_string();
|
||||
const auto result_remainder = number_lexer.scan();
|
||||
|
||||
using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
||||
{
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
|
||||
switch (result_number)
|
||||
{
|
||||
case token_type::value_integer:
|
||||
return sax->number_integer(number_lexer.get_number_integer());
|
||||
case token_type::value_unsigned:
|
||||
return sax->number_unsigned(number_lexer.get_number_unsigned());
|
||||
case token_type::value_float:
|
||||
return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
|
||||
default:
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
// Utility functions //
|
||||
///////////////////////
|
||||
|
|
|
@ -9616,51 +9616,7 @@ class binary_reader
|
|||
|
||||
case 'H':
|
||||
{
|
||||
// get size of following number string
|
||||
std::size_t size{};
|
||||
auto res = get_ubjson_size_value(size);
|
||||
if (JSON_HEDLEY_UNLIKELY(!res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
// get number string
|
||||
std::vector<char> number_vector;
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
number_vector.push_back(static_cast<char>(current));
|
||||
}
|
||||
|
||||
// parse number string
|
||||
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
|
||||
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia), false);
|
||||
const auto result_number = number_lexer.scan();
|
||||
const auto number_string = number_lexer.get_token_string();
|
||||
const auto result_remainder = number_lexer.scan();
|
||||
|
||||
using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
||||
{
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
|
||||
switch (result_number)
|
||||
{
|
||||
case token_type::value_integer:
|
||||
return sax->number_integer(number_lexer.get_number_integer());
|
||||
case token_type::value_unsigned:
|
||||
return sax->number_unsigned(number_lexer.get_number_unsigned());
|
||||
case token_type::value_float:
|
||||
return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
|
||||
default:
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
return get_ubjson_high_precision_number();
|
||||
}
|
||||
|
||||
case 'C': // char
|
||||
|
@ -9839,6 +9795,55 @@ class binary_reader
|
|||
// Note, no reader for UBJSON binary types is implemented because they do
|
||||
// not exist
|
||||
|
||||
bool get_ubjson_high_precision_number()
|
||||
{
|
||||
// get size of following number string
|
||||
std::size_t size{};
|
||||
auto res = get_ubjson_size_value(size);
|
||||
if (JSON_HEDLEY_UNLIKELY(!res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
// get number string
|
||||
std::vector<char> number_vector;
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
get();
|
||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
number_vector.push_back(static_cast<char>(current));
|
||||
}
|
||||
|
||||
// parse number string
|
||||
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
|
||||
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia), false);
|
||||
const auto result_number = number_lexer.scan();
|
||||
const auto number_string = number_lexer.get_token_string();
|
||||
const auto result_remainder = number_lexer.scan();
|
||||
|
||||
using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
|
||||
{
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
|
||||
switch (result_number)
|
||||
{
|
||||
case token_type::value_integer:
|
||||
return sax->number_integer(number_lexer.get_number_integer());
|
||||
case token_type::value_unsigned:
|
||||
return sax->number_unsigned(number_lexer.get_number_unsigned());
|
||||
case token_type::value_float:
|
||||
return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
|
||||
default:
|
||||
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number")));
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
// Utility functions //
|
||||
///////////////////////
|
||||
|
|
Loading…
Reference in a new issue