@@ -117,7 +117,7 @@ namespace glz
117
117
}
118
118
}
119
119
};
120
-
120
+
121
121
// CSV spec: https://www.ietf.org/rfc/rfc4180.txt
122
122
// Quotes are escaped via double quotes
123
123
@@ -151,43 +151,34 @@ namespace glz
151
151
// Escaped quote
152
152
value.push_back (' "' );
153
153
++it;
154
- } else {
154
+ }
155
+ else {
155
156
// Closing quote
156
157
break ;
157
158
}
158
- } else {
159
+ }
160
+ else {
159
161
value.push_back (*it);
160
162
++it;
161
163
}
162
164
}
163
165
// After closing quote, expect comma, newline, or end of input
164
- if (it != end) {
165
- if (*it == ' ,' ) {
166
- ++it; // Skip the comma
167
- } else if (*it == ' \n ' ) {
168
- // End of record, do nothing
169
- } else if (it == end) {
170
- // End of input
171
- } else {
172
- // Invalid character after closing quote
173
- ctx.error = error_code::syntax_error;
174
- return ;
175
- }
166
+ if (it != end && *it != ' ,' && *it == ' \n ' ) {
167
+ // Invalid character after closing quote
168
+ ctx.error = error_code::syntax_error;
169
+ return ;
176
170
}
177
- } else {
171
+ }
172
+ else {
178
173
// Unquoted field
179
174
while (it != end && *it != ' ,' && *it != ' \n ' ) {
180
175
value.push_back (*it);
181
176
++it;
182
177
}
183
- if (it != end && *it == ' ,' ) {
184
- ++it; // Skip the comma
185
- }
186
178
}
187
179
}
188
180
};
189
181
190
-
191
182
template <bool_t T>
192
183
struct from <CSV, T>
193
184
{
@@ -220,8 +211,7 @@ namespace glz
220
211
template <char delim>
221
212
inline void goto_delim (auto && it, auto && end) noexcept
222
213
{
223
- while (++it != end && *it != delim)
224
- ;
214
+ while (++it != end && *it != delim);
225
215
}
226
216
227
217
inline auto read_column_wise_keys (auto && ctx, auto && it, auto && end)
@@ -469,87 +459,89 @@ namespace glz
469
459
decode_hash_with_size<CSV, T, HashInfo, HashInfo.type >::op (key.data (), end, key.size ());
470
460
471
461
if (index < N) [[likely]] {
472
- visit<N>([&]<size_t I>() {
473
- decltype (auto ) member = [&]() -> decltype (auto ) {
474
- if constexpr (reflectable<T>) {
475
- return get_member (value, get<I>(to_tuple (value)));
476
- }
477
- else {
478
- return get_member (value, get<I>(reflect<T>::values));
479
- }
480
- }();
481
-
482
- using M = std::decay_t <decltype (member)>;
483
- if constexpr (fixed_array_value_t <M> && emplace_backable<M>) {
484
- size_t col = 0 ;
485
- while (it != end) {
486
- if (col < member.size ()) [[likely]] {
487
- read <CSV>::op<Opts>(member[col][csv_index], ctx, it, end);
462
+ visit<N>(
463
+ [&]<size_t I>() {
464
+ decltype (auto ) member = [&]() -> decltype (auto ) {
465
+ if constexpr (reflectable<T>) {
466
+ return get_member (value, get<I>(to_tuple (value)));
488
467
}
489
- else [[unlikely]] {
490
- read <CSV>::op<Opts>(member. emplace_back ()[csv_index], ctx, it, end );
468
+ else {
469
+ return get_member (value, get<I>(reflect<T>::values) );
491
470
}
471
+ }();
472
+
473
+ using M = std::decay_t <decltype (member)>;
474
+ if constexpr (fixed_array_value_t <M> && emplace_backable<M>) {
475
+ size_t col = 0 ;
476
+ while (it != end) {
477
+ if (col < member.size ()) [[likely]] {
478
+ read <CSV>::op<Opts>(member[col][csv_index], ctx, it, end);
479
+ }
480
+ else [[unlikely]] {
481
+ read <CSV>::op<Opts>(member.emplace_back ()[csv_index], ctx, it, end);
482
+ }
492
483
493
- if (*it == ' \r ' ) {
494
- ++it;
495
- if (*it == ' \n ' ) {
484
+ if (*it == ' \r ' ) {
485
+ ++it;
486
+ if (*it == ' \n ' ) {
487
+ ++it;
488
+ break ;
489
+ }
490
+ else [[unlikely]] {
491
+ ctx.error = error_code::syntax_error;
492
+ return ;
493
+ }
494
+ }
495
+ else if (*it == ' \n ' ) {
496
496
++it;
497
497
break ;
498
498
}
499
+ else if (it == end) {
500
+ return ;
501
+ }
502
+
503
+ if (*it == ' ,' ) [[likely]] {
504
+ ++it;
505
+ }
499
506
else [[unlikely]] {
500
507
ctx.error = error_code::syntax_error;
501
508
return ;
502
509
}
503
- }
504
- else if (*it == ' \n ' ) {
505
- ++it;
506
- break ;
507
- }
508
- else if (it == end) {
509
- return ;
510
- }
511
510
512
- if (*it == ' ,' ) [[likely]] {
513
- ++it;
511
+ ++col;
514
512
}
515
- else [[unlikely]] {
516
- ctx.error = error_code::syntax_error;
517
- return ;
518
- }
519
-
520
- ++col;
521
513
}
522
- }
523
- else {
524
- while (it != end) {
525
- read <CSV>::op<Opts>(member, ctx, it, end);
514
+ else {
515
+ while (it != end) {
516
+ read <CSV>::op<Opts>(member, ctx, it, end);
526
517
527
- if (*it == ' \r ' ) {
528
- ++it;
529
- if (*it == ' \n ' ) {
518
+ if (*it == ' \r ' ) {
519
+ ++it;
520
+ if (*it == ' \n ' ) {
521
+ ++it;
522
+ break ;
523
+ }
524
+ else [[unlikely]] {
525
+ ctx.error = error_code::syntax_error;
526
+ return ;
527
+ }
528
+ }
529
+ else if (*it == ' \n ' ) {
530
530
++it;
531
531
break ;
532
532
}
533
+
534
+ if (*it == ' ,' ) [[likely]] {
535
+ ++it;
536
+ }
533
537
else [[unlikely]] {
534
538
ctx.error = error_code::syntax_error;
535
539
return ;
536
540
}
537
541
}
538
- else if (*it == ' \n ' ) {
539
- ++it;
540
- break ;
541
- }
542
-
543
- if (*it == ' ,' ) [[likely]] {
544
- ++it;
545
- }
546
- else [[unlikely]] {
547
- ctx.error = error_code::syntax_error;
548
- return ;
549
- }
550
542
}
551
- }
552
- }, index );
543
+ },
544
+ index );
553
545
554
546
if (bool (ctx.error )) [[unlikely]] {
555
547
return ;
0 commit comments