mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
dump to alternate implementation of string, as defined in basic_json template
This commit is contained in:
@ -68,11 +68,11 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// output adapter for basic_string
|
/// 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>
|
class output_string_adapter : public output_adapter_protocol<CharType>
|
||||||
{
|
{
|
||||||
public:
|
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
|
void write_character(CharType c) override
|
||||||
{
|
{
|
||||||
@ -85,10 +85,10 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::basic_string<CharType>& str;
|
StringType& str;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CharType>
|
template<typename CharType, typename StringType = std::basic_string<CharType>>
|
||||||
class output_adapter
|
class output_adapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -98,7 +98,7 @@ class output_adapter
|
|||||||
output_adapter(std::basic_ostream<CharType>& s)
|
output_adapter(std::basic_ostream<CharType>& s)
|
||||||
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
|
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
|
||||||
|
|
||||||
output_adapter(std::basic_string<CharType>& s)
|
output_adapter(StringType& s)
|
||||||
: oa(std::make_shared<output_string_adapter<CharType>>(s)) {}
|
: oa(std::make_shared<output_string_adapter<CharType>>(s)) {}
|
||||||
|
|
||||||
operator output_adapter_t<CharType>()
|
operator output_adapter_t<CharType>()
|
||||||
|
@ -1947,7 +1947,7 @@ class basic_json
|
|||||||
const bool ensure_ascii = false) const
|
const bool ensure_ascii = false) const
|
||||||
{
|
{
|
||||||
string_t result;
|
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)
|
if (indent >= 0)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user