1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

Merge branch 'develop' into feature/sax2

This commit is contained in:
Niels Lohmann
2018-03-13 23:58:17 +01:00
8 changed files with 238 additions and 20 deletions

View File

@ -1871,6 +1871,7 @@ class lexer
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
public:
/// token types for the parser
@ -2969,7 +2970,7 @@ scan_number_done:
}
/// return current string value (implicitly resets the token; useful only once)
std::string&& move_string()
string_t&& move_string()
{
return std::move(token_buffer);
}
@ -3099,7 +3100,7 @@ scan_number_done:
std::vector<char> token_string {};
/// buffer for variable-length tokens (numbers, strings)
std::string token_buffer {};
string_t token_buffer {};
/// a description of occurred lexer errors
const char* error_message = "";
@ -3538,6 +3539,7 @@ class parser
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using lexer_t = lexer<BasicJsonType>;
using token_type = typename lexer_t::token_type;
@ -3710,7 +3712,7 @@ class parser
}
// parse values
std::string key;
string_t key;
BasicJsonType value;
while (true)
{
@ -5250,11 +5252,11 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
};
/// output adapter for basic_string
template<typename CharType>
template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_string_adapter : public output_adapter_protocol<CharType>
{
public:
explicit output_string_adapter(std::basic_string<CharType>& s) : str(s) {}
explicit output_string_adapter(StringType& s) : str(s) {}
void write_character(CharType c) override
{
@ -5267,10 +5269,10 @@ class output_string_adapter : public output_adapter_protocol<CharType>
}
private:
std::basic_string<CharType>& str;
StringType& str;
};
template<typename CharType>
template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter
{
public:
@ -5280,8 +5282,8 @@ class output_adapter
output_adapter(std::basic_ostream<CharType>& s)
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
output_adapter(std::basic_string<CharType>& s)
: oa(std::make_shared<output_string_adapter<CharType>>(s)) {}
output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
operator output_adapter_t<CharType>()
{
@ -12060,7 +12062,7 @@ class basic_json
const bool ensure_ascii = false) const
{
string_t result;
serializer s(detail::output_adapter<char>(result), indent_char);
serializer s(detail::output_adapter<char, string_t>(result), indent_char);
if (indent >= 0)
{