@@ -40,10 +40,13 @@ simdjson_really_inline json_iterator::~json_iterator() noexcept {
40
40
}
41
41
#endif
42
42
43
- SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_object () noexcept {
44
- if (*advance () != ' {' ) { return report_error (INCORRECT_TYPE , " Not an object" ); }
43
+ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_object (const uint8_t *json ) noexcept {
44
+ if (*json != ' {' ) { logger::log_error (* this , " Not an object" ); return INCORRECT_TYPE ; }
45
45
return started_object ();
46
46
}
47
+ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_object () noexcept {
48
+ return start_object (advance ());
49
+ }
47
50
48
51
SIMDJSON_WARN_UNUSED simdjson_really_inline bool json_iterator::started_object () noexcept {
49
52
if (*peek () == ' }' ) {
@@ -71,7 +74,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
71
74
bool has_next;
72
75
do {
73
76
raw_json_string actual_key;
74
- SIMDJSON_TRY ( get_raw_json_string ().get (actual_key) );
77
+ SIMDJSON_TRY ( consume_raw_json_string ().get (actual_key) );
75
78
if (*advance () != ' :' ) { return report_error (TAPE_ERROR, " Missing colon in object field" ); }
76
79
if (actual_key == key) {
77
80
logger::log_event (*this , " match" , key);
@@ -97,11 +100,15 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::field_valu
97
100
return SUCCESS;
98
101
}
99
102
100
- SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_array () noexcept {
101
- if (*advance () != ' [' ) { return report_error (INCORRECT_TYPE , " Not an array" ); }
103
+ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_array (const uint8_t *json ) noexcept {
104
+ if (*json != ' [' ) { logger::log_error (* this , " Not an array" ); return INCORRECT_TYPE ; }
102
105
return started_array ();
103
106
}
104
107
108
+ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_array () noexcept {
109
+ return start_array (advance ());
110
+ }
111
+
105
112
SIMDJSON_WARN_UNUSED simdjson_really_inline bool json_iterator::started_array () noexcept {
106
113
if (*peek () == ' ]' ) {
107
114
logger::log_value (*this , " empty array" );
@@ -124,46 +131,71 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
124
131
}
125
132
}
126
133
127
- SIMDJSON_WARN_UNUSED simdjson_result<raw_json_string> json_iterator::get_raw_json_string () noexcept {
134
+ SIMDJSON_WARN_UNUSED simdjson_result<std::string_view> json_iterator::parse_string (const uint8_t *json) noexcept {
135
+ return parse_raw_json_string (json).unescape (current_string_buf_loc);
136
+ }
137
+ SIMDJSON_WARN_UNUSED simdjson_result<std::string_view> json_iterator::consume_string () noexcept {
138
+ return parse_string (advance ());
139
+ }
140
+ SIMDJSON_WARN_UNUSED simdjson_result<raw_json_string> json_iterator::parse_raw_json_string (const uint8_t *json) noexcept {
128
141
logger::log_value (*this , " string" , " " , 0 );
129
- return raw_json_string (advance ()+1 );
142
+ if (*json != ' "' ) { logger::log_error (*this , " Not a string" ); return INCORRECT_TYPE; }
143
+ return raw_json_string (json+1 );
130
144
}
131
- SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::get_uint64 () noexcept {
145
+ SIMDJSON_WARN_UNUSED simdjson_result<raw_json_string> json_iterator::consume_raw_json_string () noexcept {
146
+ return parse_raw_json_string (advance ());
147
+ }
148
+ SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::parse_uint64 (const uint8_t *json) noexcept {
132
149
logger::log_value (*this , " uint64" , " " , 0 );
133
- return numberparsing::parse_unsigned (advance ());
150
+ return numberparsing::parse_unsigned (json);
151
+ }
152
+ SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::consume_uint64 () noexcept {
153
+ return parse_uint64 (advance ());
134
154
}
135
- SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::get_int64 ( ) noexcept {
155
+ SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::parse_int64 ( const uint8_t *json ) noexcept {
136
156
logger::log_value (*this , " int64" , " " , 0 );
137
- return numberparsing::parse_integer (advance ());
157
+ return numberparsing::parse_integer (json);
158
+ }
159
+ SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::consume_int64 () noexcept {
160
+ return parse_int64 (advance ());
138
161
}
139
- SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::get_double ( ) noexcept {
162
+ SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::parse_double ( const uint8_t *json ) noexcept {
140
163
logger::log_value (*this , " double" , " " , 0 );
141
- return numberparsing::parse_double (advance () );
164
+ return numberparsing::parse_double (json );
142
165
}
143
- SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::get_bool () noexcept {
166
+ SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::consume_double () noexcept {
167
+ return parse_double (advance ());
168
+ }
169
+ SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::parse_bool (const uint8_t *json) noexcept {
144
170
logger::log_value (*this , " bool" , " " , 0 );
145
- auto json = advance ();
146
171
auto not_true = atomparsing::str4ncmp (json, " true" );
147
172
auto not_false = atomparsing::str4ncmp (json, " fals" ) | (json[4 ] ^ ' e' );
148
173
bool error = (not_true && not_false) || jsoncharutils::is_not_structural_or_whitespace (json[not_true ? 5 : 4 ]);
149
- if (error) { return report_error (INCORRECT_TYPE , " not a boolean" ); }
174
+ if (error) { logger::log_error (* this , " Not a boolean" ); return INCORRECT_TYPE ; }
150
175
return simdjson_result<bool >(!not_true);
151
176
}
152
- simdjson_really_inline bool json_iterator::is_null () noexcept {
153
- auto json = peek ();
177
+ SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::consume_bool () noexcept {
178
+ return parse_bool (advance ());
179
+ }
180
+ simdjson_really_inline bool json_iterator::is_null (const uint8_t *json) noexcept {
154
181
if (!atomparsing::str4ncmp (json, " null" )) {
155
182
logger::log_value (*this , " null" , " " , 0 );
183
+ return true ;
184
+ }
185
+ return false ;
186
+ }
187
+ simdjson_really_inline bool json_iterator::is_null () noexcept {
188
+ if (is_null (peek ())) {
156
189
advance ();
157
190
return true ;
158
191
}
159
192
return false ;
160
193
}
161
194
162
195
template <int N>
163
- SIMDJSON_WARN_UNUSED simdjson_really_inline bool json_iterator::advance_to_buffer ( uint8_t (&tmpbuf)[N]) noexcept {
196
+ SIMDJSON_WARN_UNUSED simdjson_really_inline bool json_iterator::copy_to_buffer ( const uint8_t *json, uint8_t (&tmpbuf)[N]) noexcept {
164
197
// Truncate whitespace to fit the buffer.
165
- auto len = peek_length ();
166
- auto json = advance ();
198
+ auto len = peek_length (-1 );
167
199
if (len > N-1 ) {
168
200
if (jsoncharutils::is_not_structural_or_whitespace (json[N])) { return false ; }
169
201
len = N-1 ;
@@ -177,39 +209,51 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline bool json_iterator::advance_to_buffe
177
209
178
210
constexpr const uint32_t MAX_INT_LENGTH = 1024 ;
179
211
180
- SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::get_root_uint64 ( ) noexcept {
212
+ SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::parse_root_uint64 ( const uint8_t *json ) noexcept {
181
213
uint8_t tmpbuf[20 +1 ]; // <20 digits> is the longest possible unsigned integer
182
- if (!advance_to_buffer ( tmpbuf)) { return report_error (NUMBER_ERROR , " Root number more than 20 digits " ) ; }
214
+ if (!copy_to_buffer (json, tmpbuf)) { logger::log_error (* this , " Root number more than 20 characters " ); return NUMBER_ERROR ; }
183
215
logger::log_value (*this , " uint64" , " " , 0 );
184
216
auto result = numberparsing::parse_unsigned (buf);
185
- if (result.error ()) { report_error (result. error () , " Error parsing unsigned integer" ); }
217
+ if (result.error ()) { logger::log_error (* this , " Error parsing unsigned integer" ); return result. error ( ); }
186
218
return result;
187
219
}
188
- SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::get_root_int64 () noexcept {
220
+ SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::consume_root_uint64 () noexcept {
221
+ return parse_root_uint64 (advance ());
222
+ }
223
+ SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::parse_root_int64 (const uint8_t *json) noexcept {
189
224
uint8_t tmpbuf[20 +1 ]; // -<19 digits> is the longest possible integer
190
- if (!advance_to_buffer ( tmpbuf)) { return report_error (NUMBER_ERROR , " Root number more than 20 characters" ); }
225
+ if (!copy_to_buffer (json, tmpbuf)) { logger::log_error (* this , " Root number more than 20 characters" ); return NUMBER_ERROR ; }
191
226
logger::log_value (*this , " int64" , " " , 0 );
192
227
auto result = numberparsing::parse_integer (buf);
193
228
if (result.error ()) { report_error (result.error (), " Error parsing integer" ); }
194
229
return result;
195
230
}
196
- SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::get_root_double () noexcept {
231
+ SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::consume_root_int64 () noexcept {
232
+ return parse_root_int64 (advance ());
233
+ }
234
+ SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::parse_root_double (const uint8_t *json) noexcept {
197
235
// Per https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/, 1074 is the maximum number of significant fractional digits. Add 8 more digits for the biggest number: -0.<fraction>e-308.
198
236
uint8_t tmpbuf[1074 +8 +1 ];
199
- if (!advance_to_buffer ( tmpbuf)) { return report_error (NUMBER_ERROR , " Root float more than 1082 digits " ) ; }
237
+ if (!copy_to_buffer (json, tmpbuf)) { logger::log_error (* this , " Root number more than 1082 characters " ); return NUMBER_ERROR ; }
200
238
logger::log_value (*this , " double" , " " , 0 );
201
239
auto result = numberparsing::parse_double (buf);
202
240
if (result.error ()) { report_error (result.error (), " Error parsing double" ); }
203
241
return result;
204
242
}
205
- SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::get_root_bool () noexcept {
243
+ SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::consume_root_double () noexcept {
244
+ return parse_root_double (advance ());
245
+ }
246
+ SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::parse_root_bool (const uint8_t *json) noexcept {
206
247
uint8_t tmpbuf[5 +1 ];
207
- if (!advance_to_buffer (tmpbuf)) { return INCORRECT_TYPE; } // Too big! Can't be true or false
208
- return get_bool ();
248
+ if (!copy_to_buffer (json, tmpbuf)) { logger::log_error (*this , " Not a boolean" ); return INCORRECT_TYPE; }
249
+ return consume_bool ();
250
+ }
251
+ SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::consume_root_bool () noexcept {
252
+ return parse_root_bool (advance ());
209
253
}
210
- simdjson_really_inline bool json_iterator::root_is_null () noexcept {
254
+ simdjson_really_inline bool json_iterator::root_is_null (const uint8_t *json ) noexcept {
211
255
uint8_t tmpbuf[4 +1 ];
212
- if (!advance_to_buffer ( tmpbuf)) { return false ; } // Too big! Can't be null
256
+ if (!copy_to_buffer (json, tmpbuf)) { return false ; }
213
257
return is_null ();
214
258
}
215
259
0 commit comments