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