REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::compat::basic_regex< CharT, Traits > Class Template Reference

A std::basic_regex-compatible pattern, backed by real where proven, else std. More...

#include <regex_core.hpp>

Public Types

using value_type = CharT
 Character type.
 
using flag_type = regex_constants::syntax_option_type
 Option type.
 
using string_type = std::basic_string< CharT >
 Pattern string type.
 

Public Member Functions

 basic_regex ()=default
 
 basic_regex (const CharT *pattern, flag_type f=regex_constants::ECMAScript, policy pol=policy::strict)
 
 basic_regex (const string_type &pattern, flag_type f=regex_constants::ECMAScript, policy pol=policy::strict)
 
 basic_regex (const CharT *pattern, std::size_t len, flag_type f=regex_constants::ECMAScript, policy pol=policy::strict)
 
template<typename It >
 basic_regex (It begin, It end, flag_type f=regex_constants::ECMAScript, policy pol=policy::strict)
 
std::size_t mark_count () const noexcept
 Number of marked sub-expressions (excluding group 0), as std::basic_regex.
 
flag_type flags () const noexcept
 The flags this regex was built with.
 
void swap (basic_regex &other) noexcept
 
bool uses_real () const noexcept
 True if this regex is backed by the real engine (vs the std fallback).
 
bool uses_fallback () const noexcept
 True if this regex fell back to std::regex (a policy::fallback regex on an ineligible pattern) — so this pattern is not linear-time / ReDoS-safe. Always false under strict.
 
compat::policy policy () const noexcept
 The drop-in policy this regex was constructed with.
 
const std::variant< std::basic_regex< CharT, Traits >, real::regex > & engine () const noexcept
 Access the active backend (engine-facing; used by the free functions).
 
bool nullable () const noexcept
 Whether the pattern can match the empty string (real's empty_match_possible hint).
 
bool posix_longest () const noexcept
 Whether this is a POSIX-ERE pattern routed to REAL: search/match must use leftmost-**longest** bounds (the POSIX semantics), not the default leftmost-first. Set only for a translated extended.
 
bool uses_real_traversal () const noexcept
 Whether replace/iterate run on the real traversal (real-backed AND non-nullable). A nullable pattern delegates replace/iterate to std (the empty-match traversal differs; and iterating a nullable pattern whose per-position match cost is O(n) is O(n²) on any linear engine, so routing it buys correctness but not a linear guarantee — see the nullable note in COMPATIBILITY.md).
 
const std::basic_regex< CharT, Traits > & std_engine () const
 The std::regex for the std / lazy-std path (built once on demand for a real-backed pattern reached via a constraining flag / nullable replace-iterate / $0/sed replace).
 

Private Member Functions

void assign (std::basic_string_view< CharT > pattern, flag_type f)
 
void reject_or_fallback (std::string_view sv, flag_type f, const std::string &reason)
 The policy branch for a pattern the linear engine cannot represent: strict throws regex_error with error_complexity and a REAL-identifiable message; fallback delegates it to std::regex.
 
void emplace_std (std::string_view sv, flag_type f)
 

Private Attributes

std::variant< std::basic_regex< CharT, Traits >, real::regexengine_
 
string_type pattern_
 Original pattern (for the lazy std build).
 
flag_type flags_ {regex_constants::ECMAScript}
 
std::size_t mark_count_ {}
 
bool nullable_ {}
 empty_match_possible (real-backed).
 
bool posix_longest_ {}
 POSIX ERE on REAL: search uses leftmost-longest bounds.
 
std::optional< std::basic_regex< CharT, Traits > > lazy_std_
 Lazy std for nullable replace/iterate.
 
compat::policy policy_ {policy::strict}
 strict rejects ineligible, fallback delegates to std.
 

Detailed Description

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
class real::compat::basic_regex< CharT, Traits >

A std::basic_regex-compatible pattern, backed by real where proven, else std.

Template Parameters
CharTCharacter type (char; other types route straight to std).
TraitsRegex traits (std parity).

Definition at line 579 of file regex_core.hpp.

Member Typedef Documentation

◆ flag_type

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
using real::compat::basic_regex< CharT, Traits >::flag_type = regex_constants::syntax_option_type

Option type.

Definition at line 584 of file regex_core.hpp.

◆ string_type

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
using real::compat::basic_regex< CharT, Traits >::string_type = std::basic_string<CharT>

Pattern string type.

Definition at line 585 of file regex_core.hpp.

◆ value_type

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
using real::compat::basic_regex< CharT, Traits >::value_type = CharT

Character type.

Definition at line 583 of file regex_core.hpp.

Constructor & Destructor Documentation

◆ basic_regex() [1/5]

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
real::compat::basic_regex< CharT, Traits >::basic_regex ( )
default

◆ basic_regex() [2/5]

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
real::compat::basic_regex< CharT, Traits >::basic_regex ( const CharT *  pattern,
flag_type  f = regex_constants::ECMAScript,
policy  pol = policy::strict 
)
inlineexplicit

Definition at line 589 of file regex_core.hpp.

◆ basic_regex() [3/5]

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
real::compat::basic_regex< CharT, Traits >::basic_regex ( const string_type pattern,
flag_type  f = regex_constants::ECMAScript,
policy  pol = policy::strict 
)
inlineexplicit

Definition at line 597 of file regex_core.hpp.

◆ basic_regex() [4/5]

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
real::compat::basic_regex< CharT, Traits >::basic_regex ( const CharT *  pattern,
std::size_t  len,
flag_type  f = regex_constants::ECMAScript,
policy  pol = policy::strict 
)
inline

Definition at line 605 of file regex_core.hpp.

◆ basic_regex() [5/5]

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
template<typename It >
real::compat::basic_regex< CharT, Traits >::basic_regex ( It  begin,
It  end,
flag_type  f = regex_constants::ECMAScript,
policy  pol = policy::strict 
)
inline

Definition at line 615 of file regex_core.hpp.

Member Function Documentation

◆ assign()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
void real::compat::basic_regex< CharT, Traits >::assign ( std::basic_string_view< CharT >  pattern,
flag_type  f 
)
inlineprivate

Definition at line 743 of file regex_core.hpp.

◆ emplace_std()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
void real::compat::basic_regex< CharT, Traits >::emplace_std ( std::string_view  sv,
flag_type  f 
)
inlineprivate

Definition at line 839 of file regex_core.hpp.

◆ engine()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
const std::variant< std::basic_regex< CharT, Traits >, real::regex > & real::compat::basic_regex< CharT, Traits >::engine ( ) const
inlinenoexcept

Access the active backend (engine-facing; used by the free functions).

Definition at line 669 of file regex_core.hpp.

◆ flags()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
flag_type real::compat::basic_regex< CharT, Traits >::flags ( ) const
inlinenoexcept

The flags this regex was built with.

Definition at line 632 of file regex_core.hpp.

◆ mark_count()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
std::size_t real::compat::basic_regex< CharT, Traits >::mark_count ( ) const
inlinenoexcept

Number of marked sub-expressions (excluding group 0), as std::basic_regex.

Definition at line 626 of file regex_core.hpp.

◆ nullable()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::nullable ( ) const
inlinenoexcept

Whether the pattern can match the empty string (real's empty_match_possible hint).

Empty-match traversal (replace / iterate) follows Python's advance rules in real, which differ from ECMAScript. So a nullable real-backed pattern routes those operations to a lazily built std::regex (std_engine) — per operation, not at construction, so search/match keep real's linear-time guarantee even on nullable-ReDoS patterns like (a*)*.

Definition at line 680 of file regex_core.hpp.

◆ policy()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
compat::policy real::compat::basic_regex< CharT, Traits >::policy ( ) const
inlinenoexcept

The drop-in policy this regex was constructed with.

Definition at line 663 of file regex_core.hpp.

◆ posix_longest()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::posix_longest ( ) const
inlinenoexcept

Whether this is a POSIX-ERE pattern routed to REAL: search/match must use leftmost-**longest** bounds (the POSIX semantics), not the default leftmost-first. Set only for a translated extended.

Definition at line 687 of file regex_core.hpp.

◆ reject_or_fallback()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
void real::compat::basic_regex< CharT, Traits >::reject_or_fallback ( std::string_view  sv,
flag_type  f,
const std::string &  reason 
)
inlineprivate

The policy branch for a pattern the linear engine cannot represent: strict throws regex_error with error_complexity and a REAL-identifiable message; fallback delegates it to std::regex.

Definition at line 814 of file regex_core.hpp.

◆ std_engine()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
const std::basic_regex< CharT, Traits > & real::compat::basic_regex< CharT, Traits >::std_engine ( ) const
inline

The std::regex for the std / lazy-std path (built once on demand for a real-backed pattern reached via a constraining flag / nullable replace-iterate / $0/sed replace).

Thread-safe: std::regex guarantees concurrent const operations on one object are safe, but this builds lazy_std_ (a mutable member) on demand. A function-local static build mutex serialises the build (and the read is taken under the same lock), so the guarantee holds for nullable AND non-nullable real-backed patterns. std::once_flag would be lighter but is non-copyable, and basic_regex must stay copyable (std::regex is); a static mutex keeps the value semantics defaulted. The build is per operation, cold relative to matching.

Definition at line 710 of file regex_core.hpp.

◆ swap()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
void real::compat::basic_regex< CharT, Traits >::swap ( basic_regex< CharT, Traits > &  other)
inlinenoexcept

Definition at line 637 of file regex_core.hpp.

◆ uses_fallback()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::uses_fallback ( ) const
inlinenoexcept

True if this regex fell back to std::regex (a policy::fallback regex on an ineligible pattern) — so this pattern is not linear-time / ReDoS-safe. Always false under strict.

Definition at line 657 of file regex_core.hpp.

◆ uses_real()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::uses_real ( ) const
inlinenoexcept

True if this regex is backed by the real engine (vs the std fallback).

Definition at line 650 of file regex_core.hpp.

◆ uses_real_traversal()

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::uses_real_traversal ( ) const
inlinenoexcept

Whether replace/iterate run on the real traversal (real-backed AND non-nullable). A nullable pattern delegates replace/iterate to std (the empty-match traversal differs; and iterating a nullable pattern whose per-position match cost is O(n) is O(n²) on any linear engine, so routing it buys correctness but not a linear guarantee — see the nullable note in COMPATIBILITY.md).

Definition at line 696 of file regex_core.hpp.

Member Data Documentation

◆ engine_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
std::variant<std::basic_regex<CharT, Traits>, real::regex> real::compat::basic_regex< CharT, Traits >::engine_
private

Definition at line 734 of file regex_core.hpp.

◆ flags_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
flag_type real::compat::basic_regex< CharT, Traits >::flags_ {regex_constants::ECMAScript}
private

Definition at line 736 of file regex_core.hpp.

◆ lazy_std_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
std::optional<std::basic_regex<CharT, Traits> > real::compat::basic_regex< CharT, Traits >::lazy_std_
mutableprivate

Lazy std for nullable replace/iterate.

Definition at line 740 of file regex_core.hpp.

◆ mark_count_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
std::size_t real::compat::basic_regex< CharT, Traits >::mark_count_ {}
private

Definition at line 737 of file regex_core.hpp.

◆ nullable_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::nullable_ {}
private

empty_match_possible (real-backed).

Definition at line 738 of file regex_core.hpp.

◆ pattern_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
string_type real::compat::basic_regex< CharT, Traits >::pattern_
private

Original pattern (for the lazy std build).

Definition at line 735 of file regex_core.hpp.

◆ policy_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
compat::policy real::compat::basic_regex< CharT, Traits >::policy_ {policy::strict}
private

strict rejects ineligible, fallback delegates to std.

Definition at line 741 of file regex_core.hpp.

◆ posix_longest_

template<typename CharT = char, typename Traits = std::regex_traits<CharT>>
bool real::compat::basic_regex< CharT, Traits >::posix_longest_ {}
private

POSIX ERE on REAL: search uses leftmost-longest bounds.

Definition at line 739 of file regex_core.hpp.


The documentation for this class was generated from the following file: