Update JSON_SPIRIT from 4.06 to 4.08
This was SVN commit r24481.
This commit is contained in:
parent
59d0885d68
commit
0d28281485
2
source/third_party/jsonspirit/LICENSE.txt
vendored
2
source/third_party/jsonspirit/LICENSE.txt
vendored
@ -1,6 +1,6 @@
|
|||||||
The MIT License
|
The MIT License
|
||||||
|
|
||||||
Copyright (c) 2007 - 2010 John W. Wilkinson
|
Copyright (c) 2007 - 2014 John W. Wilkinson
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
|
2
source/third_party/jsonspirit/README.txt
vendored
2
source/third_party/jsonspirit/README.txt
vendored
@ -5,7 +5,7 @@ The SpiderMonkey API also changes frequently and we hope that the JSON parsing c
|
|||||||
Get the library from here:
|
Get the library from here:
|
||||||
http://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-JSON-Parser-Generator-Implemented
|
http://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-JSON-Parser-Generator-Implemented
|
||||||
|
|
||||||
The currently used version was released on the 23th of May 2013.
|
The currently used version was released on the 10 of May 2014.
|
||||||
|
|
||||||
Search for this comment in json_spirit_value.h and uncomment the lines we don't need:
|
Search for this comment in json_spirit_value.h and uncomment the lines we don't need:
|
||||||
// comment out the value types you don't need to reduce build times and intermediate file sizes
|
// comment out the value types you don't need to reduce build times and intermediate file sizes
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#ifndef JSON_SPIRIT_ERROR_POSITION
|
#ifndef JSON_SPIRIT_ERROR_POSITION
|
||||||
#define JSON_SPIRIT_ERROR_POSITION
|
#define JSON_SPIRIT_ERROR_POSITION
|
||||||
|
|
||||||
// Copyright John W. Wilkinson 2007 - 2013
|
// Copyright John W. Wilkinson 2007 - 2014
|
||||||
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
||||||
|
|
||||||
// json spirit version 4.06
|
// json spirit version 4.08
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#ifndef JSON_SPIRIT_READER_TEMPLATE
|
#ifndef JSON_SPIRIT_READER_TEMPLATE
|
||||||
#define JSON_SPIRIT_READER_TEMPLATE
|
#define JSON_SPIRIT_READER_TEMPLATE
|
||||||
|
|
||||||
// Copyright John W. Wilkinson 2007 - 2013
|
// Copyright John W. Wilkinson 2007 - 2014
|
||||||
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
||||||
|
|
||||||
// json spirit version 4.06
|
// json spirit version 4.08
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
#ifndef JSON_SPIRIT_VALUE
|
#ifndef JSON_SPIRIT_VALUE
|
||||||
#define JSON_SPIRIT_VALUE
|
#define JSON_SPIRIT_VALUE
|
||||||
|
|
||||||
// Copyright John W. Wilkinson 2007 - 2013
|
// Copyright John W. Wilkinson 2007 - 2014
|
||||||
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
||||||
|
|
||||||
// json spirit version 4.06
|
// json spirit version 4.08
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
# pragma warning(disable: 4505) // Unreferenced function has been removed.
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -24,9 +23,9 @@
|
|||||||
|
|
||||||
// comment out the value types you don't need to reduce build times and intermediate file sizes
|
// comment out the value types you don't need to reduce build times and intermediate file sizes
|
||||||
#define JSON_SPIRIT_VALUE_ENABLED
|
#define JSON_SPIRIT_VALUE_ENABLED
|
||||||
//#define JSON_SPIRIT_WVALUE_ENABLED
|
#define JSON_SPIRIT_WVALUE_ENABLED
|
||||||
//#define JSON_SPIRIT_MVALUE_ENABLED
|
#define JSON_SPIRIT_MVALUE_ENABLED
|
||||||
//#define JSON_SPIRIT_WMVALUE_ENABLED
|
#define JSON_SPIRIT_WMVALUE_ENABLED
|
||||||
|
|
||||||
namespace json_spirit
|
namespace json_spirit
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#ifndef JSON_SPIRIT_WRITER_OPTIONS
|
#ifndef JSON_SPIRIT_WRITER_OPTIONS
|
||||||
#define JSON_SPIRIT_WRITER_OPTIONS
|
#define JSON_SPIRIT_WRITER_OPTIONS
|
||||||
|
|
||||||
// Copyright John W. Wilkinson 2007 - 2013
|
// Copyright John W. Wilkinson 2007 - 2014
|
||||||
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
||||||
|
|
||||||
// json spirit version 4.06
|
// json spirit version 4.08
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
@ -12,7 +12,9 @@
|
|||||||
|
|
||||||
namespace json_spirit
|
namespace json_spirit
|
||||||
{
|
{
|
||||||
enum Output_options{ pretty_print = 0x01, // Add whitespace to format the output nicely.
|
enum Output_options{ none = 0, // default options
|
||||||
|
|
||||||
|
pretty_print = 0x01, // Add whitespace to format the output nicely.
|
||||||
|
|
||||||
raw_utf8 = 0x02, // This prevents non-printable characters from being escapted using "\uNNNN" notation.
|
raw_utf8 = 0x02, // This prevents non-printable characters from being escapted using "\uNNNN" notation.
|
||||||
// Note, this is an extension to the JSON standard. It disables the escaping of
|
// Note, this is an extension to the JSON standard. It disables the escaping of
|
||||||
@ -20,7 +22,7 @@ namespace json_spirit
|
|||||||
// to pass through unaltered.
|
// to pass through unaltered.
|
||||||
|
|
||||||
remove_trailing_zeros = 0x04,
|
remove_trailing_zeros = 0x04,
|
||||||
// outputs e.g. "1.200000000000000" as "1.2"
|
// no longer used kept for backwards compatibility
|
||||||
single_line_arrays = 0x08,
|
single_line_arrays = 0x08,
|
||||||
// pretty printing except that arrays printed on single lines unless they contain
|
// pretty printing except that arrays printed on single lines unless they contain
|
||||||
// composite elements, i.e. objects or arrays
|
// composite elements, i.e. objects or arrays
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#ifndef JSON_SPIRIT_WRITER_TEMPLATE
|
#ifndef JSON_SPIRIT_WRITER_TEMPLATE
|
||||||
#define JSON_SPIRIT_WRITER_TEMPLATE
|
#define JSON_SPIRIT_WRITER_TEMPLATE
|
||||||
|
|
||||||
// Copyright John W. Wilkinson 2007 - 2013
|
// Copyright John W. Wilkinson 2007 - 2014
|
||||||
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
// Distributed under the MIT License, see accompanying file LICENSE.txt
|
||||||
|
|
||||||
// json spirit version 4.06
|
// json spirit version 4.08
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
@ -103,58 +103,6 @@ namespace json_spirit
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Ostream >
|
|
||||||
void append_double( Ostream& os, const double d, const int precision )
|
|
||||||
{
|
|
||||||
os << std::showpoint << std::setprecision( precision ) << d;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class String_type >
|
|
||||||
void erase_and_extract_exponent( String_type& str, String_type& exp )
|
|
||||||
{
|
|
||||||
const typename String_type::size_type exp_start= str.find( 'e' );
|
|
||||||
|
|
||||||
if( exp_start != String_type::npos )
|
|
||||||
{
|
|
||||||
exp = str.substr( exp_start );
|
|
||||||
str.erase( exp_start );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class String_type >
|
|
||||||
typename String_type::size_type find_first_non_zero( const String_type& str )
|
|
||||||
{
|
|
||||||
typename String_type::size_type result = str.size() - 1;
|
|
||||||
|
|
||||||
for( ; result != 0; --result )
|
|
||||||
{
|
|
||||||
if( str[ result ] != '0' )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class String_type >
|
|
||||||
void remove_trailing( String_type& str )
|
|
||||||
{
|
|
||||||
String_type exp;
|
|
||||||
|
|
||||||
erase_and_extract_exponent( str, exp );
|
|
||||||
|
|
||||||
const typename String_type::size_type first_non_zero = find_first_non_zero( str );
|
|
||||||
|
|
||||||
if( first_non_zero != 0 )
|
|
||||||
{
|
|
||||||
const int offset = str[first_non_zero] == '.' ? 2 : 1; // note zero digits following a decimal point is non standard
|
|
||||||
str.erase( first_non_zero + offset );
|
|
||||||
}
|
|
||||||
|
|
||||||
str += exp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this class generates the JSON text,
|
// this class generates the JSON text,
|
||||||
// it keeps track of the indentation level etc.
|
// it keeps track of the indentation level etc.
|
||||||
//
|
//
|
||||||
@ -170,16 +118,24 @@ namespace json_spirit
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Generator( const Value_type& value, Ostream_type& os, unsigned int options )
|
Generator( const Value_type& value, Ostream_type& os, int options, unsigned int precision_of_doubles )
|
||||||
: os_( os )
|
: os_( os )
|
||||||
, indentation_level_( 0 )
|
, indentation_level_( 0 )
|
||||||
, pretty_( ( options & pretty_print ) != 0 || ( options & single_line_arrays ) != 0 )
|
, pretty_( ( options & pretty_print ) != 0 || ( options & single_line_arrays ) != 0 )
|
||||||
, raw_utf8_( ( options & raw_utf8 ) != 0 )
|
, raw_utf8_( ( options & raw_utf8 ) != 0 )
|
||||||
, esc_nonascii_( ( options & always_escape_nonascii ) != 0 )
|
, esc_nonascii_( ( options & always_escape_nonascii ) != 0 )
|
||||||
, remove_trailing_zeros_( ( options & remove_trailing_zeros ) != 0 )
|
|
||||||
, single_line_arrays_( ( options & single_line_arrays ) != 0 )
|
, single_line_arrays_( ( options & single_line_arrays ) != 0 )
|
||||||
, ios_saver_( os )
|
, ios_saver_( os )
|
||||||
{
|
{
|
||||||
|
if( precision_of_doubles > 0 )
|
||||||
|
{
|
||||||
|
precision_of_doubles_ = precision_of_doubles;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
precision_of_doubles_ = ( options & remove_trailing_zeros ) != 0 ? 16 : 17;
|
||||||
|
}
|
||||||
|
|
||||||
output( value );
|
output( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,23 +192,7 @@ namespace json_spirit
|
|||||||
|
|
||||||
void output( double d )
|
void output( double d )
|
||||||
{
|
{
|
||||||
if( remove_trailing_zeros_ )
|
os_ << std::setprecision( precision_of_doubles_ ) << d;
|
||||||
{
|
|
||||||
std::basic_ostringstream< Char_type > os;
|
|
||||||
|
|
||||||
append_double( os, d, 16 ); // note precision is 16 so that we get some trailing space that we can remove,
|
|
||||||
// otherwise, 0.1234 gets converted to "0.12399999..."
|
|
||||||
|
|
||||||
String_type str = os.str();
|
|
||||||
|
|
||||||
remove_trailing( str );
|
|
||||||
|
|
||||||
os_ << str;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
append_double( os_, d, 17 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool contains_composite_elements( const Array_type& arr )
|
static bool contains_composite_elements( const Array_type& arr )
|
||||||
@ -351,8 +291,8 @@ namespace json_spirit
|
|||||||
bool pretty_;
|
bool pretty_;
|
||||||
bool raw_utf8_;
|
bool raw_utf8_;
|
||||||
bool esc_nonascii_;
|
bool esc_nonascii_;
|
||||||
bool remove_trailing_zeros_;
|
|
||||||
bool single_line_arrays_;
|
bool single_line_arrays_;
|
||||||
|
int precision_of_doubles_;
|
||||||
boost::io::basic_ios_all_saver< Char_type > ios_saver_; // so that ostream state is reset after control is returned to the caller
|
boost::io::basic_ios_all_saver< Char_type > ios_saver_; // so that ostream state is reset after control is returned to the caller
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,10 +301,10 @@ namespace json_spirit
|
|||||||
// write_stream( value, os, pretty_print );
|
// write_stream( value, os, pretty_print );
|
||||||
//
|
//
|
||||||
template< class Value_type, class Ostream_type >
|
template< class Value_type, class Ostream_type >
|
||||||
void write_stream( const Value_type& value, Ostream_type& os, unsigned int options = 0 )
|
void write_stream( const Value_type& value, Ostream_type& os, int options = none, unsigned int precision_of_doubles = 0 )
|
||||||
{
|
{
|
||||||
os << std::dec;
|
os << std::dec;
|
||||||
Generator< Value_type, Ostream_type >( value, os, options );
|
Generator< Value_type, Ostream_type >( value, os, options, precision_of_doubles );
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes JSON Value to a stream, e.g.
|
// writes JSON Value to a stream, e.g.
|
||||||
@ -372,13 +312,13 @@ namespace json_spirit
|
|||||||
// const string json_str = write( value, pretty_print );
|
// const string json_str = write( value, pretty_print );
|
||||||
//
|
//
|
||||||
template< class Value_type >
|
template< class Value_type >
|
||||||
typename Value_type::String_type write_string( const Value_type& value, unsigned int options = 0 )
|
typename Value_type::String_type write_string( const Value_type& value, int options = none, unsigned int precision_of_doubles = 0 )
|
||||||
{
|
{
|
||||||
typedef typename Value_type::String_type::value_type Char_type;
|
typedef typename Value_type::String_type::value_type Char_type;
|
||||||
|
|
||||||
std::basic_ostringstream< Char_type > os;
|
std::basic_ostringstream< Char_type > os;
|
||||||
|
|
||||||
write_stream( value, os, options );
|
write_stream( value, os, options, precision_of_doubles );
|
||||||
|
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user