@@ -13,8 +13,6 @@ namespace fly::parser {
13
13
14
14
namespace {
15
15
16
- using JsonString = fly::JsonTraits::StringType;
17
-
18
16
inline bool
19
17
is_feature_enabled (JsonParser::Features enabled_features, JsonParser::Features feature)
20
18
{
@@ -102,7 +100,7 @@ std::optional<fly::Json> JsonParser::parse_object()
102
100
{
103
101
static constexpr const Token s_end_token = Token::CloseBrace;
104
102
105
- fly::Json object = fly::JsonTraits::object_type ();
103
+ fly::Json object = fly::json_object_type ();
106
104
ParseState state;
107
105
108
106
// Discard the opening brace, which has already been peeked.
@@ -115,7 +113,7 @@ std::optional<fly::Json> JsonParser::parse_object()
115
113
break ;
116
114
}
117
115
118
- std::optional<fly::JsonTraits::string_type > key = parse_quoted_string ();
116
+ std::optional<fly::json_string_type > key = parse_quoted_string ();
119
117
120
118
if (!key || (consume_token (Token::Colon) == ParseState::Invalid))
121
119
{
@@ -140,7 +138,7 @@ std::optional<fly::Json> JsonParser::parse_array()
140
138
{
141
139
static constexpr const Token s_end_token = Token::CloseBracket;
142
140
143
- fly::Json array = fly::JsonTraits::array_type ();
141
+ fly::Json array = fly::json_array_type ();
144
142
ParseState state;
145
143
146
144
// Discard the opening bracket, which has already been peeked.
@@ -191,9 +189,9 @@ JsonParser::ParseState JsonParser::state_for_object_or_array(Token end_token)
191
189
}
192
190
193
191
// ==================================================================================================
194
- std::optional<fly::JsonTraits::string_type > JsonParser::parse_quoted_string ()
192
+ std::optional<fly::json_string_type > JsonParser::parse_quoted_string ()
195
193
{
196
- fly::JsonTraits::string_type value;
194
+ fly::json_string_type value;
197
195
Token token;
198
196
199
197
if (consume_token (Token::Quote) == ParseState::Invalid)
@@ -203,14 +201,14 @@ std::optional<fly::JsonTraits::string_type> JsonParser::parse_quoted_string()
203
201
204
202
while ((token = get<Token>()) != Token::Quote)
205
203
{
206
- value.push_back (static_cast <fly::JsonTraits::char_type >(token));
204
+ value.push_back (static_cast <fly::json_char_type >(token));
207
205
208
206
if (token == Token::ReverseSolidus)
209
207
{
210
208
// Blindly ignore escaped symbols, the fly::Json class will check whether they are
211
209
// valid. Just read at least one more symbol to prevent breaking out of the loop too
212
210
// early if the next symbol is a quote.
213
- value.push_back (get<fly::JsonTraits::char_type >());
211
+ value.push_back (get<fly::json_char_type >());
214
212
}
215
213
else if (token == Token::EndOfFile)
216
214
{
@@ -224,7 +222,7 @@ std::optional<fly::JsonTraits::string_type> JsonParser::parse_quoted_string()
224
222
// ==================================================================================================
225
223
std::optional<fly::Json> JsonParser::parse_value ()
226
224
{
227
- const fly::JsonTraits::string_type value = consume_value ();
225
+ const fly::json_string_type value = consume_value ();
228
226
229
227
if (value == FLY_JSON_STR (" true" ))
230
228
{
@@ -242,21 +240,22 @@ std::optional<fly::Json> JsonParser::parse_value()
242
240
switch (validate_number (value))
243
241
{
244
242
case NumberType::SignedInteger:
245
- if (auto num = JsonString:: convert<fly::JsonTraits::signed_type >(value); num)
243
+ if (auto num = fly::JsonStringType:: convert<fly::json_signed_integer_type >(value); num)
246
244
{
247
245
return *num;
248
246
}
249
247
break ;
250
248
251
249
case NumberType::UnsignedInteger:
252
- if (auto num = JsonString::convert<fly::JsonTraits::unsigned_type>(value); num)
250
+ if (auto num = fly::JsonStringType::convert<fly::json_unsigned_integer_type>(value);
251
+ num)
253
252
{
254
253
return *num;
255
254
}
256
255
break ;
257
256
258
257
case NumberType::FloatingPoint:
259
- if (auto num = JsonString:: convert<fly::JsonTraits::float_type >(value); num)
258
+ if (auto num = fly::JsonStringType:: convert<fly::json_floating_point_type >(value); num)
260
259
{
261
260
return *num;
262
261
}
@@ -306,9 +305,9 @@ JsonParser::ParseState JsonParser::consume_comma(Token end_token)
306
305
}
307
306
308
307
// ==================================================================================================
309
- fly::JsonTraits::string_type JsonParser::consume_value ()
308
+ fly::json_string_type JsonParser::consume_value ()
310
309
{
311
- fly::JsonTraits::string_type value;
310
+ fly::json_string_type value;
312
311
313
312
auto keep_parsing = [this ](Token token) -> bool
314
313
{
@@ -328,7 +327,7 @@ fly::JsonTraits::string_type JsonParser::consume_value()
328
327
329
328
while (keep_parsing (peek<Token>()))
330
329
{
331
- value.push_back (get<fly::JsonTraits::char_type >());
330
+ value.push_back (get<fly::json_char_type >());
332
331
}
333
332
334
333
return value;
@@ -418,9 +417,9 @@ JsonParser::ParseState JsonParser::consume_comment()
418
417
}
419
418
420
419
// ==================================================================================================
421
- JsonParser::NumberType JsonParser::validate_number (const fly::JsonTraits::string_type &value) const
420
+ JsonParser::NumberType JsonParser::validate_number (const fly::json_string_type &value) const
422
421
{
423
- const JsonString ::view_type value_view = value;
422
+ const fly::JsonStringType ::view_type value_view = value;
424
423
425
424
const bool is_signed = !value_view.empty () && (value_view[0 ] == ' -' );
426
425
const auto signless = value_view.substr (is_signed ? 1 : 0 );
@@ -431,23 +430,22 @@ JsonParser::NumberType JsonParser::validate_number(const fly::JsonTraits::string
431
430
}
432
431
433
432
const bool is_octal =
434
- (signless.size () > 1 ) && (signless[0 ] == ' 0' ) && JsonString ::is_digit (signless[1 ]);
433
+ (signless.size () > 1 ) && (signless[0 ] == ' 0' ) && fly::JsonStringType ::is_digit (signless[1 ]);
435
434
436
- if (!JsonString ::is_digit (signless[0 ]) || is_octal)
435
+ if (!fly::JsonStringType ::is_digit (signless[0 ]) || is_octal)
437
436
{
438
437
return NumberType::Invalid;
439
438
}
440
439
441
- const fly::JsonTraits::string_type ::size_type d = signless.find (' .' );
442
- const fly::JsonTraits::string_type ::size_type e1 = signless.find (' e' );
443
- const fly::JsonTraits::string_type ::size_type e2 = signless.find (' E' );
440
+ const fly::json_string_type ::size_type d = signless.find (' .' );
441
+ const fly::json_string_type ::size_type e1 = signless.find (' e' );
442
+ const fly::json_string_type ::size_type e2 = signless.find (' E' );
444
443
445
- if (d != fly::JsonTraits::string_type ::npos)
444
+ if (d != fly::json_string_type ::npos)
446
445
{
447
- fly::JsonTraits::string_type ::size_type end = signless.size ();
446
+ fly::json_string_type ::size_type end = signless.size ();
448
447
449
- if ((e1 != fly::JsonTraits::string_type::npos) ||
450
- (e2 != fly::JsonTraits::string_type::npos))
448
+ if ((e1 != fly::json_string_type::npos) || (e2 != fly::json_string_type::npos))
451
449
{
452
450
end = std::min (e1 , e2 );
453
451
}
@@ -459,8 +457,7 @@ JsonParser::NumberType JsonParser::validate_number(const fly::JsonTraits::string
459
457
460
458
return NumberType::FloatingPoint;
461
459
}
462
- else if (
463
- (e1 != fly::JsonTraits::string_type::npos) || (e2 != fly::JsonTraits::string_type::npos))
460
+ else if ((e1 != fly::json_string_type::npos) || (e2 != fly::json_string_type::npos))
464
461
{
465
462
return NumberType::FloatingPoint;
466
463
}
0 commit comments