|
4 | 4 | #ifndef TAOCPP_JSON_INCLUDE_FROM_STRING_HH |
5 | 5 | #define TAOCPP_JSON_INCLUDE_FROM_STRING_HH |
6 | 6 |
|
7 | | -#include "external/pegtl/parse.hh" |
| 7 | +#include <cstddef> |
| 8 | +#include <utility> |
| 9 | +#include <string> |
8 | 10 |
|
9 | | -#include "internal/value_builder.hh" |
10 | | - |
11 | | -#include "internal/grammar.hh" |
12 | | -#include "internal/action.hh" |
13 | | -#include "internal/control.hh" |
| 11 | +#include "sax/from_string.hh" |
| 12 | +#include "sax/to_value.hh" |
14 | 13 |
|
15 | 14 | namespace tao |
16 | 15 | { |
17 | 16 | namespace json |
18 | 17 | { |
19 | | - template< typename Handler > |
20 | | - inline void from_string( const char * data, const std::size_t size, Handler & handler, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
21 | | - { |
22 | | - tao_json_pegtl::input input( line, column, data, data + size, source ? source : __PRETTY_FUNCTION__ ); |
23 | | - tao_json_pegtl::parse_input< internal::grammar, internal::action, internal::control >( input, handler ); |
24 | | - } |
25 | | - |
26 | | - template< typename Handler > |
27 | | - inline void from_string( const std::string & data, Handler & handler, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
28 | | - { |
29 | | - json::from_string( data.data(), data.size(), handler, source, line, column ); |
30 | | - } |
31 | | - |
32 | 18 | template< template< typename ... > class Traits > |
33 | 19 | inline basic_value< Traits > from_string( const char * data, const std::size_t size, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
34 | 20 | { |
35 | | - internal::value_builder< Traits > handler; |
36 | | - json::from_string( data, size, handler, source, line, column ); |
37 | | - return std::move( handler.value_ ); |
| 21 | + sax::to_basic_value< Traits > handler; |
| 22 | + sax::from_string( data, size, handler, source, line, column ); |
| 23 | + return std::move( handler.result() ); |
38 | 24 | } |
39 | 25 |
|
40 | 26 | template< template< typename ... > class Traits > |
41 | | - inline void from_string( basic_value< Traits > & output, const char * data, const std::size_t size, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
| 27 | + inline basic_value< Traits > from_string( const char * data, const std::size_t size, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
42 | 28 | { |
43 | | - output = from_string< Traits >( data, size, source, line, column ); |
| 29 | + return from_string< Traits >( data, size, source.c_str(), line, column ); |
44 | 30 | } |
45 | 31 |
|
46 | 32 | inline value from_string( const char * data, const std::size_t size, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
47 | 33 | { |
48 | 34 | return from_string< traits >( data, size, source, line, column ); |
49 | 35 | } |
50 | 36 |
|
51 | | - template< template< typename ... > class Traits > |
52 | | - inline void from_string( basic_value< Traits > & output, const char * data, const std::size_t size, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
53 | | - { |
54 | | - json::from_string( output, data, size, source.c_str(), line, column ); |
55 | | - } |
56 | | - |
57 | | - template< template< typename ... > class Traits > |
58 | | - inline basic_value< Traits > from_string( const char * data, const std::size_t size, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
59 | | - { |
60 | | - return from_string< Traits >( data, size, source.c_str(), line, column ); |
61 | | - } |
62 | | - |
63 | 37 | inline value from_string( const char * data, const std::size_t size, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
64 | 38 | { |
65 | | - return json::from_string( data, size, source.c_str(), line, column ); |
| 39 | + return from_string< traits >( data, size, source.c_str(), line, column ); |
66 | 40 | } |
67 | 41 |
|
68 | 42 | template< template< typename ... > class Traits > |
69 | | - inline void from_string( basic_value< Traits > & output, const std::string & data, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
| 43 | + inline basic_value< Traits > from_string( const std::string & data, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
70 | 44 | { |
71 | | - json::from_string( output, data.data(), data.size(), source, line, column ); |
| 45 | + return from_string< Traits >( data.data(), data.size(), source, line, column ); |
72 | 46 | } |
73 | 47 |
|
74 | 48 | template< template< typename ... > class Traits > |
75 | | - inline basic_value< Traits > from_string( const std::string & data, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
| 49 | + inline basic_value< Traits > from_string( const std::string & data, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
76 | 50 | { |
77 | | - return from_string< Traits >( data.data(), data.size(), source, line, column ); |
| 51 | + return from_string< Traits >( data.data(), data.size(), source.c_str(), line, column ); |
78 | 52 | } |
79 | 53 |
|
80 | 54 | inline value from_string( const std::string & data, const char * source = nullptr, const std::size_t line = 1, const std::size_t column = 0 ) |
81 | 55 | { |
82 | 56 | return json::from_string( data.data(), data.size(), source, line, column ); |
83 | 57 | } |
84 | 58 |
|
85 | | - template< template< typename ... > class Traits > |
86 | | - inline void from_string( basic_value< Traits > & output, const std::string & data, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
87 | | - { |
88 | | - json::from_string( output, data.data(), data.size(), source.c_str(), line, column ); |
89 | | - } |
90 | | - |
91 | | - template< template< typename ... > class Traits > |
92 | | - inline basic_value< Traits > from_string( const std::string & data, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
| 59 | + inline value from_string( const std::string & data, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
93 | 60 | { |
94 | | - return from_string< Traits >( data.data(), data.size(), source.c_str(), line, column ); |
| 61 | + return json::from_string( data.data(), data.size(), source.c_str(), line, column ); |
95 | 62 | } |
96 | 63 |
|
97 | | - inline value from_string( const std::string & data, const std::string & source, const std::size_t line = 1, const std::size_t column = 0 ) |
| 64 | + template< template< typename ... > class Traits, typename ... Ts > |
| 65 | + inline void from_string( basic_value< Traits > & output, Ts && ... ts ) |
98 | 66 | { |
99 | | - return json::from_string( data.data(), data.size(), source.c_str(), line, column ); |
| 67 | + output = from_string< Traits >( std::forward< Ts >( ts ) ... ); |
100 | 68 | } |
101 | 69 |
|
102 | 70 | inline namespace literals |
|
0 commit comments