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 typedef typename String_type::value_type Char_type;
39 String_type result( 6,
'\\' );
51 template<
typename Char_type,
class String_type >
56 case '"': s += to_str< String_type >(
"\\\"" );
return true;
57 case '\\': s += to_str< String_type >(
"\\\\" );
return true;
58 case '\b': s += to_str< String_type >(
"\\b" );
return true;
59 case '\f': s += to_str< String_type >(
"\\f" );
return true;
60 case '\n': s += to_str< String_type >(
"\\n" );
return true;
61 case '\r': s += to_str< String_type >(
"\\r" );
return true;
62 case '\t': s += to_str< String_type >(
"\\t" );
return true;
68 template<
class String_type >
71 typedef typename String_type::const_iterator Iter_type;
72 typedef typename String_type::value_type Char_type;
76 const Iter_type end( s.end() );
78 for( Iter_type i = s.begin(); i != end; ++i )
80 const Char_type c( *i );
90 const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );
92 if( !esc_nonascii && iswprint( unsigned_c ) )
98 result += non_printable_to_string< String_type >( unsigned_c );
106 template<
class Ostream >
109 os << std::showpoint << std::setprecision( precision ) << d;
112 template<
class String_type >
115 const typename String_type::size_type exp_start= str.find(
'e' );
117 if( exp_start != String_type::npos )
119 exp = str.substr( exp_start );
120 str.erase( exp_start );
124 template<
class String_type >
127 typename String_type::size_type result = str.size() - 1;
129 for( ; result != 0; --result )
131 if( str[ result ] !=
'0' )
140 template<
class String_type >
149 if( first_non_zero != 0 )
151 const int offset = str[first_non_zero] ==
'.' ? 2 : 1;
152 str.erase( first_non_zero + offset );
161 template<
class Value_type,
class Ostream_type >
190 switch( value.type() )
199 default: assert(
false );
208 void output(
const Obj_member_type& member )
210 output( Config_type::get_name( member ) );
space();
217 if( value.is_uint64() )
219 os_ << value.get_uint64();
223 os_ << value.get_int64();
234 os_ << to_str< String_type >( b ?
"true" :
"false" );
241 std::basic_ostringstream< Char_type > os;
246 String_type str = os.str();
260 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
274 template<
class Iter >
291 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
313 for(
typename T::const_iterator i = t.begin(); i != t.end(); ++i )
363 template<
class Value_type,
class Ostream_type >
374 template<
class Value_type >
377 typedef typename Value_type::String_type::value_type
Char_type;
379 std::basic_ostringstream< Char_type > os;
String_type non_printable_to_string(unsigned int c)
Definition: json_spirit_writer_template.h:35
Definition: json_spirit_writer_options.h:22
int indentation_level_
Definition: json_spirit_writer_template.h:350
void output(const String_type &s)
Definition: json_spirit_writer_template.h:227
Definition: json_spirit_writer_options.h:15
void erase_and_extract_exponent(String_type &str, String_type &exp)
Definition: json_spirit_writer_template.h:113
String_type::value_type Char_type
Definition: json_spirit_writer_template.h:168
Value_type::String_type write_string(const Value_type &value, unsigned int options=0)
Definition: json_spirit_writer_template.h:375
void append_double(Ostream &os, const double d, const int precision)
Definition: json_spirit_writer_template.h:107
Generator & operator=(const Generator &)
Definition: json_spirit_writer_options.h:17
bool single_line_arrays_
Definition: json_spirit_writer_template.h:355
Definition: json_spirit_error_position.h:15
bool esc_nonascii_
Definition: json_spirit_writer_template.h:353
Definition: json_spirit_writer_template.h:162
void space()
Definition: json_spirit_writer_template.h:337
boost::io::basic_ios_all_saver< Char_type > ios_saver_
Definition: json_spirit_writer_template.h:356
Object_type::value_type Obj_member_type
Definition: json_spirit_writer_template.h:169
void output_int(const Value_type &value)
Definition: json_spirit_writer_template.h:215
Definition: json_spirit_writer_options.h:24
void indent()
Definition: json_spirit_writer_template.h:327
Definition: json_spirit_value.h:32
bool add_esc_char(Char_type c, String_type &s)
Definition: json_spirit_writer_template.h:52
char to_hex_char(unsigned int c)
Definition: json_spirit_writer_template.h:23
Value_type
Definition: json_spirit_value.h:32
Config_type::Array_type Array_type
Definition: json_spirit_writer_template.h:167
void output(const Array_type &arr)
Definition: json_spirit_writer_template.h:285
void write_stream(const Value_type &value, Ostream_type &os, unsigned int options=0)
Definition: json_spirit_writer_template.h:364
void output_composite_item(Iter i, Iter last)
Definition: json_spirit_writer_template.h:275
Config_type::String_type String_type
Definition: json_spirit_writer_template.h:165
int get_value(const Value &value, Type_to_type< int >)
Definition: json_spirit_value.h:531
Ostream_type & os_
Definition: json_spirit_writer_template.h:349
void remove_trailing(String_type &str)
Definition: json_spirit_writer_template.h:141
Definition: json_spirit_value.h:32
Definition: json_spirit_value.h:32
void output(const Value_type &value)
Definition: json_spirit_writer_template.h:188
bool remove_trailing_zeros_
Definition: json_spirit_writer_template.h:354
#define T(string_literal)
Definition: secure_crt.cpp:76
Definition: json_spirit_value.h:32
String_type::size_type find_first_non_zero(const String_type &str)
Definition: json_spirit_writer_template.h:125
void output_array_or_obj(const T &t, Char_type start_char, Char_type end_char)
Definition: json_spirit_writer_template.h:307
Generator(const Value_type &value, Ostream_type &os, unsigned int options)
Definition: json_spirit_writer_template.h:173
void output(const Obj_member_type &member)
Definition: json_spirit_writer_template.h:208
String_type add_esc_chars(const String_type &s, bool raw_utf8, bool esc_nonascii)
Definition: json_spirit_writer_template.h:69
Definition: json_spirit_value.h:32
void new_line()
Definition: json_spirit_writer_template.h:342
Definition: json_spirit_value.h:32
Value_type::Config_type Config_type
Definition: json_spirit_writer_template.h:164
bool raw_utf8_
Definition: json_spirit_writer_template.h:352
Config_type::Object_type Object_type
Definition: json_spirit_writer_template.h:166
static bool contains_composite_elements(const Array_type &arr)
Definition: json_spirit_writer_template.h:258
Definition: json_spirit_value.h:32
void output(const Object_type &obj)
Definition: json_spirit_writer_template.h:203
void output(double d)
Definition: json_spirit_writer_template.h:237
Definition: json_spirit_writer_options.h:27
void output(bool b)
Definition: json_spirit_writer_template.h:232
bool pretty_
Definition: json_spirit_writer_template.h:351