fix additional warnings and errors for clang and msvc

This commit is contained in:
Qianqian Fang 2022-02-17 11:11:36 -05:00
parent 76ee885fd2
commit 4985323bb7
3 changed files with 120 additions and 120 deletions

View File

@ -95,16 +95,16 @@ class binary_reader
@return whether parsing was successful @return whether parsing was successful
*/ */
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
bool sax_parse(const input_format_t format_, bool sax_parse(const input_format_t format,
json_sax_t* sax_, json_sax_t* sax_,
const bool strict = true, const bool strict = true,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
{ {
sax = sax_; sax = sax_;
format = format_; input_format = format;
bool result = false; bool result = false;
switch (format) switch (input_format)
{ {
case input_format_t::bson: case input_format_t::bson:
result = parse_bson_internal(); result = parse_bson_internal();
@ -131,7 +131,7 @@ class binary_reader
// strict mode: next byte must be EOF // strict mode: next byte must be EOF
if (result && strict) if (result && strict)
{ {
if (format == input_format_t::ubjson || format == input_format_t::bjdata) if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
{ {
get_ignore_noop(); get_ignore_noop();
} }
@ -143,7 +143,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
exception_message(format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr));
} }
} }
@ -1846,7 +1846,7 @@ class binary_reader
get(); // TODO(niels): may we ignore N here? get(); // TODO(niels): may we ignore N here?
} }
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "value"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
{ {
return false; return false;
} }
@ -1856,58 +1856,58 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t len{}; std::uint8_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'i': case 'i':
{ {
std::int8_t len{}; std::int8_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'I': case 'I':
{ {
std::int16_t len{}; std::int16_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'l': case 'l':
{ {
std::int32_t len{}; std::int32_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'L': case 'L':
{ {
std::int64_t len{}; std::int64_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
default: default:
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (current) switch (current)
{ {
case 'u': case 'u':
{ {
uint16_t len; uint16_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'm': case 'm':
{ {
uint32_t len; uint32_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'M': case 'M':
{ {
uint64_t len; uint64_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
} }
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("expected length type specification (U, i, I, l, L); last byte: 0x", last_token), "string"), nullptr)); exception_message(input_format, concat("expected length type specification (U, i, I, l, L); last byte: 0x", last_token), "string"), nullptr));
} }
} }
@ -1990,7 +1990,7 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t number{}; std::uint8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2001,7 +2001,7 @@ class binary_reader
case 'i': case 'i':
{ {
std::int8_t number{}; std::int8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2012,7 +2012,7 @@ class binary_reader
case 'I': case 'I':
{ {
std::int16_t number{}; std::int16_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2023,7 +2023,7 @@ class binary_reader
case 'l': case 'l':
{ {
std::int32_t number{}; std::int32_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2034,7 +2034,7 @@ class binary_reader
case 'L': case 'L':
{ {
std::int64_t number{}; std::int64_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2044,14 +2044,14 @@ class binary_reader
default: default:
{ {
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (prefix) switch (prefix)
{ {
case 'u': case 'u':
{ {
uint16_t number; uint16_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2061,7 +2061,7 @@ class binary_reader
case 'm': case 'm':
{ {
uint32_t number; uint32_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2071,7 +2071,7 @@ class binary_reader
case 'M': case 'M':
{ {
uint64_t number; uint64_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -2099,7 +2099,7 @@ class binary_reader
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("expected length type specification (U, i, I, l, L) after '#'; last byte: 0x", last_token), "size"), nullptr)); exception_message(input_format, concat("expected length type specification (U, i, I, l, L) after '#'; last byte: 0x", last_token), "size"), nullptr));
} }
} }
} }
@ -2124,7 +2124,7 @@ class binary_reader
if (current == '$') if (current == '$')
{ {
result.second = get(); // must not ignore 'N', because 'N' maybe the type result.second = get(); // must not ignore 'N', because 'N' maybe the type
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "type"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type")))
{ {
return false; return false;
} }
@ -2132,13 +2132,13 @@ class binary_reader
get_ignore_noop(); get_ignore_noop();
if (JSON_HEDLEY_UNLIKELY(current != '#')) if (JSON_HEDLEY_UNLIKELY(current != '#'))
{ {
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "value"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
{ {
return false; return false;
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
exception_message(format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr));
} }
return get_ubjson_size_value(result.first); return get_ubjson_size_value(result.first);
@ -2161,7 +2161,7 @@ class binary_reader
switch (prefix) switch (prefix)
{ {
case std::char_traits<char_type>::eof(): // EOF case std::char_traits<char_type>::eof(): // EOF
return unexpect_eof(format, "value"); return unexpect_eof(input_format, "value");
case 'T': // true case 'T': // true
return sax->boolean(true); return sax->boolean(true);
@ -2174,43 +2174,43 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t number{}; std::uint8_t number{};
return get_number(format, number) && sax->number_unsigned(number); return get_number(input_format, number) && sax->number_unsigned(number);
} }
case 'i': case 'i':
{ {
std::int8_t number{}; std::int8_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'I': case 'I':
{ {
std::int16_t number{}; std::int16_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'l': case 'l':
{ {
std::int32_t number{}; std::int32_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'L': case 'L':
{ {
std::int64_t number{}; std::int64_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'd': case 'd':
{ {
float number{}; float number{};
return get_number(format, number) && sax->number_float(static_cast<number_float_t>(number), ""); return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'D': case 'D':
{ {
double number{}; double number{};
return get_number(format, number) && sax->number_float(static_cast<number_float_t>(number), ""); return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'H': case 'H':
@ -2221,7 +2221,7 @@ class binary_reader
case 'C': // char case 'C': // char
{ {
get(); get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "char"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "char")))
{ {
return false; return false;
} }
@ -2229,7 +2229,7 @@ class binary_reader
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr));
} }
string_t s(1, static_cast<typename string_t::value_type>(current)); string_t s(1, static_cast<typename string_t::value_type>(current));
return sax->string(s); return sax->string(s);
@ -2249,34 +2249,34 @@ class binary_reader
default: // anything else default: // anything else
{ {
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (prefix) switch (prefix)
{ {
case 'u': case 'u':
{ {
uint16_t number; uint16_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'm': case 'm':
{ {
uint32_t number; uint32_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'M': case 'M':
{ {
uint64_t number; uint64_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'h': case 'h':
{ {
const int byte2 = get(); const int byte2 = get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "half"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "half")))
{ {
return false; return false;
} }
const int byte1 = get(); const int byte1 = get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "half"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "half")))
{ {
return false; return false;
} }
@ -2316,7 +2316,7 @@ class binary_reader
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
exception_message(format, concat("invalid byte: 0x", last_token), "value"), nullptr)); exception_message(input_format, concat("invalid byte: 0x", last_token), "value"), nullptr));
} }
} }
} }
@ -2476,7 +2476,7 @@ class binary_reader
for (std::size_t i = 0; i < size; ++i) for (std::size_t i = 0; i < size; ++i)
{ {
get(); get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number")))
{ {
return false; return false;
} }
@ -2495,7 +2495,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) 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, return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
exception_message(format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
} }
switch (result_number) switch (result_number)
@ -2522,7 +2522,7 @@ class binary_reader
case token_type::literal_or_value: case token_type::literal_or_value:
default: default:
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
exception_message(format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
} }
} }
@ -2586,7 +2586,7 @@ class binary_reader
} }
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
if ((is_little_endian != InputIsLittleEndian && format != input_format_t::bjdata) or if ((is_little_endian != InputIsLittleEndian && format != input_format_t::bjdata) ||
(is_little_endian == InputIsLittleEndian && format == input_format_t::bjdata)) (is_little_endian == InputIsLittleEndian && format == input_format_t::bjdata))
{ {
vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current); vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
@ -2674,12 +2674,12 @@ class binary_reader
@return whether the last read character is not EOF @return whether the last read character is not EOF
*/ */
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
bool unexpect_eof(const input_format_t format_, const char* context) const bool unexpect_eof(const input_format_t format, const char* context) const
{ {
if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, "<end of file>", return sax->parse_error(chars_read, "<end of file>",
parse_error::create(110, chars_read, exception_message(format_, "unexpected end of input", context), nullptr)); parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
} }
return true; return true;
} }
@ -2700,13 +2700,13 @@ class binary_reader
@param[in] context further context information @param[in] context further context information
@return a message string to use in the parse_error exceptions @return a message string to use in the parse_error exceptions
*/ */
std::string exception_message(const input_format_t format_, std::string exception_message(const input_format_t format,
const std::string& detail, const std::string& detail,
const std::string& context) const const std::string& context) const
{ {
std::string error_msg = "syntax error while parsing "; std::string error_msg = "syntax error while parsing ";
switch (format_) switch (format)
{ {
case input_format_t::cbor: case input_format_t::cbor:
error_msg += "CBOR"; error_msg += "CBOR";
@ -2749,8 +2749,8 @@ class binary_reader
/// whether we can assume little endianness /// whether we can assume little endianness
const bool is_little_endian = little_endianness(); const bool is_little_endian = little_endianness();
/// sax parser format /// input format
input_format_t format; input_format_t input_format;
/// the SAX parser /// the SAX parser
json_sax_t* sax = nullptr; json_sax_t* sax = nullptr;

View File

@ -1367,7 +1367,7 @@ class binary_writer
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n));
} }
else if (is_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint64_t>::max)())) else if (is_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
{ {
if (add_prefix) if (add_prefix)
{ {
@ -1454,7 +1454,7 @@ class binary_writer
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n));
} }
else if (is_bjdata && (static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::min)()) <= n && n <= static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::max)()))) else if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= static_cast<std::uint64_t>(n) && static_cast<std::uint64_t>(n) <= (std::numeric_limits<std::uint64_t>::max)()))
{ {
if (add_prefix) if (add_prefix)
{ {
@ -1523,7 +1523,7 @@ class binary_writer
{ {
return 'L'; return 'L';
} }
if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint64_t>::max)())) if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= static_cast<std::uint64_t>(j.m_value.number_integer) && static_cast<std::uint64_t>(j.m_value.number_integer) <= (std::numeric_limits<std::uint64_t>::max)()))
{ {
return 'M'; return 'M';
} }
@ -1561,7 +1561,7 @@ class binary_writer
{ {
return 'L'; return 'L';
} }
if (is_bjdata && j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::max)())) if (is_bjdata && j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
{ {
return 'M'; return 'M';
} }

View File

@ -8471,16 +8471,16 @@ class binary_reader
@return whether parsing was successful @return whether parsing was successful
*/ */
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
bool sax_parse(const input_format_t format_, bool sax_parse(const input_format_t format,
json_sax_t* sax_, json_sax_t* sax_,
const bool strict = true, const bool strict = true,
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
{ {
sax = sax_; sax = sax_;
format = format_; input_format = format;
bool result = false; bool result = false;
switch (format) switch (input_format)
{ {
case input_format_t::bson: case input_format_t::bson:
result = parse_bson_internal(); result = parse_bson_internal();
@ -8507,7 +8507,7 @@ class binary_reader
// strict mode: next byte must be EOF // strict mode: next byte must be EOF
if (result && strict) if (result && strict)
{ {
if (format == input_format_t::ubjson || format == input_format_t::bjdata) if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
{ {
get_ignore_noop(); get_ignore_noop();
} }
@ -8519,7 +8519,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
exception_message(format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr));
} }
} }
@ -10222,7 +10222,7 @@ class binary_reader
get(); // TODO(niels): may we ignore N here? get(); // TODO(niels): may we ignore N here?
} }
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "value"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
{ {
return false; return false;
} }
@ -10232,58 +10232,58 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t len{}; std::uint8_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'i': case 'i':
{ {
std::int8_t len{}; std::int8_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'I': case 'I':
{ {
std::int16_t len{}; std::int16_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'l': case 'l':
{ {
std::int32_t len{}; std::int32_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'L': case 'L':
{ {
std::int64_t len{}; std::int64_t len{};
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
default: default:
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (current) switch (current)
{ {
case 'u': case 'u':
{ {
uint16_t len; uint16_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'm': case 'm':
{ {
uint32_t len; uint32_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
case 'M': case 'M':
{ {
uint64_t len; uint64_t len;
return get_number(format, len) && get_string(format, len, result); return get_number(input_format, len) && get_string(input_format, len, result);
} }
} }
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("expected length type specification (U, i, I, l, L); last byte: 0x", last_token), "string"), nullptr)); exception_message(input_format, concat("expected length type specification (U, i, I, l, L); last byte: 0x", last_token), "string"), nullptr));
} }
} }
@ -10366,7 +10366,7 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t number{}; std::uint8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10377,7 +10377,7 @@ class binary_reader
case 'i': case 'i':
{ {
std::int8_t number{}; std::int8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10388,7 +10388,7 @@ class binary_reader
case 'I': case 'I':
{ {
std::int16_t number{}; std::int16_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10399,7 +10399,7 @@ class binary_reader
case 'l': case 'l':
{ {
std::int32_t number{}; std::int32_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10410,7 +10410,7 @@ class binary_reader
case 'L': case 'L':
{ {
std::int64_t number{}; std::int64_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10420,14 +10420,14 @@ class binary_reader
default: default:
{ {
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (prefix) switch (prefix)
{ {
case 'u': case 'u':
{ {
uint16_t number; uint16_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10437,7 +10437,7 @@ class binary_reader
case 'm': case 'm':
{ {
uint32_t number; uint32_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10447,7 +10447,7 @@ class binary_reader
case 'M': case 'M':
{ {
uint64_t number; uint64_t number;
if (JSON_HEDLEY_UNLIKELY(!get_number(format, number))) if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
{ {
return false; return false;
} }
@ -10475,7 +10475,7 @@ class binary_reader
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("expected length type specification (U, i, I, l, L) after '#'; last byte: 0x", last_token), "size"), nullptr)); exception_message(input_format, concat("expected length type specification (U, i, I, l, L) after '#'; last byte: 0x", last_token), "size"), nullptr));
} }
} }
} }
@ -10500,7 +10500,7 @@ class binary_reader
if (current == '$') if (current == '$')
{ {
result.second = get(); // must not ignore 'N', because 'N' maybe the type result.second = get(); // must not ignore 'N', because 'N' maybe the type
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "type"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type")))
{ {
return false; return false;
} }
@ -10508,13 +10508,13 @@ class binary_reader
get_ignore_noop(); get_ignore_noop();
if (JSON_HEDLEY_UNLIKELY(current != '#')) if (JSON_HEDLEY_UNLIKELY(current != '#'))
{ {
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "value"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
{ {
return false; return false;
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
exception_message(format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr));
} }
return get_ubjson_size_value(result.first); return get_ubjson_size_value(result.first);
@ -10537,7 +10537,7 @@ class binary_reader
switch (prefix) switch (prefix)
{ {
case std::char_traits<char_type>::eof(): // EOF case std::char_traits<char_type>::eof(): // EOF
return unexpect_eof(format, "value"); return unexpect_eof(input_format, "value");
case 'T': // true case 'T': // true
return sax->boolean(true); return sax->boolean(true);
@ -10550,43 +10550,43 @@ class binary_reader
case 'U': case 'U':
{ {
std::uint8_t number{}; std::uint8_t number{};
return get_number(format, number) && sax->number_unsigned(number); return get_number(input_format, number) && sax->number_unsigned(number);
} }
case 'i': case 'i':
{ {
std::int8_t number{}; std::int8_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'I': case 'I':
{ {
std::int16_t number{}; std::int16_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'l': case 'l':
{ {
std::int32_t number{}; std::int32_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'L': case 'L':
{ {
std::int64_t number{}; std::int64_t number{};
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'd': case 'd':
{ {
float number{}; float number{};
return get_number(format, number) && sax->number_float(static_cast<number_float_t>(number), ""); return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'D': case 'D':
{ {
double number{}; double number{};
return get_number(format, number) && sax->number_float(static_cast<number_float_t>(number), ""); return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'H': case 'H':
@ -10597,7 +10597,7 @@ class binary_reader
case 'C': // char case 'C': // char
{ {
get(); get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "char"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "char")))
{ {
return false; return false;
} }
@ -10605,7 +10605,7 @@ class binary_reader
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
exception_message(format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr));
} }
string_t s(1, static_cast<typename string_t::value_type>(current)); string_t s(1, static_cast<typename string_t::value_type>(current));
return sax->string(s); return sax->string(s);
@ -10625,34 +10625,34 @@ class binary_reader
default: // anything else default: // anything else
{ {
if (format == input_format_t::bjdata) if (input_format == input_format_t::bjdata)
{ {
switch (prefix) switch (prefix)
{ {
case 'u': case 'u':
{ {
uint16_t number; uint16_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'm': case 'm':
{ {
uint32_t number; uint32_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'M': case 'M':
{ {
uint64_t number; uint64_t number;
return get_number(format, number) && sax->number_integer(number); return get_number(input_format, number) && sax->number_integer(number);
} }
case 'h': case 'h':
{ {
const int byte2 = get(); const int byte2 = get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "half"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "half")))
{ {
return false; return false;
} }
const int byte1 = get(); const int byte1 = get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "half"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "half")))
{ {
return false; return false;
} }
@ -10692,7 +10692,7 @@ class binary_reader
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
exception_message(format, concat("invalid byte: 0x", last_token), "value"), nullptr)); exception_message(input_format, concat("invalid byte: 0x", last_token), "value"), nullptr));
} }
} }
} }
@ -10852,7 +10852,7 @@ class binary_reader
for (std::size_t i = 0; i < size; ++i) for (std::size_t i = 0; i < size; ++i)
{ {
get(); get();
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number"))) if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number")))
{ {
return false; return false;
} }
@ -10871,7 +10871,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) 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, return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
exception_message(format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
} }
switch (result_number) switch (result_number)
@ -10898,7 +10898,7 @@ class binary_reader
case token_type::literal_or_value: case token_type::literal_or_value:
default: default:
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
exception_message(format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
} }
} }
@ -10962,7 +10962,7 @@ class binary_reader
} }
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
if ((is_little_endian != InputIsLittleEndian && format != input_format_t::bjdata) or if ((is_little_endian != InputIsLittleEndian && format != input_format_t::bjdata) ||
(is_little_endian == InputIsLittleEndian && format == input_format_t::bjdata)) (is_little_endian == InputIsLittleEndian && format == input_format_t::bjdata))
{ {
vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current); vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
@ -11050,12 +11050,12 @@ class binary_reader
@return whether the last read character is not EOF @return whether the last read character is not EOF
*/ */
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
bool unexpect_eof(const input_format_t format_, const char* context) const bool unexpect_eof(const input_format_t format, const char* context) const
{ {
if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, "<end of file>", return sax->parse_error(chars_read, "<end of file>",
parse_error::create(110, chars_read, exception_message(format_, "unexpected end of input", context), nullptr)); parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
} }
return true; return true;
} }
@ -11076,13 +11076,13 @@ class binary_reader
@param[in] context further context information @param[in] context further context information
@return a message string to use in the parse_error exceptions @return a message string to use in the parse_error exceptions
*/ */
std::string exception_message(const input_format_t format_, std::string exception_message(const input_format_t format,
const std::string& detail, const std::string& detail,
const std::string& context) const const std::string& context) const
{ {
std::string error_msg = "syntax error while parsing "; std::string error_msg = "syntax error while parsing ";
switch (format_) switch (format)
{ {
case input_format_t::cbor: case input_format_t::cbor:
error_msg += "CBOR"; error_msg += "CBOR";
@ -11125,8 +11125,8 @@ class binary_reader
/// whether we can assume little endianness /// whether we can assume little endianness
const bool is_little_endian = little_endianness(); const bool is_little_endian = little_endianness();
/// sax parser format /// input format
input_format_t format; input_format_t input_format;
/// the SAX parser /// the SAX parser
json_sax_t* sax = nullptr; json_sax_t* sax = nullptr;
@ -15152,7 +15152,7 @@ class binary_writer
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n));
} }
else if (is_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint64_t>::max)())) else if (is_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
{ {
if (add_prefix) if (add_prefix)
{ {
@ -15239,7 +15239,7 @@ class binary_writer
} }
write_number(static_cast<std::int64_t>(n)); write_number(static_cast<std::int64_t>(n));
} }
else if (is_bjdata && (static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::min)()) <= n && n <= static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::max)()))) else if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= static_cast<std::uint64_t>(n) && static_cast<std::uint64_t>(n) <= (std::numeric_limits<std::uint64_t>::max)()))
{ {
if (add_prefix) if (add_prefix)
{ {
@ -15308,7 +15308,7 @@ class binary_writer
{ {
return 'L'; return 'L';
} }
if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint64_t>::max)())) if (is_bjdata && ((std::numeric_limits<std::uint64_t>::min)() <= static_cast<std::uint64_t>(j.m_value.number_integer) && static_cast<std::uint64_t>(j.m_value.number_integer) <= (std::numeric_limits<std::uint64_t>::max)()))
{ {
return 'M'; return 'M';
} }
@ -15346,7 +15346,7 @@ class binary_writer
{ {
return 'L'; return 'L';
} }
if (is_bjdata && j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint64_t>::max)())) if (is_bjdata && j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
{ {
return 'M'; return 'M';
} }