aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_spirit_reader_template.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/json/json_spirit_reader_template.h')
-rw-r--r--src/json/json_spirit_reader_template.h114
1 files changed, 76 insertions, 38 deletions
diff --git a/src/json/json_spirit_reader_template.h b/src/json/json_spirit_reader_template.h
index 4dec00e6c9..d3d0cecaa5 100644
--- a/src/json/json_spirit_reader_template.h
+++ b/src/json/json_spirit_reader_template.h
@@ -1,10 +1,14 @@
#ifndef JSON_SPIRIT_READER_TEMPLATE
#define JSON_SPIRIT_READER_TEMPLATE
-// Copyright John W. Wilkinson 2007 - 2009.
+// Copyright John W. Wilkinson 2007 - 2013
// Distributed under the MIT License, see accompanying file LICENSE.txt
-// json spirit version 4.03
+// json spirit version 4.06
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
#include "json_spirit_value.h"
#include "json_spirit_error_position.h"
@@ -484,7 +488,7 @@ namespace json_spirit
;
string_
- = lexeme_d // this causes white space inside a string to be retained
+ = lexeme_d // this causes white space and what would appear to be comments inside a string to be retained
[
confix_p
(
@@ -515,6 +519,44 @@ namespace json_spirit
};
template< class Iter_type, class Value_type >
+ void add_posn_iter_and_read_range_or_throw( Iter_type begin, Iter_type end, Value_type& value )
+ {
+ typedef spirit_namespace::position_iterator< Iter_type > Posn_iter_t;
+
+ const Posn_iter_t posn_begin( begin, end );
+ const Posn_iter_t posn_end( end, end );
+
+ read_range_or_throw( posn_begin, posn_end, value );
+ }
+
+ template< class Istream_type >
+ struct Multi_pass_iters
+ {
+ typedef typename Istream_type::char_type Char_type;
+ typedef std::istream_iterator< Char_type, Char_type > istream_iter;
+ typedef spirit_namespace::multi_pass< istream_iter > Mp_iter;
+
+ Multi_pass_iters( Istream_type& is )
+ {
+ is.unsetf( std::ios::skipws );
+
+ begin_ = spirit_namespace::make_multi_pass( istream_iter( is ) );
+ end_ = spirit_namespace::make_multi_pass( istream_iter() );
+ }
+
+ Mp_iter begin_;
+ Mp_iter end_;
+ };
+
+ // reads a JSON Value from a pair of input iterators throwing an exception on invalid input, e.g.
+ //
+ // string::const_iterator start = str.begin();
+ // const string::const_iterator next = read_range_or_throw( str.begin(), str.end(), value );
+ //
+ // The iterator 'next' will point to the character past the
+ // last one read.
+ //
+ template< class Iter_type, class Value_type >
Iter_type read_range_or_throw( Iter_type begin, Iter_type end, Value_type& value )
{
Semantic_actions< Value_type, Iter_type > semantic_actions( value );
@@ -522,7 +564,9 @@ namespace json_spirit
const spirit_namespace::parse_info< Iter_type > info =
spirit_namespace::parse( begin, end,
Json_grammer< Value_type, Iter_type >( semantic_actions ),
- spirit_namespace::space_p );
+ spirit_namespace::space_p |
+ spirit_namespace::comment_p("//") |
+ spirit_namespace::comment_p("/*", "*/") );
if( !info.hit )
{
@@ -533,17 +577,14 @@ namespace json_spirit
return info.stop;
}
- template< class Iter_type, class Value_type >
- void add_posn_iter_and_read_range_or_throw( Iter_type begin, Iter_type end, Value_type& value )
- {
- typedef spirit_namespace::position_iterator< Iter_type > Posn_iter_t;
-
- const Posn_iter_t posn_begin( begin, end );
- const Posn_iter_t posn_end( end, end );
-
- read_range_or_throw( posn_begin, posn_end, value );
- }
-
+ // reads a JSON Value from a pair of input iterators, e.g.
+ //
+ // string::const_iterator start = str.begin();
+ // const bool success = read_string( start, str.end(), value );
+ //
+ // The iterator 'start' will point to the character past the
+ // last one read.
+ //
template< class Iter_type, class Value_type >
bool read_range( Iter_type& begin, Iter_type end, Value_type& value )
{
@@ -559,12 +600,10 @@ namespace json_spirit
}
}
- template< class String_type, class Value_type >
- void read_string_or_throw( const String_type& s, Value_type& value )
- {
- add_posn_iter_and_read_range_or_throw( s.begin(), s.end(), value );
- }
-
+ // reads a JSON Value from a string, e.g.
+ //
+ // const bool success = read_string( str, value );
+ //
template< class String_type, class Value_type >
bool read_string( const String_type& s, Value_type& value )
{
@@ -573,25 +612,20 @@ namespace json_spirit
return read_range( begin, s.end(), value );
}
- template< class Istream_type >
- struct Multi_pass_iters
+ // reads a JSON Value from a string throwing an exception on invalid input, e.g.
+ //
+ // read_string_or_throw( is, value );
+ //
+ template< class String_type, class Value_type >
+ void read_string_or_throw( const String_type& s, Value_type& value )
{
- typedef typename Istream_type::char_type Char_type;
- typedef std::istream_iterator< Char_type, Char_type > istream_iter;
- typedef spirit_namespace::multi_pass< istream_iter > Mp_iter;
-
- Multi_pass_iters( Istream_type& is )
- {
- is.unsetf( std::ios::skipws );
-
- begin_ = spirit_namespace::make_multi_pass( istream_iter( is ) );
- end_ = spirit_namespace::make_multi_pass( istream_iter() );
- }
-
- Mp_iter begin_;
- Mp_iter end_;
- };
+ add_posn_iter_and_read_range_or_throw( s.begin(), s.end(), value );
+ }
+ // reads a JSON Value from a stream, e.g.
+ //
+ // const bool success = read_stream( is, value );
+ //
template< class Istream_type, class Value_type >
bool read_stream( Istream_type& is, Value_type& value )
{
@@ -600,6 +634,10 @@ namespace json_spirit
return read_range( mp_iters.begin_, mp_iters.end_, value );
}
+ // reads a JSON Value from a stream throwing an exception on invalid input, e.g.
+ //
+ // read_stream_or_throw( is, value );
+ //
template< class Istream_type, class Value_type >
void read_stream_or_throw( Istream_type& is, Value_type& value )
{