REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
regex_core.hpp File Reference

std::regex-compatibility layer, part 1/3: the constants, the error type, the backend-routing screens, and basic_regex. Included via the std/regex.hpp umbrella — do not include the parts directly; #include <real/std/regex.hpp> stays the one public entry point. More...

#include <real/version.hpp>
#include <cstddef>
#include <mutex>
#include <optional>
#include <regex>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
#include <real/real.hpp>
Include dependency graph for regex_core.hpp:

Go to the source code of this file.

Classes

class  real::compat::regex_error
 std::regex_error-compatible exception. More...
 
class  real::compat::basic_regex< CharT, Traits >
 A std::basic_regex-compatible pattern, backed by real where proven, else std. More...
 

Namespaces

namespace  real
 
namespace  real::compat
 
namespace  real::compat::regex_constants
 Compatibility constants mirroring std::regex_constants (own values, mapped internally).
 
namespace  real::compat::detail
 

Typedefs

using real::compat::regex_constants::error_type = std::regex_constants::error_type
 Error categories. Aliased to std's so regex_error::code() is a true drop-in.
 
using real::compat::regex = basic_regex< char >
 The char-path compat regex (real-eligible).
 
using real::compat::wregex = basic_regex< wchar_t >
 The wide compat regex (always the std backend).
 

Enumerations

enum  real::compat::regex_constants::syntax_option_type : unsigned {
  real::compat::regex_constants::ECMAScript = 0 , real::compat::regex_constants::icase = 1U << 0U , real::compat::regex_constants::nosubs = 1U << 1U , real::compat::regex_constants::optimize = 1U << 2U ,
  real::compat::regex_constants::collate = 1U << 3U , real::compat::regex_constants::multiline = 1U << 4U , real::compat::regex_constants::basic = 1U << 5U , real::compat::regex_constants::extended = 1U << 6U ,
  real::compat::regex_constants::awk = 1U << 7U , real::compat::regex_constants::grep = 1U << 8U , real::compat::regex_constants::egrep = 1U << 9U
}
 Grammar / option flags (own bit values; mapped to real::flags or std at construction). More...
 
enum  real::compat::regex_constants::match_flag_type : unsigned {
  real::compat::regex_constants::match_default = 0 , real::compat::regex_constants::match_not_bol = 1U << 0U , real::compat::regex_constants::match_not_eol = 1U << 1U , real::compat::regex_constants::match_not_bow = 1U << 2U ,
  real::compat::regex_constants::match_not_eow = 1U << 3U , real::compat::regex_constants::match_any = 1U << 4U , real::compat::regex_constants::match_not_null = 1U << 5U , real::compat::regex_constants::match_continuous = 1U << 6U ,
  real::compat::regex_constants::match_prev_avail = 1U << 7U , real::compat::regex_constants::format_default = 0 , real::compat::regex_constants::format_sed = 1U << 8U , real::compat::regex_constants::format_no_copy = 1U << 9U ,
  real::compat::regex_constants::format_first_only = 1U << 10U
}
 Match-control flags: the common subset. More...
 
enum class  real::compat::policy : std::uint8_t { real::compat::strict , real::compat::fallback }
 The drop-in policy for a pattern the linear engine cannot represent (backreferences, an unbounded lookaround, a POSIX class, …). strict (the default) rejects it, so every accepted pattern executes each regex_search/regex_match in time linear in the input — the ReDoS-safety guarantee (replace/iterate compose O(n) such operations: quadratic worst-case on any linear engine, never exponential); fallback delegates it to std::regex, which may accept it but forfeits the guarantee for that pattern. More...
 

Functions

constexpr syntax_option_type real::compat::regex_constants::operator| (syntax_option_type a, syntax_option_type b) noexcept
 
constexpr syntax_option_type real::compat::regex_constants::operator& (syntax_option_type a, syntax_option_type b) noexcept
 
constexpr match_flag_type real::compat::regex_constants::operator| (match_flag_type a, match_flag_type b) noexcept
 
constexpr match_flag_type real::compat::regex_constants::operator& (match_flag_type a, match_flag_type b) noexcept
 
constexpr match_flag_type real::compat::regex_constants::operator~ (match_flag_type a) noexcept
 
bool real::compat::detail::grammar_forces_std (regex_constants::syntax_option_type f) noexcept
 Grammars/options that force the std backend (real implements default-traits ECMAScript, reporting every group — so nosubs, which std answers by exposing only group 0, also routes to std to avoid a structural both-accept divergence).
 
bool real::compat::detail::pattern_forces_std (std::string_view p) noexcept
 Pattern text that real accepts but matches differently from libstdc++ — a both-accept silent divergence, so it must route to std up front (real's accept hides it otherwise).
 
bool real::compat::detail::format_forces_std (std::string_view fmt) noexcept
 Replacement format text that must route to std: $0. $0 is platform-variant (libstdc++ = the whole match, strict-ECMAScript/MSVC = a literal), so real cannot pick one without risking a silent divergence — route to std, which is authoritative for its own platform. $$ is skipped (an escaped literal $).
 
std::string real::compat::detail::posix_class_ranges (std::string_view name)
 A POSIX bracket-class name to its ASCII (C-locale) range content, appended inside a [...] during ERE translation. Empty for an unknown name (the caller then falls back to std).
 
bool real::compat::detail::translate_bracket (std::string_view p, std::size_t &i, std::string &out)
 Translates a POSIX bracket expression [...] — identical syntax in BRE and ERE, so shared by both translators. POSIX classes ([[:alpha:]]) become ASCII ranges; other members pass through. i must point at the opening [; on success it advances past the ] and appends the class to out. Returns false (the caller then declines to std) on an unterminated class or an unknown / collating [[:foo:]] / [.x.] / [=x=].
 
bool real::compat::detail::append_awk_escape (std::string_view p, std::size_t &i, std::string &out)
 Appends the REAL translation of an awk C-escape at i (which points at the backslash), advancing i; returns false to decline (→ std). awk's escapes beyond ERE: \b is BACKSPACE (0x08) — not a word boundary, the inverse of the ERE decline — \a=BEL, \n\t\r\f\v the usual controls, \/ and \" literals, and a 1-to-3-digit octal \ddd (both std libraries agree; an overflow > 0377 declines). Emitted as \xHH so REAL matches the exact byte.
 
bool real::compat::detail::has_empty_alternation_branch (std::string_view p)
 Whether p has an empty alternation branch — a | with nothing on one side: (|, |), ||, or a | at the pattern start or end. Two reasons this matters: (a) std::regex rejects these in the POSIX grammars, so translating one would make compat over-accept vs std; (b) REAL's leftmost-first star semantics over an empty-first branch ((|a)*) diverge from re / std on repetition. Conservative — a | merely adjacent to a group boundary or the pattern edge counts, an escaped \| or a | inside a class does not — because a false positive only costs linear coverage (safe) while a false negative is a silent divergence (forbidden).
 
std::optional< std::string > real::compat::detail::translate_ere (std::string_view p, bool awk=false)
 Translates a POSIX extended (ERE) — or, with awk, an awk — pattern to an equivalent REAL pattern, or nullopt when it uses a construct the two grammars read differently (an ECMAScript shorthand \d\w\s — undefined/literal in ERE; an ambiguous {; an unknown/collating [[:…:]]; an empty alternation branch, which std rejects — see has_empty_alternation_branch). awk adds the C-escapes (see append_awk_escape). POSIX classes become ASCII ranges (C locale); the common productions pass through, since REAL reads them like ERE. Validated by a bounds differential.
 
std::optional< std::string > real::compat::detail::translate_bre (std::string_view p)
 Translates a POSIX basic (BRE) pattern to an equivalent REAL pattern, or nullopt. BRE differs from ERE: \( \) group and \{n\} quantify, while bare ( ) { } | + ? are LITERALS (escaped for REAL); * at an expression start and ^/$ off the ends are literals too. Declines (→ std) on a backreference \1-\9 (std's residual value), an ECMAScript-ism, a non-strict \{, an unknown / collating class, or a POSIX-undefined corner (^/$/* at a subexpression boundary).
 
template<typename LineFn >
std::optional< std::string > real::compat::detail::translate_newline_alt (std::string_view p, LineFn translate_line)
 grep / egrep: a newline in the pattern is a top-level alternation of the lines (grep = BRE lines, egrep = ERE lines). Each line is translated by translate_line and the results are joined with | — correct precedence by construction, since | is the lowest, and each line's ^/$ stay branch-relative. A line that declines, or an empty line (a blank branch — a std edge best left to std), declines the whole pattern.
 
std::optional< std::string > real::compat::detail::translate_posix (std::string_view p, regex_constants::syntax_option_type f)
 Dispatches a single POSIX grammar to its translator, or nullopt (→ std). Exactly one grammar bit must be set, and neither collate nor nosubs (which force std). extended → ERE, basic → BRE, awk → ERE + C-escapes, grep → BRE lines joined by |, egrep → ERE lines joined by |.
 
real::flags real::compat::detail::to_real (regex_constants::syntax_option_type f) noexcept
 Maps compat options to real::flags (always with bytes|ecma for std-char alignment).
 
std::regex_constants::syntax_option_type real::compat::detail::to_std (regex_constants::syntax_option_type f) noexcept
 Maps compat options to std::regex syntax flags (the fallback path).
 

Variables

template<typename CharT , typename Traits >
constexpr bool real::compat::detail::real_eligible
 Whether real is even eligible for this basic_regex instantiation. real runs only the char path with default traits; wchar_t/char8_t/… and custom traits are always std. This is a compile-time gate: it must compile real's char-only code (the byte string_view, fill_from_real) out for other CharT, not merely skip it at runtime.
 

Detailed Description

std::regex-compatibility layer, part 1/3: the constants, the error type, the backend-routing screens, and basic_regex. Included via the std/regex.hpp umbrella — do not include the parts directly; #include <real/std/regex.hpp> stays the one public entry point.

Definition in file regex_core.hpp.