@@ -159,6 +159,57 @@ namespace glz::yaml
159159 return t;
160160 }();
161161
162+ // Table for characters that terminate a plain scalar in flow context
163+ // Terminators: space, tab, newline, carriage return, colon, comma, [ ] { } #
164+ inline constexpr std::array<bool , 256 > plain_scalar_end_table = [] {
165+ std::array<bool , 256 > t{};
166+ t[' ' ] = true ;
167+ t[' \t ' ] = true ;
168+ t[' \n ' ] = true ;
169+ t[' \r ' ] = true ;
170+ t[' :' ] = true ;
171+ t[' ,' ] = true ;
172+ t[' [' ] = true ;
173+ t[' ]' ] = true ;
174+ t[' {' ] = true ;
175+ t[' }' ] = true ;
176+ t[' #' ] = true ;
177+ return t;
178+ }();
179+
180+ // Table for whitespace and line ending characters
181+ // Characters: space, tab, newline, carriage return
182+ inline constexpr std::array<bool , 256 > whitespace_or_line_end_table = [] {
183+ std::array<bool , 256 > t{};
184+ t[' ' ] = true ;
185+ t[' \t ' ] = true ;
186+ t[' \n ' ] = true ;
187+ t[' \r ' ] = true ;
188+ return t;
189+ }();
190+
191+ // Table for line ending or comment characters
192+ // Characters: newline, carriage return, #
193+ inline constexpr std::array<bool , 256 > line_end_or_comment_table = [] {
194+ std::array<bool , 256 > t{};
195+ t[' \n ' ] = true ;
196+ t[' \r ' ] = true ;
197+ t[' #' ] = true ;
198+ return t;
199+ }();
200+
201+ // Table for flow context ending characters (line end + flow terminators)
202+ // Characters: newline, carriage return, comma, ] }
203+ inline constexpr std::array<bool , 256 > flow_context_end_table = [] {
204+ std::array<bool , 256 > t{};
205+ t[' \n ' ] = true ;
206+ t[' \r ' ] = true ;
207+ t[' ,' ] = true ;
208+ t[' ]' ] = true ;
209+ t[' }' ] = true ;
210+ return t;
211+ }();
212+
162213 // Scalar style detection
163214 enum struct scalar_style : uint8_t {
164215 plain, // unquoted
@@ -208,8 +259,7 @@ namespace glz::yaml
208259
209260 // Read tag name
210261 auto tag_start = it;
211- while (it != end && *it != ' ' && *it != ' \t ' && *it != ' \n ' && *it != ' \r ' && *it != ' :' && *it != ' ,' &&
212- *it != ' [' && *it != ' ]' && *it != ' {' && *it != ' }' ) {
262+ while (it != end && !plain_scalar_end_table[static_cast <uint8_t >(*it)]) {
213263 ++it;
214264 }
215265
@@ -265,8 +315,7 @@ namespace glz::yaml
265315 }
266316
267317 // Named tag !name - skip it and read name
268- while (it != end && *it != ' ' && *it != ' \t ' && *it != ' \n ' && *it != ' \r ' && *it != ' :' && *it != ' ,' &&
269- *it != ' [' && *it != ' ]' && *it != ' {' && *it != ' }' ) {
318+ while (it != end && !plain_scalar_end_table[static_cast <uint8_t >(*it)]) {
270319 ++it;
271320 }
272321
@@ -457,7 +506,7 @@ namespace glz::yaml
457506
458507 // Check if this is a content line (not blank, not comment-only)
459508 skip_inline_ws (it, end);
460- if (it != end && *it != ' \n ' && *it != ' \r ' && *it != ' # ' ) {
509+ if (it != end && !line_end_or_comment_table[ static_cast < uint8_t >( *it)] ) {
461510 it = start; // Reset to start of line
462511 return indent;
463512 }
0 commit comments