libstdc++
regex_executor.tcc
Go to the documentation of this file.
1// class template regex -*- C++ -*-
2
3// Copyright (C) 2013-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/**
26 * @file bits/regex_executor.tcc
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{regex}
29 */
30
31namespace std _GLIBCXX_VISIBILITY(default)
32{
33_GLIBCXX_BEGIN_NAMESPACE_VERSION
34
35#pragma GCC diagnostic push
36#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
37namespace __detail
38{
39_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
40 template<typename _BiIter, typename _Alloc, typename _TraitsT,
41 bool __dfs_mode>
44 {
45 if (_M_search_from_first())
46 return true;
48 return false;
50 while (_M_begin != _M_end)
51 {
52 ++_M_begin;
53 if (_M_search_from_first())
54 return true;
55 }
56 return false;
57 }
58
59 enum _ExecutorFrameOpcode : unsigned char
60 {
61 _S_fopcode_next,
62 _S_fopcode_fallback_next,
63 _S_fopcode_rep_once_more,
64 _S_fopcode_fallback_rep_once_more,
65 _S_fopcode_posix_alternative,
66 _S_fopcode_merge_sol,
67 _S_fopcode_restore_cur_results,
68 _S_fopcode_restore_rep_count,
69 _S_fopcode_decrement_rep_count,
70 };
71
72#pragma GCC diagnostic push
73#pragma GCC diagnostic ignored "-Wpedantic" // anon struct
74 struct _ExecutorFrameBase
75 {
76 _ExecutorFrameBase(_ExecutorFrameOpcode __op, _StateIdT __i)
77 : _M_op(__op), _M_state_id(__i)
78 { }
79
80 _ExecutorFrameOpcode _M_op;
81 union {
82 unsigned char _M_byte0 = 0;
83 struct { // Used by restore_rep_count frame
84 unsigned char _M_count : 2;
85 };
86 struct { // Used by restore_cur_results frame
87 unsigned char _M_subexpr_end : 1;
88 unsigned char _M_matched : 1;
89 };
90 };
91 unsigned char _M_bytes[6];
92 _StateIdT _M_state_id;
93 };
94#pragma GCC diagnostic pop
95
96 template<typename _BiIter, bool _Trivial /* = is_trivially_copyable<_BiIter>::value */>
97 struct _ExecutorFrame : _ExecutorFrameBase
98 {
99 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i)
100 : _ExecutorFrameBase(__op, __i)
101 { }
102
103 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i, _BiIter __p)
104 : _ExecutorFrameBase(__op, __i), _M_pos(__p)
105 { }
106
107 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i, long __v)
108 : _ExecutorFrameBase(__op, __i), _M_val(__v)
109 { }
110
111 // _M_pos and _M_val are mutually exclusive, which the optimized
112 // partial specialization below depends on.
113 _BiIter _M_pos = _BiIter();
114 long _M_val = 0;
115 };
116
117 // Space-optimized partial specialization for when the input iterator is
118 // trivially copyable.
119 template<typename _BiIter>
120 struct _ExecutorFrame<_BiIter, true> : _ExecutorFrameBase
121 {
122 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i)
123 : _ExecutorFrameBase(__op, __i)
124 { }
125
126 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i, _BiIter __p)
127 : _ExecutorFrameBase(__op, __i), _M_pos(__p)
128 { }
129
130 _ExecutorFrame(_ExecutorFrameOpcode __op, _StateIdT __i, long __v)
131 : _ExecutorFrameBase(__op, __i), _M_val(__v)
132 { }
133
134 union {
135 _BiIter _M_pos;
136 long _M_val;
137 };
138 };
139
140 // The _M_main function operates in different modes, DFS mode or BFS mode,
141 // indicated by template parameter __dfs_mode, and dispatches to one of the
142 // _M_main_dispatch overloads.
143 //
144 // ------------------------------------------------------------
145 //
146 // DFS mode:
147 //
148 // It applies a Depth-First-Search (aka backtracking) on given NFA and input
149 // string.
150 // At the very beginning the executor stands in the start state, then it
151 // tries every possible state transition in current state recursively. Some
152 // state transitions consume input string, say, a single-char-matcher or a
153 // back-reference matcher; some don't, like assertion or other anchor nodes.
154 // When the input is exhausted and/or the current state is an accepting
155 // state, the whole executor returns true.
156 //
157 // TODO: This approach is exponentially slow for certain input.
158 // Try to compile the NFA to a DFA.
159 //
160 // Time complexity: \Omega(match_length), O(2^(_M_nfa.size()))
161 // Space complexity: \theta(match_results.size() + match_length)
162 //
163 template<typename _BiIter, typename _Alloc, typename _TraitsT,
164 bool __dfs_mode>
166 _M_main_dispatch(_Match_mode __match_mode, __dfs)
167 {
168 _M_has_sol = false;
169 *_M_states._M_get_sol_pos() = _BiIter();
170 _M_cur_results = _M_results;
171 _M_dfs(__match_mode, _M_states._M_start);
172 return _M_has_sol;
173 }
174
175 // ------------------------------------------------------------
176 //
177 // BFS mode:
178 //
179 // Russ Cox's article (http://swtch.com/~rsc/regexp/regexp1.html)
180 // explained this algorithm clearly.
181 //
182 // It first computes epsilon closure (states that can be achieved without
183 // consuming characters) for every state that's still matching,
184 // using the same DFS algorithm, but doesn't re-enter states (using
185 // _M_states._M_visited to check), nor follow _S_opcode_match.
186 //
187 // Then apply DFS using every _S_opcode_match (in _M_states._M_match_queue)
188 // as the start state.
189 //
190 // It significantly reduces potential duplicate states, so has a better
191 // upper bound; but it requires more overhead.
192 //
193 // Time complexity: \Omega(match_length * match_results.size())
194 // O(match_length * _M_nfa.size() * match_results.size())
195 // Space complexity: \Omega(_M_nfa.size() + match_results.size())
196 // O(_M_nfa.size() * match_results.size())
197 template<typename _BiIter, typename _Alloc, typename _TraitsT,
198 bool __dfs_mode>
200 _M_main_dispatch(_Match_mode __match_mode, __bfs)
201 {
202 _M_states._M_queue(_M_states._M_start, _M_results);
203 bool __ret = false;
204 while (1)
205 {
206 _M_has_sol = false;
207 if (_M_states._M_match_queue.empty())
208 break;
209 std::fill_n(_M_states._M_visited_states, _M_nfa.size(), false);
210 auto __old_queue = std::move(_M_states._M_match_queue);
211 auto __alloc = _M_cur_results.get_allocator();
212 for (auto& __task : __old_queue)
213 {
214 _M_cur_results = _ResultsVec(std::move(__task.second), __alloc);
215 _M_dfs(__match_mode, __task.first);
216 }
217 if (__match_mode == _Match_mode::_Prefix)
218 __ret |= _M_has_sol;
219 if (_M_current == _M_end)
220 break;
221 ++_M_current;
222 }
223 if (__match_mode == _Match_mode::_Exact)
224 __ret = _M_has_sol;
225 _M_states._M_match_queue.clear();
226 return __ret;
227 }
228
229 // Return whether now match the given sub-NFA.
230 template<typename _BiIter, typename _Alloc, typename _TraitsT,
231 bool __dfs_mode>
233 _M_lookahead(_StateIdT __next)
234 {
235 // Backreferences may refer to captured content.
236 // We may want to make this faster by not copying,
237 // but let's not be clever prematurely.
238 _ResultsVec __what(_M_cur_results);
239 _Executor __sub(_M_current, _M_end, __what, _M_re, _M_flags);
240 __sub._M_states._M_start = __next;
241 if (__sub._M_search_from_first())
242 {
243 for (size_t __i = 0; __i < __what.size(); __i++)
244 if (__what[__i].matched)
245 _M_cur_results[__i] = __what[__i];
246 return true;
247 }
248 return false;
249 }
250
251 // __rep_count records how many times (__rep_count.second)
252 // this node is visited under certain input iterator
253 // (__rep_count.first). This prevent the executor from entering
254 // infinite loop by refusing to continue when it's already been
255 // visited more than twice. It's `twice` instead of `once` because
256 // we need to spare one more time for potential group capture.
257 template<typename _BiIter, typename _Alloc, typename _TraitsT,
258 bool __dfs_mode>
260 _M_rep_once_more(_Match_mode __match_mode, _StateIdT __i)
261 {
262 const auto& __state = _M_nfa[__i];
263 auto& __rep_count = _M_rep_count[__i];
264 if (__rep_count.second == 0 || __rep_count.first != _M_current)
265 {
266 _M_frames.emplace_back(_S_fopcode_restore_rep_count,
267 __i, __rep_count.first);
268 _M_frames.back()._M_count = __rep_count.second;
269 __rep_count.first = _M_current;
270 __rep_count.second = 1;
271 _M_frames.emplace_back(_S_fopcode_next, __state._M_alt);
272 }
273 else
274 {
275 if (__rep_count.second < 2)
276 {
277 __rep_count.second++;
278 _M_frames.emplace_back(_S_fopcode_decrement_rep_count, __i);
279 _M_frames.emplace_back(_S_fopcode_next, __state._M_alt);
280 }
281 }
282 }
283
284 // _M_alt branch is "match once more", while _M_next is "get me out
285 // of this quantifier". Executing _M_next first or _M_alt first don't
286 // mean the same thing, and we need to choose the correct order under
287 // given greedy mode.
288 template<typename _BiIter, typename _Alloc, typename _TraitsT,
289 bool __dfs_mode>
291 _M_handle_repeat(_Match_mode __match_mode, _StateIdT __i)
292 {
293 const auto& __state = _M_nfa[__i];
294 // Greedy.
295 if (!__state._M_neg)
296 {
297 if constexpr (__dfs_mode)
298 // If it's DFS executor and already accepted, we're done.
299 _M_frames.emplace_back(_S_fopcode_fallback_next, __state._M_next,
300 _M_current);
301 else
302 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
303 _M_frames.emplace_back(_S_fopcode_rep_once_more, __i);
304 }
305 else // Non-greedy mode
306 {
307 if constexpr (__dfs_mode)
308 {
309 // vice-versa.
310 _M_frames.emplace_back(_S_fopcode_fallback_rep_once_more, __i,
311 _M_current);
312 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
313 }
314 else
315 {
316 // DON'T attempt anything, because there's already another
317 // state with higher priority accepted. This state cannot
318 // be better by attempting its next node.
319 if (!_M_has_sol)
320 {
321 // DON'T attempt anything if it's already accepted. An
322 // accepted state *must* be better than a solution that
323 // matches a non-greedy quantifier one more time.
324 _M_frames.emplace_back(_S_fopcode_fallback_rep_once_more, __i);
325 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
326 }
327 }
328 }
329 }
330
331 template<typename _BiIter, typename _Alloc, typename _TraitsT,
332 bool __dfs_mode>
334 _M_handle_subexpr_begin(_Match_mode __match_mode, _StateIdT __i)
335 {
336 const auto& __state = _M_nfa[__i];
337 auto& __res = _M_cur_results[__state._M_subexpr];
338 _M_frames.emplace_back(_S_fopcode_restore_cur_results,
339 static_cast<_StateIdT>(__state._M_subexpr),
340 __res.first);
341 __res.first = _M_current;
342 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
343 }
344
345 template<typename _BiIter, typename _Alloc, typename _TraitsT,
346 bool __dfs_mode>
348 _M_handle_subexpr_end(_Match_mode __match_mode, _StateIdT __i)
349 {
350 const auto& __state = _M_nfa[__i];
351 auto& __res = _M_cur_results[__state._M_subexpr];
352 _M_frames.emplace_back(_S_fopcode_restore_cur_results,
353 static_cast<_StateIdT>(__state._M_subexpr),
354 __res.second);
355 _M_frames.back()._M_subexpr_end = true;
356 _M_frames.back()._M_matched = __res.matched;
357 __res.second = _M_current;
358 __res.matched = true;
359 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
360 }
361
362 template<typename _BiIter, typename _Alloc, typename _TraitsT,
363 bool __dfs_mode>
365 _M_handle_line_begin_assertion(_Match_mode __match_mode, _StateIdT __i)
366 {
367 const auto& __state = _M_nfa[__i];
368 if (_M_at_begin())
369 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
370 }
371
372 template<typename _BiIter, typename _Alloc, typename _TraitsT,
373 bool __dfs_mode>
375 _M_handle_line_end_assertion(_Match_mode __match_mode, _StateIdT __i)
376 {
377 const auto& __state = _M_nfa[__i];
378 if (_M_at_end())
379 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
380 }
381
382 template<typename _BiIter, typename _Alloc, typename _TraitsT,
383 bool __dfs_mode>
385 _M_handle_word_boundary(_Match_mode __match_mode, _StateIdT __i)
386 {
387 const auto& __state = _M_nfa[__i];
388 if (_M_word_boundary() == !__state._M_neg)
389 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
390 }
391
392 // Here __state._M_alt offers a single start node for a sub-NFA.
393 // We recursively invoke our algorithm to match the sub-NFA.
394 template<typename _BiIter, typename _Alloc, typename _TraitsT,
395 bool __dfs_mode>
397 _M_handle_subexpr_lookahead(_Match_mode __match_mode, _StateIdT __i)
398 {
399 const auto& __state = _M_nfa[__i];
400 if (_M_lookahead(__state._M_alt) == !__state._M_neg)
401 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
402 }
403
404 template<typename _BiIter, typename _Alloc, typename _TraitsT,
405 bool __dfs_mode>
407 _M_handle_match(_Match_mode __match_mode, _StateIdT __i)
408 {
409 const auto& __state = _M_nfa[__i];
410 if (_M_current == _M_end)
411 return;
412 if constexpr (__dfs_mode)
413 {
414 if (__state._M_matches(*_M_current))
415 {
416 ++_M_current;
417 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
418 }
419 }
420 else
421 if (__state._M_matches(*_M_current))
422 _M_states._M_queue(__state._M_next, _M_cur_results);
423 }
424
425 template<typename _BiIter, typename _TraitsT>
426 struct _Backref_matcher
427 {
428 _Backref_matcher(bool /* __icase */, const _TraitsT& __traits)
429 : _M_traits(__traits) { }
430
431 bool
432 _M_apply(_BiIter __expected_begin,
433 _BiIter __expected_end, _BiIter __actual_begin,
434 _BiIter __actual_end)
435 {
436 return _M_traits.transform(__expected_begin, __expected_end)
437 == _M_traits.transform(__actual_begin, __actual_end);
438 }
439
440 const _TraitsT& _M_traits;
441 };
442
443 template<typename _BiIter, typename _CharT>
444 struct _Backref_matcher<_BiIter, std::regex_traits<_CharT>>
445 {
446 using _TraitsT = std::regex_traits<_CharT>;
447 _Backref_matcher(bool __icase, const _TraitsT& __traits)
448 : _M_icase(__icase), _M_traits(__traits) { }
449
450 bool
451 _M_apply(_BiIter __expected_begin,
452 _BiIter __expected_end, _BiIter __actual_begin,
453 _BiIter __actual_end)
454 {
455 if (!_M_icase)
456 return _GLIBCXX_STD_A::__equal4(__expected_begin, __expected_end,
457 __actual_begin, __actual_end);
458 typedef std::ctype<_CharT> __ctype_type;
459 const auto& __fctyp = use_facet<__ctype_type>(_M_traits.getloc());
460 return _GLIBCXX_STD_A::__equal4(__expected_begin, __expected_end,
461 __actual_begin, __actual_end,
462 [this, &__fctyp](_CharT __lhs, _CharT __rhs)
463 {
464 return __fctyp.tolower(__lhs)
465 == __fctyp.tolower(__rhs);
466 });
467 }
468
469 bool _M_icase;
470 const _TraitsT& _M_traits;
471 };
472
473 // First fetch the matched result from _M_cur_results as __submatch;
474 // then compare it with
475 // (_M_current, _M_current + (__submatch.second - __submatch.first)).
476 // If matched, keep going; else just return and try another state.
477 template<typename _BiIter, typename _Alloc, typename _TraitsT,
478 bool __dfs_mode>
480 _M_handle_backref(_Match_mode __match_mode, _StateIdT __i)
481 {
482 static_assert(__dfs_mode, "this should never be instantiated");
483
484 const auto& __state = _M_nfa[__i];
485 auto& __submatch = _M_cur_results[__state._M_backref_index];
486 if (!__submatch.matched)
487 return;
488 auto __last = _M_current;
489 for (auto __tmp = __submatch.first;
490 __last != _M_end && __tmp != __submatch.second;
491 ++__tmp)
492 ++__last;
493 if (_Backref_matcher<_BiIter, _TraitsT>(
494 _M_re.flags() & regex_constants::icase,
495 _M_re._M_automaton->_M_traits)._M_apply(
496 __submatch.first, __submatch.second, _M_current, __last))
497 {
498 _M_current = __last;
499 _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
500 }
501 }
502
503 template<typename _BiIter, typename _Alloc, typename _TraitsT,
504 bool __dfs_mode>
506 _M_handle_accept(_Match_mode __match_mode, _StateIdT)
507 {
508 if constexpr (__dfs_mode)
509 {
510 __glibcxx_assert(!_M_has_sol);
511 if (__match_mode == _Match_mode::_Exact)
512 _M_has_sol = _M_current == _M_end;
513 else
514 _M_has_sol = true;
515 if (_M_current == _M_begin
516 && (_M_flags & regex_constants::match_not_null))
517 _M_has_sol = false;
518 if (_M_has_sol)
519 {
520 if (_M_nfa._M_flags & regex_constants::ECMAScript)
521 _M_results = _M_cur_results;
522 else // POSIX
523 {
524 __glibcxx_assert(_M_states._M_get_sol_pos());
525 // Here's POSIX's logic: match the longest one. However
526 // we never know which one (lhs or rhs of "|") is longer
527 // unless we try both of them and compare the results.
528 // The member variable _M_sol_pos records the end
529 // position of the last successful match. It's better
530 // to be larger, because POSIX regex is always greedy.
531 // TODO: This could be slow.
532 if (*_M_states._M_get_sol_pos() == _BiIter()
533 || std::distance(_M_begin,
534 *_M_states._M_get_sol_pos())
535 < std::distance(_M_begin, _M_current))
536 {
537 *_M_states._M_get_sol_pos() = _M_current;
538 _M_results = _M_cur_results;
539 }
540 }
541 }
542 }
543 else
544 {
545 if (_M_current == _M_begin
546 && (_M_flags & regex_constants::match_not_null))
547 return;
548 if (__match_mode == _Match_mode::_Prefix || _M_current == _M_end)
549 if (!_M_has_sol)
550 {
551 _M_has_sol = true;
552 _M_results = _M_cur_results;
553 }
554 }
555 }
556
557 template<typename _BiIter, typename _Alloc, typename _TraitsT,
558 bool __dfs_mode>
560 _M_handle_alternative(_Match_mode __match_mode, _StateIdT __i)
561 {
562 const auto& __state = _M_nfa[__i];
563 if (_M_nfa._M_flags & regex_constants::ECMAScript)
564 {
565 // TODO: Fix BFS support. It is wrong.
566 // Pick lhs if it matches. Only try rhs if it doesn't.
567 _M_frames.emplace_back(_S_fopcode_fallback_next, __state._M_next,
568 _M_current);
569 _M_frames.emplace_back(_S_fopcode_next, __state._M_alt);
570 }
571 else
572 {
573 // Try both and compare the result.
574 // See "case _S_opcode_accept:" handling above.
575 _M_frames.emplace_back(_S_fopcode_posix_alternative, __state._M_next,
576 _M_current);
577 _M_frames.emplace_back(_S_fopcode_next, __state._M_alt);
578 }
579 }
580
581 template<typename _BiIter, typename _Alloc, typename _TraitsT,
582 bool __dfs_mode>
583#ifdef __OPTIMIZE__
584 [[__gnu__::__always_inline__]]
585#endif
587 _M_node(_Match_mode __match_mode, _StateIdT __i)
588 {
589 if (_M_states._M_visited(__i))
590 return;
591
592 switch (_M_nfa[__i]._M_opcode())
593 {
594 case _S_opcode_repeat:
595 _M_handle_repeat(__match_mode, __i); break;
596 case _S_opcode_subexpr_begin:
597 _M_handle_subexpr_begin(__match_mode, __i); break;
598 case _S_opcode_subexpr_end:
599 _M_handle_subexpr_end(__match_mode, __i); break;
600 case _S_opcode_line_begin_assertion:
601 _M_handle_line_begin_assertion(__match_mode, __i); break;
602 case _S_opcode_line_end_assertion:
603 _M_handle_line_end_assertion(__match_mode, __i); break;
604 case _S_opcode_word_boundary:
605 _M_handle_word_boundary(__match_mode, __i); break;
606 case _S_opcode_subexpr_lookahead:
607 _M_handle_subexpr_lookahead(__match_mode, __i); break;
608 case _S_opcode_match:
609 _M_handle_match(__match_mode, __i); break;
610 case _S_opcode_backref:
611 if constexpr (__dfs_mode)
612 _M_handle_backref(__match_mode, __i);
613 else
614 __builtin_unreachable();
615 break;
616 case _S_opcode_accept:
617 _M_handle_accept(__match_mode, __i); break;
618 case _S_opcode_alternative:
619 _M_handle_alternative(__match_mode, __i); break;
620 default:
621 __glibcxx_assert(false);
622 }
623 }
624
625 template<typename _BiIter, typename _Alloc, typename _TraitsT,
626 bool __dfs_mode>
628 _M_dfs(_Match_mode __match_mode, _StateIdT __start)
629 {
630 _M_frames.emplace_back(_S_fopcode_next, __start);
631
632 while (!_M_frames.empty())
633 {
634 _ExecutorFrame<_BiIter> __frame = std::move(_M_frames.back());
635 _M_frames.pop_back();
636
637 switch (__frame._M_op)
638 {
639 case _S_fopcode_fallback_next:
640 if (_M_has_sol)
641 break;
642 if constexpr (__dfs_mode)
643 _M_current = __frame._M_pos;
644 [[__fallthrough__]];
645 case _S_fopcode_next:
646 _M_node(__match_mode, __frame._M_state_id);
647 break;
648
649 case _S_fopcode_fallback_rep_once_more:
650 if (_M_has_sol)
651 break;
652 if constexpr (__dfs_mode)
653 _M_current = __frame._M_pos;
654 [[__fallthrough__]];
655 case _S_fopcode_rep_once_more:
656 _M_rep_once_more(__match_mode, __frame._M_state_id);
657 break;
658
659 case _S_fopcode_posix_alternative:
660 _M_frames.emplace_back(_S_fopcode_merge_sol, 0, _M_has_sol);
661 _M_frames.emplace_back(_S_fopcode_next, __frame._M_state_id);
662 if constexpr (__dfs_mode)
663 _M_current = __frame._M_pos;
664 _M_has_sol = false;
665 break;
666
667 case _S_fopcode_merge_sol:
668 _M_has_sol |= __frame._M_val;
669 break;
670
671 case _S_fopcode_restore_cur_results:
672 if (!__frame._M_subexpr_end)
673 _M_cur_results[__frame._M_state_id].first = __frame._M_pos;
674 else
675 {
676 _M_cur_results[__frame._M_state_id].second = __frame._M_pos;
677 _M_cur_results[__frame._M_state_id].matched = __frame._M_matched;
678 }
679 break;
680
681 case _S_fopcode_restore_rep_count:
682 _M_rep_count[__frame._M_state_id].first = __frame._M_pos;
683 _M_rep_count[__frame._M_state_id].second = __frame._M_count;
684 break;
685
686 case _S_fopcode_decrement_rep_count:
687 _M_rep_count[__frame._M_state_id].second--;
688 break;
689 }
690 }
691 }
692
693 // Return whether now is at some word boundary.
694 template<typename _BiIter, typename _Alloc, typename _TraitsT,
695 bool __dfs_mode>
697 _M_word_boundary() const
698 {
699 if (_M_current == _M_begin && (_M_flags & regex_constants::match_not_bow))
700 return false;
701 if (_M_current == _M_end && (_M_flags & regex_constants::match_not_eow))
702 return false;
703
704 bool __left_is_word = false;
705 if (_M_current != _M_begin
706 || (_M_flags & regex_constants::match_prev_avail))
707 {
708 auto __prev = _M_current;
709 if (_M_is_word(*std::prev(__prev)))
710 __left_is_word = true;
711 }
712 bool __right_is_word =
713 _M_current != _M_end && _M_is_word(*_M_current);
714
715 return __left_is_word != __right_is_word;
716 }
717_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
718} // namespace __detail
719#pragma GCC diagnostic pop
720
721_GLIBCXX_END_NAMESPACE_VERSION
722} // namespace
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
const _Facet & use_facet(const locale &__loc)
Return a facet.
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Implementation details not part of the namespace std interface.
constexpr match_flag_type match_not_bow
constexpr syntax_option_type ECMAScript
constexpr match_flag_type match_continuous
constexpr syntax_option_type icase
constexpr match_flag_type match_prev_avail
constexpr match_flag_type match_not_eow
constexpr match_flag_type match_not_null
Takes a regex and an input string and does the matching.