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

std::regex compatibility, part 2/3: sub_match, match_results, the backend runner and the regex_search / regex_match / regex_replace free functions. More...

#include "regex_core.hpp"
#include <algorithm>
#include <iterator>
#include <ostream>
Include dependency graph for regex_match.hpp:

Classes

class  real::compat::sub_match< BidirIt >
 A matched sub-expression: a [first, second) range into the searched sequence. Any bidirectional iterator, as std::sub_match; only view needs contiguous storage. More...
 
class  real::compat::match_results< BidirIt, Alloc >
 The result of a match: group sub-matches plus the prefix and suffix. More...
 
class  real::compat::detail::offset_cursor< BidirIt >
 Maps offsets into a non-contiguous range's copy back to the caller's iterators by moving one iterator from the last offset mapped; std::next(first, offset) per mark would rewalk a std::list. More...
 
struct  real::compat::detail::call_shape
 What a regex_search or regex_match call asks of REAL, its match flags included. More...
 
class  real::compat::detail::offset_match< RealMatch >
 A REAL match found on a suffix of the subject, seen with the subject's offsets: what the format expander and the match-results fill read (size, start, end). More...
 

Namespaces

namespace  real
 REAL's public API: real::regex, real::static_regex, real::flags and the match/iterator types built on them.
 
namespace  real::compat
 Drop-in replacements for <regex>, backed by REAL's linear-time engine where it can serve the pattern and by std::regex otherwise, never by a silent divergence.
 
namespace  real::compat::detail
 Backend routing and format expansion for the compat layer. Not a stable API.
 

Typedefs

using real::compat::ssub_match = sub_match< std::string::const_iterator >
 Sub-match over a std::string.
 
using real::compat::csub_match = sub_match< const char * >
 Sub-match over a C string.
 
using real::compat::wssub_match = sub_match< std::wstring::const_iterator >
 Sub-match over a std::wstring.
 
using real::compat::wcsub_match = sub_match< const wchar_t * >
 Sub-match over a wide C string.
 
using real::compat::smatch = match_results< std::string::const_iterator >
 Match over a std::string.
 
using real::compat::cmatch = match_results< const char * >
 Match over a C string.
 
using real::compat::wsmatch = match_results< std::wstring::const_iterator >
 Match over a std::wstring (always std).
 
using real::compat::wcmatch = match_results< const wchar_t * >
 Match over a wide C string (always std).
 

Functions

template<typename BidirIt >
bool real::compat::operator== (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::string_type &rhs)
 Equality against an owned string (the common std::sub_match comparison).
 
template<typename BidirIt >
bool real::compat::operator== (const typename sub_match< BidirIt >::string_type &lhs, const sub_match< BidirIt > &rhs)
 Equality with the string on the left, for std::sub_match parity.
 
template<typename BidirIt >
bool real::compat::operator== (const sub_match< BidirIt > &lhs, const sub_match< BidirIt > &rhs)
 Equality between two sub-matches, by matched text.
 
template<typename BidirIt >
auto real::compat::operator<=> (const sub_match< BidirIt > &lhs, const sub_match< BidirIt > &rhs)
 Ordering between two sub-matches, by matched text (std::sub_match parity).
 
template<typename BidirIt >
auto real::compat::operator<=> (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::string_type &rhs)
 Ordering against an owned string; the reversed and the <, > forms follow from it.
 
template<typename BidirIt >
bool real::compat::operator== (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::value_type *rhs)
 Equality against a C string.
 
template<typename BidirIt >
auto real::compat::operator<=> (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::value_type *rhs)
 Ordering against a C string.
 
template<typename BidirIt >
bool real::compat::operator== (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::value_type &rhs)
 Equality against one character: the sub-match holds exactly it.
 
template<typename BidirIt >
auto real::compat::operator<=> (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::value_type &rhs)
 Ordering against one character, as against the string holding only it.
 
template<typename CharT , typename Traits , typename BidirIt >
std::basic_ostream< CharT, Traits > & real::compat::operator<< (std::basic_ostream< CharT, Traits > &os, const sub_match< BidirIt > &m)
 Streams m.str(), empty when the group did not participate (std::sub_match parity).
 
template<typename BidirIt , typename Alloc >
bool real::compat::operator== (const match_results< BidirIt, Alloc > &lhs, const match_results< BidirIt, Alloc > &rhs)
 Equality of two results (std::match_results parity): both not ready, or both ready and both empty, or both holding the same text in the prefix, every group and the suffix.
 
template<typename BidirIt , typename Alloc >
void real::compat::swap (match_results< BidirIt, Alloc > &lhs, match_results< BidirIt, Alloc > &rhs) noexcept
 Exchanges two results (std::swap parity).
 
template<typename CharT , typename Traits >
auto real::compat::detail::find_real (const basic_regex< CharT, Traits > &re, std::string_view view, call_shape shape)
 The REAL call for shape over view, whose first shape.lead characters are context only: ^, \b and a lookbehind see them, and a non-multiline ^ does not hold after them ([re.matchflag]).
 
template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::detail::run_copied (BidirIt first, BidirIt last, match_results< BidirIt > &m, const basic_regex< CharT, Traits > &re, call_shape shape)
 run_impl over a non-contiguous range on REAL: the range is copied once, searched, and every offset of the result mapped back to the caller's iterators in one forward walk.
 
bool real::compat::detail::real_honors (regex_constants::match_flag_type mf) noexcept
 Whether an iteration may stay on real under mf: only match_default and match_any (met by the leftmost match) qualify; a constraining bit routes it to std rather than be ignored. A single search or match honors more (call_stays_real).
 
bool real::compat::detail::call_stays_real (regex_constants::match_flag_type mf, bool anchored, bool longest, bool not_null_ok) noexcept
 Whether one regex_search or regex_match call can honor mf on real.
 
template<typename CharT , typename Traits >
bool real::compat::detail::not_null_stays_real (const basic_regex< CharT, Traits > &re) noexcept
 Whether REAL honors match_not_null for re: always when the pattern cannot match empty (the flag then changes nothing); otherwise when its search is leftmost-first and its traversal REAL's (a nullable capturing group under a quantifier takes another last iteration than std's).
 
call_shape real::compat::detail::shape_of (regex_constants::match_flag_type mf, bool anchored, bool nullable) noexcept
 The REAL call a regex_search or regex_match with mf makes; see call_stays_real.
 
template<typename CharT , typename Traits >
const real::regex * real::compat::detail::real_engine_for (const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type mf, bool anchored)
 The REAL engine a regex_search or regex_match with mf runs on, or null for std.
 
bool real::compat::detail::replace_stays_real (regex_constants::match_flag_type f) noexcept
 Whether regex_replace may run on real under f: the real expanders honor format_first_only, format_no_copy, format_sed and match_any; the traversal would ignore a constraining match flag, so any routes the whole substitution to std.
 
std::regex_constants::match_flag_type real::compat::detail::to_std_match (regex_constants::match_flag_type f) noexcept
 Maps every compat match and format flag to std::regex_constants; a bit missing here would be silently dropped on the std path.
 
template<bool Capture, typename BidirIt , typename CharT , typename Traits >
bool real::compat::detail::run_impl (BidirIt first, BidirIt last, std::type_identity_t< match_results< BidirIt > > *m, const basic_regex< CharT, Traits > &re, bool anchored, regex_constants::match_flag_type mf)
 Runs the backend over [first, last), filling m under Capture; a flag REAL cannot honor routes to std.
 
template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_search (BidirIt first, BidirIt last, match_results< BidirIt > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search of [first, last), as std::regex_search; the overloads taking no match_results skip capture filling.
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const std::basic_string< CharT > &s, match_results< typename std::basic_string< CharT >::const_iterator > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search over a std::basic_string, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const CharT *s, match_results< const CharT * > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search over a C string, as the primary overload.
 
template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_search (BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search over [first, last), without capturing, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search over a std::basic_string, without capturing, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const CharT *s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search over a C string, without capturing, as the primary overload.
 
template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_match (BidirIt first, BidirIt last, match_results< BidirIt > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Match of the entire [first, last), as std::regex_match; the overloads taking no match_results skip capture filling.
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const std::basic_string< CharT > &s, match_results< typename std::basic_string< CharT >::const_iterator > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Whole-sequence match over a std::basic_string, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const CharT *s, match_results< const CharT * > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Whole-sequence match over a C string, as the primary overload.
 
template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_match (BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Whole-sequence match over [first, last), without capturing, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Whole-sequence match over a std::basic_string, without capturing, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const CharT *s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Whole-sequence match over a C string, without capturing, as the primary overload.
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &)=delete
 
template<typename CharT , typename Traits >
bool real::compat::regex_search (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &, regex_constants::match_flag_type)=delete
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &)=delete
 
template<typename CharT , typename Traits >
bool real::compat::regex_match (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &, regex_constants::match_flag_type)=delete
 
template<typename RealMatch >
void real::compat::detail::append_replacement (std::string &out, const RealMatch &m, std::string_view fmt, std::string_view text, std::size_t prefix_start, bool sed)
 Appends one match's expanded replacement (expand_replacement), the prefix running from prefix_start as in std::regex_replace. A $0 never reaches here (format_forces_std routes it to std).
 
template<typename RealMatch >
void real::compat::detail::append_replacement (std::string &out, const RealMatch &match, std::string_view fmt, std::string_view text, std::size_t &last_end, bool no_copy, bool sed)
 Appends one match's replacement: the text since the previous match (unless format_no_copy), then the expanded format.
 
std::optional< real::regex::result_type > real::compat::detail::nonempty_at_without_context (const real::regex &engine, std::string_view text, std::size_t at)
 The retry [re.regiter.incr] makes after the iteration's first match came out empty at at: a non-empty match starting there, searched without match_prev_avail, so \b, ^ and a lookbehind read at as the start. Later empty matches need no retry: real's own advance is the standard's.
 
template<typename CharT , typename Traits >
std::basic_string< CharT > real::compat::regex_replace (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, const std::basic_string< CharT > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 Replaces matches of re in s with the formatted fmt; the other overloads forward here.
 
template<typename CharT , typename Traits >
std::basic_string< CharT > real::compat::regex_replace (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, const CharT *fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 regex_replace overload for a C-string format.
 
template<typename OutputIt , typename BidirIt , typename CharT , typename Traits >
OutputIt real::compat::regex_replace (OutputIt out, BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, const std::basic_string< CharT > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 regex_replace writing to an output iterator (std parity).
 
template<typename OutputIt , typename BidirIt , typename CharT , typename Traits >
OutputIt real::compat::regex_replace (OutputIt out, BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, const CharT *fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 regex_replace to an output iterator with a C-string format, so a string literal binds (std parity).
 

Detailed Description

std::regex compatibility, part 2/3: sub_match, match_results, the backend runner and the regex_search / regex_match / regex_replace free functions.