mirror of
https://github.com/nlohmann/json.git
synced 2026-10-24 06:48:55 +00:00
2.3.2: get_string_with_length for the plain-order string sites (#5891)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
1 file changed
+23
-14
@@ -2050,20 +2050,17 @@ class binary_reader
|
|||||||
|
|
||||||
case 0xD9: // str 8
|
case 0xD9: // str 8
|
||||||
{
|
{
|
||||||
std::uint8_t len{};
|
return get_string_with_length<std::uint8_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0xDA: // str 16
|
case 0xDA: // str 16
|
||||||
{
|
{
|
||||||
std::uint16_t len{};
|
return get_string_with_length<std::uint16_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0xDB: // str 32
|
case 0xDB: // str 32
|
||||||
{
|
{
|
||||||
std::uint32_t len{};
|
return get_string_with_length<std::uint32_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -2508,8 +2505,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
case 'U':
|
case 'U':
|
||||||
{
|
{
|
||||||
std::uint8_t len{};
|
return get_string_with_length<std::uint8_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
@@ -2542,8 +2538,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::uint16_t len{};
|
return get_string_with_length<std::uint16_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
@@ -2552,8 +2547,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::uint32_t len{};
|
return get_string_with_length<std::uint32_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
@@ -2562,8 +2556,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::uint64_t len{};
|
return get_string_with_length<std::uint64_t>(result, context);
|
||||||
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -4122,6 +4115,22 @@ class binary_reader
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief read a length of type @a NumberType, then a string of that many bytes
|
||||||
|
|
||||||
|
@tparam NumberType the type of the length field
|
||||||
|
@param[out] result string the bytes are appended to
|
||||||
|
@param[in] context further context information (for diagnostics)
|
||||||
|
|
||||||
|
@return whether reading and validating the string succeeded
|
||||||
|
*/
|
||||||
|
template<typename NumberType>
|
||||||
|
bool get_string_with_length(string_t& result, const char* context)
|
||||||
|
{
|
||||||
|
NumberType len{};
|
||||||
|
return get_number(len) && get_string(len, result) && check_string_utf8(result, context);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief create a byte array by reading bytes from the input
|
@brief create a byte array by reading bytes from the input
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user