1 #ifndef JSON_SPIRIT_WRITER_TEMPLATE
2 #define JSON_SPIRIT_WRITER_TEMPLATE
9 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
19 #include <boost/io/ios_state.hpp>
27 const char ch =
static_cast< char >( c );
29 if( ch < 10 )
return '0' + ch;
34 template<
class String_type >
37 String_type result( 6,
'\\' );
49 template<
typename Char_type,
class String_type >
54 case '"': s += to_str< String_type >(
"\\\"" );
return true;
55 case '\\': s += to_str< String_type >(
"\\\\" );
return true;
56 case '\b': s += to_str< String_type >(
"\\b" );
return true;
57 case '\f': s += to_str< String_type >(
"\\f" );
return true;
58 case '\n': s += to_str< String_type >(
"\\n" );
return true;
59 case '\r': s += to_str< String_type >(
"\\r" );
return true;
60 case '\t': s += to_str< String_type >(
"\\t" );
return true;
66 template<
class String_type >
69 typedef typename String_type::const_iterator Iter_type;
70 typedef typename String_type::value_type Char_type;
74 const Iter_type end( s.end() );
76 for( Iter_type i = s.begin(); i != end; ++i )
78 const Char_type c( *i );
88 const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );
90 if( iswprint( unsigned_c ) )
96 result += non_printable_to_string< String_type >( unsigned_c );
104 template<
class Ostream >
107 os << std::showpoint << std::setprecision( precision ) << d;
110 template<
class String_type >
113 const typename String_type::size_type exp_start= str.find(
'e' );
115 if( exp_start != String_type::npos )
117 exp = str.substr( exp_start );
118 str.erase( exp_start );
122 template<
class String_type >
125 typename String_type::size_type result = str.size() - 1;
127 for( ; result != 0; --result )
129 if( str[ result ] !=
'0' )
138 template<
class String_type >
147 if( first_non_zero != 0 )
149 const int offset = str[first_non_zero] ==
'.' ? 2 : 1;
150 str.erase( first_non_zero + offset );
159 template<
class Value_type,
class Ostream_type >
187 switch(
value.type() )
196 default: assert(
false );
break;
207 output( Config_type::get_name( member ) );
space();
214 if(
value.is_uint64() )
231 os_ << to_str< String_type >( b ?
"true" :
"false" );
238 std::basic_ostringstream< Char_type > os;
257 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
271 template<
class Iter >
288 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
310 for(
typename T::const_iterator i = t.begin(); i != t.end(); ++i )
359 template<
class Value_type,
class Ostream_type >
370 template<
class Value_type >
373 typedef typename Value_type::String_type::value_type Char_type;
375 std::basic_ostringstream< Char_type > os;
General iterator template. Provides iterator over objects of type Object in some container.
static bool contains_composite_elements(const Array_type &arr)
boost::io::basic_ios_all_saver< Char_type > ios_saver_
bool remove_trailing_zeros_
void output(const Object_type &obj)
void output(const Value_type &value)
Generator(const Value_type &value, Ostream_type &os, unsigned int options)
Config_type::String_type String_type
void output_array_or_obj(const T &t, Char_type start_char, Char_type end_char)
void output(const String_type &s)
Value_type::Config_type Config_type
Config_type::Object_type Object_type
Generator & operator=(const Generator &)
void output(const Array_type &arr)
String_type::value_type Char_type
Object_type::value_type Obj_member_type
void output_int(const Value_type &value)
void output_composite_item(Iter i, Iter last)
Config_type::Array_type Array_type
void output(const Obj_member_type &member)
static constexpr bool value
int get_value(const Value &value, Type_to_type< int >)
Value_type::String_type write_string(const Value_type &value, unsigned int options=0)
bool add_esc_char(Char_type c, String_type &s)
void append_double(Ostream &os, const double d, const int precision)
String_type::size_type find_first_non_zero(const String_type &str)
char to_hex_char(unsigned int c)
void write_stream(const Value_type &value, Ostream_type &os, unsigned int options=0)
String_type non_printable_to_string(unsigned int c)
void remove_trailing(String_type &str)
void erase_and_extract_exponent(String_type &str, String_type &exp)
String_type add_esc_chars(const String_type &s, bool raw_utf8)