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( 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 >
189 switch(
value.type() )
198 default: assert(
false );
break;
209 output( Config_type::get_name( member ) );
space();
216 if(
value.is_uint64() )
233 os_ << to_str< String_type >( b ?
"true" :
"false" );
240 std::basic_ostringstream< Char_type > os;
259 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
273 template<
class Iter >
290 for(
typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i )
312 for(
typename T::const_iterator i = t.begin(); i != t.end(); ++i )
361 template<
class Value_type,
class Ostream_type >
372 template<
class Value_type >
375 typedef typename Value_type::String_type::value_type Char_type;
377 std::basic_ostringstream< Char_type > os;