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