jsoncons 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/ext/jsoncons/extconf.rb +43 -0
  3. data/ext/jsoncons/jsoncons.cpp +161 -0
  4. data/ext/jsoncons/jsoncons.h +10 -0
  5. data/jsoncons.gemspec +44 -0
  6. data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
  7. data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
  8. data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
  9. data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
  10. data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
  11. data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
  12. data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
  13. data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
  14. data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
  15. data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
  16. data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
  17. data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
  18. data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
  19. data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
  20. data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
  21. data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
  22. data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
  23. data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
  24. data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
  25. data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
  26. data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
  27. data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
  28. data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
  29. data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
  30. data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
  31. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
  32. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
  33. data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
  34. data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
  35. data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
  36. data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
  37. data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
  38. data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
  39. data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
  40. data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
  41. data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
  42. data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
  43. data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
  44. data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
  45. data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
  46. data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
  47. data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
  48. data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
  49. data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
  50. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
  51. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
  52. data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
  53. data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
  54. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
  55. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
  56. data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
  57. data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
  58. data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
  59. data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
  60. data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
  61. data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
  62. data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
  63. data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
  64. data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
  65. data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
  66. data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
  67. data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
  68. data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
  69. data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
  70. data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
  71. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
  72. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
  73. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
  74. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
  75. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
  76. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
  77. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
  78. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
  79. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
  80. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
  81. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
  82. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
  83. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
  84. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
  85. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
  86. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
  87. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
  88. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
  89. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
  90. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
  91. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
  92. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
  93. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
  94. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
  95. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
  96. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
  97. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
  98. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
  99. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
  100. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
  101. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
  102. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
  103. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
  104. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
  105. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
  106. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
  107. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
  108. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
  109. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
  110. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
  111. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
  112. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
  113. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
  114. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
  115. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
  116. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
  117. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
  118. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
  119. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
  120. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
  121. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
  122. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
  123. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
  124. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
  125. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
  126. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
  127. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
  128. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
  129. data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
  130. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
  131. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
  132. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
  133. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
  134. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
  135. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
  136. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
  137. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
  138. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
  139. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
  140. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
  141. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
  142. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
  143. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
  144. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
  145. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
  146. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
  147. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
  148. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
  149. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
  150. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
  151. data/lib/jsoncons/version.rb +5 -0
  152. data/lib/jsoncons.rb +33 -0
  153. data/test/jsoncons_test.rb +108 -0
  154. data/test/test_helper.rb +7 -0
  155. metadata +268 -0
@@ -0,0 +1,156 @@
1
+ /// Copyright 2013 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSON_ERROR_HPP
8
+ #define JSONCONS_JSON_ERROR_HPP
9
+
10
+ #include <system_error>
11
+ #include <jsoncons/config/jsoncons_config.hpp>
12
+
13
+ namespace jsoncons {
14
+
15
+ enum class json_errc
16
+ {
17
+ success = 0,
18
+ unexpected_eof = 1,
19
+ source_error,
20
+ syntax_error,
21
+ extra_character,
22
+ max_nesting_depth_exceeded,
23
+ single_quote,
24
+ illegal_character_in_string,
25
+ extra_comma,
26
+ expected_key,
27
+ expected_value,
28
+ invalid_value,
29
+ expected_colon,
30
+ illegal_control_character,
31
+ illegal_escaped_character,
32
+ expected_codepoint_surrogate_pair,
33
+ invalid_hex_escape_sequence,
34
+ invalid_unicode_escape_sequence,
35
+ leading_zero,
36
+ invalid_number,
37
+ expected_comma_or_rbrace,
38
+ expected_comma_or_rbracket,
39
+ unexpected_rbracket,
40
+ unexpected_rbrace,
41
+ illegal_comment,
42
+ expected_continuation_byte,
43
+ over_long_utf8_sequence,
44
+ illegal_codepoint,
45
+ illegal_surrogate_value,
46
+ unpaired_high_surrogate,
47
+ illegal_unicode_character
48
+ };
49
+
50
+ class json_error_category_impl
51
+ : public std::error_category
52
+ {
53
+ public:
54
+ const char* name() const noexcept override
55
+ {
56
+ return "jsoncons/json";
57
+ }
58
+ std::string message(int ev) const override
59
+ {
60
+ switch (static_cast<json_errc>(ev))
61
+ {
62
+ case json_errc::unexpected_eof:
63
+ return "Unexpected end of file";
64
+ case json_errc::source_error:
65
+ return "Source error";
66
+ case json_errc::syntax_error:
67
+ return "JSON syntax_error";
68
+ case json_errc::extra_character:
69
+ return "Unexpected non-whitespace character after JSON text";
70
+ case json_errc::max_nesting_depth_exceeded:
71
+ return "Data item nesting exceeds limit in options";
72
+ case json_errc::single_quote:
73
+ return "JSON strings cannot be quoted with single quotes";
74
+ case json_errc::illegal_character_in_string:
75
+ return "Illegal character in string";
76
+ case json_errc::extra_comma:
77
+ return "Extra comma";
78
+ case json_errc::expected_key:
79
+ return "Expected object member key";
80
+ case json_errc::expected_value:
81
+ return "Expected value";
82
+ case json_errc::invalid_value:
83
+ return "Invalid value";
84
+ case json_errc::expected_colon:
85
+ return "Expected name separator ':'";
86
+ case json_errc::illegal_control_character:
87
+ return "Illegal control character in string";
88
+ case json_errc::illegal_escaped_character:
89
+ return "Illegal escaped character in string";
90
+ case json_errc::expected_codepoint_surrogate_pair:
91
+ return "Invalid codepoint, expected another \\u token to begin the second half of a codepoint surrogate pair.";
92
+ case json_errc::invalid_hex_escape_sequence:
93
+ return "Invalid codepoint, expected hexadecimal digit.";
94
+ case json_errc::invalid_unicode_escape_sequence:
95
+ return "Invalid codepoint, expected four hexadecimal digits.";
96
+ case json_errc::leading_zero:
97
+ return "A number cannot have a leading zero";
98
+ case json_errc::invalid_number:
99
+ return "Invalid number";
100
+ case json_errc::expected_comma_or_rbrace:
101
+ return "Expected comma or right brace '}'";
102
+ case json_errc::expected_comma_or_rbracket:
103
+ return "Expected comma or right bracket ']'";
104
+ case json_errc::unexpected_rbrace:
105
+ return "Unexpected right brace '}'";
106
+ case json_errc::unexpected_rbracket:
107
+ return "Unexpected right bracket ']'";
108
+ case json_errc::illegal_comment:
109
+ return "Illegal comment";
110
+ case json_errc::expected_continuation_byte:
111
+ return "Expected continuation byte";
112
+ case json_errc::over_long_utf8_sequence:
113
+ return "Over long UTF-8 sequence";
114
+ case json_errc::illegal_codepoint:
115
+ return "Illegal codepoint (>= 0xd800 && <= 0xdfff)";
116
+ case json_errc::illegal_surrogate_value:
117
+ return "UTF-16 surrogate values are illegal in UTF-32";
118
+ case json_errc::unpaired_high_surrogate:
119
+ return "Expected low surrogate following the high surrogate";
120
+ case json_errc::illegal_unicode_character:
121
+ return "Illegal unicode character";
122
+ default:
123
+ return "Unknown JSON parser error";
124
+ }
125
+ }
126
+ };
127
+
128
+ inline
129
+ const std::error_category& json_error_category()
130
+ {
131
+ static json_error_category_impl instance;
132
+ return instance;
133
+ }
134
+
135
+ inline
136
+ std::error_code make_error_code(json_errc result)
137
+ {
138
+ return std::error_code(static_cast<int>(result),json_error_category());
139
+ }
140
+
141
+ #if !defined(JSONCONS_NO_DEPRECATED)
142
+ JSONCONS_DEPRECATED_MSG("Instead, use json_errc") typedef json_errc json_parser_errc;
143
+
144
+ JSONCONS_DEPRECATED_MSG("Instead, use json_errc") typedef json_errc json_parse_errc;
145
+ #endif
146
+
147
+ } // jsoncons
148
+
149
+ namespace std {
150
+ template<>
151
+ struct is_error_code_enum<jsoncons::json_errc> : public true_type
152
+ {
153
+ };
154
+ }
155
+
156
+ #endif
@@ -0,0 +1,241 @@
1
+ // Copyright 2013 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSON_EXCEPTION_HPP
8
+ #define JSON_EXCEPTION_HPP
9
+
10
+ #include <string> // std::string
11
+ #include <sstream> // std::ostringstream
12
+ #include <system_error> // std::error_code
13
+ #include <jsoncons/unicode_traits.hpp> // unicode_traits::convert
14
+ #include <jsoncons/config/jsoncons_config.hpp>
15
+ #include <jsoncons/traits_extension.hpp>
16
+
17
+ namespace jsoncons {
18
+
19
+ // json_exception
20
+
21
+ class json_exception
22
+ {
23
+ public:
24
+ virtual ~json_exception() noexcept = default;
25
+ virtual const char* what() const noexcept = 0;
26
+ };
27
+
28
+ // json_runtime_error
29
+
30
+ template <class Base, class Enable = void>
31
+ class json_runtime_error
32
+ {
33
+ };
34
+
35
+ template <class Base>
36
+ class json_runtime_error<Base,
37
+ typename std::enable_if<std::is_convertible<Base*,std::exception*>::value &&
38
+ traits_extension::is_constructible_from_string<Base>::value>::type>
39
+ : public Base, public virtual json_exception
40
+ {
41
+ public:
42
+ json_runtime_error(const std::string& s) noexcept
43
+ : Base(s)
44
+ {
45
+ }
46
+ ~json_runtime_error() noexcept
47
+ {
48
+ }
49
+ const char* what() const noexcept override
50
+ {
51
+ return Base::what();
52
+ }
53
+ };
54
+
55
+ class key_not_found : public std::out_of_range, public virtual json_exception
56
+ {
57
+ std::string name_;
58
+ mutable std::string what_;
59
+ public:
60
+ template <class CharT>
61
+ explicit key_not_found(const CharT* key, std::size_t length) noexcept
62
+ : std::out_of_range("Key not found")
63
+ {
64
+ JSONCONS_TRY
65
+ {
66
+ unicode_traits::convert(key, length, name_,
67
+ unicode_traits::conv_flags::strict);
68
+ }
69
+ JSONCONS_CATCH(...)
70
+ {
71
+ }
72
+ }
73
+
74
+ virtual ~key_not_found() noexcept
75
+ {
76
+ }
77
+
78
+ const char* what() const noexcept override
79
+ {
80
+ if (what_.empty())
81
+ {
82
+ JSONCONS_TRY
83
+ {
84
+ what_.append(std::out_of_range::what());
85
+ what_.append(": '");
86
+ what_.append(name_);
87
+ what_.append("'");
88
+ return what_.c_str();
89
+ }
90
+ JSONCONS_CATCH(...)
91
+ {
92
+ return std::out_of_range::what();
93
+ }
94
+ }
95
+ else
96
+ {
97
+ return what_.c_str();
98
+ }
99
+ }
100
+ };
101
+
102
+ class not_an_object : public std::runtime_error, public virtual json_exception
103
+ {
104
+ std::string name_;
105
+ mutable std::string what_;
106
+ public:
107
+ template <class CharT>
108
+ explicit not_an_object(const CharT* key, std::size_t length) noexcept
109
+ : std::runtime_error("Attempting to access a member of a value that is not an object")
110
+ {
111
+ JSONCONS_TRY
112
+ {
113
+ unicode_traits::convert(key, length, name_,
114
+ unicode_traits::conv_flags::strict);
115
+ }
116
+ JSONCONS_CATCH(...)
117
+ {
118
+ }
119
+ }
120
+
121
+ virtual ~not_an_object() noexcept
122
+ {
123
+ }
124
+ const char* what() const noexcept override
125
+ {
126
+ if (what_.empty())
127
+ {
128
+ JSONCONS_TRY
129
+ {
130
+ what_.append(std::runtime_error::what());
131
+ what_.append(": '");
132
+ what_.append(name_);
133
+ what_.append("'");
134
+ return what_.c_str();
135
+ }
136
+ JSONCONS_CATCH(...)
137
+ {
138
+ return std::runtime_error::what();
139
+ }
140
+ }
141
+ else
142
+ {
143
+ return what_.c_str();
144
+ }
145
+ }
146
+ };
147
+
148
+ class ser_error : public std::system_error, public virtual json_exception
149
+ {
150
+ std::size_t line_number_;
151
+ std::size_t column_number_;
152
+ mutable std::string what_;
153
+ public:
154
+ ser_error(std::error_code ec)
155
+ : std::system_error(ec), line_number_(0), column_number_(0)
156
+ {
157
+ }
158
+ ser_error(std::error_code ec, const std::string& what_arg)
159
+ : std::system_error(ec, what_arg), line_number_(0), column_number_(0)
160
+ {
161
+ }
162
+ ser_error(std::error_code ec, std::size_t position)
163
+ : std::system_error(ec), line_number_(0), column_number_(position)
164
+ {
165
+ }
166
+ ser_error(std::error_code ec, std::size_t line, std::size_t column)
167
+ : std::system_error(ec), line_number_(line), column_number_(column)
168
+ {
169
+ }
170
+ ser_error(const ser_error& other) = default;
171
+
172
+ ser_error(ser_error&& other) = default;
173
+
174
+ const char* what() const noexcept override
175
+ {
176
+ if (what_.empty())
177
+ {
178
+ JSONCONS_TRY
179
+ {
180
+ what_.append(std::system_error::what());
181
+ if (line_number_ != 0 && column_number_ != 0)
182
+ {
183
+ what_.append(" at line ");
184
+ what_.append(std::to_string(line_number_));
185
+ what_.append(" and column ");
186
+ what_.append(std::to_string(column_number_));
187
+ }
188
+ else if (column_number_ != 0)
189
+ {
190
+ what_.append(" at position ");
191
+ what_.append(std::to_string(column_number_));
192
+ }
193
+ return what_.c_str();
194
+ }
195
+ JSONCONS_CATCH(...)
196
+ {
197
+ return std::system_error::what();
198
+ }
199
+ }
200
+ else
201
+ {
202
+ return what_.c_str();
203
+ }
204
+ }
205
+
206
+ std::size_t line() const noexcept
207
+ {
208
+ return line_number_;
209
+ }
210
+
211
+ std::size_t column() const noexcept
212
+ {
213
+ return column_number_;
214
+ }
215
+
216
+ #if !defined(JSONCONS_NO_DEPRECATED)
217
+ JSONCONS_DEPRECATED_MSG("Instead, use line()")
218
+ std::size_t line_number() const noexcept
219
+ {
220
+ return line();
221
+ }
222
+
223
+ JSONCONS_DEPRECATED_MSG("Instead, use column()")
224
+ std::size_t column_number() const noexcept
225
+ {
226
+ return column();
227
+ }
228
+ #endif
229
+ };
230
+
231
+ #if !defined(JSONCONS_NO_DEPRECATED)
232
+ JSONCONS_DEPRECATED_MSG("Instead, use ser_error") typedef ser_error serialization_error;
233
+ JSONCONS_DEPRECATED_MSG("Instead, use ser_error") typedef ser_error json_parse_exception;
234
+ JSONCONS_DEPRECATED_MSG("Instead, use ser_error") typedef ser_error parse_exception;
235
+ JSONCONS_DEPRECATED_MSG("Instead, use ser_error") typedef ser_error parse_error;
236
+ typedef ser_error codec_error;
237
+ #endif
238
+
239
+ } // namespace jsoncons
240
+
241
+ #endif