forked from symless/json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_string.hpp
72 lines (57 loc) · 2.58 KB
/
from_string.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/
#ifndef TAOCPP_JSON_INCLUDE_FROM_STRING_HPP
#define TAOCPP_JSON_INCLUDE_FROM_STRING_HPP
#include <cstddef>
#include <string>
#include <utility>
#include "value.hpp"
#include "events/from_string.hpp"
#include "events/to_value.hpp"
#include "events/transformer.hpp"
namespace tao
{
namespace json
{
template< template< typename... > class... Transformers >
data from_string( const char* data, const std::size_t size, const char* source = nullptr, const std::size_t byte = 0, const std::size_t line = 1, const std::size_t column = 0 )
{
events::transformer< events::to_value, Transformers... > consumer;
events::from_string( consumer, data, size, source, byte, line, column );
return std::move( consumer.value );
}
template< template< typename... > class... Transformers >
data from_string( const char* data, const std::size_t size, const std::string& source, const std::size_t byte = 0, const std::size_t line = 1, const std::size_t column = 0 )
{
return from_string< Transformers... >( data, size, source.c_str(), byte, line, column );
}
template< template< typename... > class... Transformers, typename... Ts >
data from_string( const tao::string_view data, Ts&&... ts )
{
return from_string< Transformers... >( data.data(), data.size(), std::forward< Ts >( ts )... );
}
template< template< typename... > class Traits, template< typename... > class... Transformers, typename... Ts >
basic_custom_value< Traits > basic_custom_from_string( Ts&&... ts )
{
return from_string< Transformers... >( std::forward< Ts >( ts )... );
}
template< template< typename... > class... Transformers, typename... Ts >
custom_value custom_from_string( Ts&&... ts )
{
return from_string< Transformers... >( std::forward< Ts >( ts )... );
}
template< template< typename... > class... Transformers, template< typename... > class Traits, typename... Ts >
void from_string( basic_custom_value< Traits >& output, Ts&&... ts )
{
output = from_string< Transformers... >( std::forward< Ts >( ts )... );
}
inline namespace literals
{
inline data operator"" _json( const char* data, const std::size_t size )
{
return json::from_string( data, size, "literal" );
}
} // namespace literals
} // namespace json
} // namespace tao
#endif