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

real::compat::re2 — RE2's reading of the syntax REAL reads as Python's, rewritten into REAL's. More...

#include <real/version.hpp>
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <string>
#include <string_view>
#include <vector>
#include <real/unicode/unicode_fold.hpp>
#include <real/unicode/utf8.hpp>
Include dependency graph for flavor.hpp:

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::re2
 Drop-in replacement for RE2's API surface, on REAL's engine.
 

Typedefs

using real::compat::re2::detail::ascii_set = std::bitset< 0x80 >
 An ASCII set, one bit per byte below 0x80.
 

Functions

bool real::compat::re2::detail::re2_ascii_set (std::string_view name, ascii_set &set)
 The ASCII set a shorthand letter or a POSIX class name stands for, as RE2 defines it.
 
void real::compat::re2::detail::append_code_point (std::string &out, std::uint32_t cp)
 Appends cp as a class member REAL reads in any position: \x{...}.
 
void real::compat::re2::detail::append_set (std::string &out, const ascii_set &set)
 Appends the members of set as class ranges.
 
void real::compat::re2::detail::append_complement (std::string &out, const ascii_set &set, bool icase)
 Appends, as class ranges, every scalar value outside set and, under icase, outside the case partners of its members: the class member RE2 reads for \W or [:^alpha:].
 
std::size_t real::compat::re2::detail::next_character_length (std::string_view text, std::size_t pos)
 The length of the character at pos: its UTF-8 sequence when whole, else one byte (RE2 steps over an invalid byte alone). One past the end of text, one.
 
std::string real::compat::re2::detail::translate_flavor (std::string_view pattern, bool icase)
 Rewrites pattern from RE2's flavor into REAL's: ASCII shorthands and word boundaries, and the POSIX classes, the rest unchanged. Malformed text is copied as it is, for REAL to reject.
 

Detailed Description

real::compat::re2 — RE2's reading of the syntax REAL reads as Python's, rewritten into REAL's.

RE2's \w \d \s are ASCII, its \b \B read ASCII word characters, and it reads the POSIX classes ([[:alpha:]]) inside a bracket. Under case folding RE2 folds a class member before negating it, the member's own negation included: (?i)[\W] leaves out k and the Kelvin sign alike. The rewrite gives REAL the same sets as written members, which REAL folds as RE2 does.

Function Documentation

◆ append_code_point()

void real::compat::re2::detail::append_code_point ( std::string &  out,
std::uint32_t  cp 
)
inline

Appends cp as a class member REAL reads in any position: \x{...}.

Parameters
[in,out]outThe class text.
[in]cpThe code point.

◆ append_complement()

void real::compat::re2::detail::append_complement ( std::string &  out,
const ascii_set &  set,
bool  icase 
)
inline

Appends, as class ranges, every scalar value outside set and, under icase, outside the case partners of its members: the class member RE2 reads for \W or [:^alpha:].

Parameters
[in,out]outThe class text.
[in]setThe set being negated.
[in]icaseWhether the member is folded before it is negated.

◆ append_set()

void real::compat::re2::detail::append_set ( std::string &  out,
const ascii_set &  set 
)
inline

Appends the members of set as class ranges.

Parameters
[in,out]outThe class text.
[in]setThe set.

◆ next_character_length()

std::size_t real::compat::re2::detail::next_character_length ( std::string_view  text,
std::size_t  pos 
)
inline

The length of the character at pos: its UTF-8 sequence when whole, else one byte (RE2 steps over an invalid byte alone). One past the end of text, one.

Parameters
[in]textThe text.
[in]posA position in text, or its end.
Returns
How far the next character starts from pos.

◆ re2_ascii_set()

bool real::compat::re2::detail::re2_ascii_set ( std::string_view  name,
ascii_set &  set 
)
inline

The ASCII set a shorthand letter or a POSIX class name stands for, as RE2 defines it.

Parameters
[in]nameA shorthand letter (w, d, s) or a POSIX class name (alpha, word, ...).
[out]setReceives the set.
Returns
false for a name RE2 does not define.

◆ translate_flavor()

std::string real::compat::re2::detail::translate_flavor ( std::string_view  pattern,
bool  icase 
)
inline

Rewrites pattern from RE2's flavor into REAL's: ASCII shorthands and word boundaries, and the POSIX classes, the rest unchanged. Malformed text is copied as it is, for REAL to reject.

Parameters
[in]patternThe pattern as RE2 reads it.
[in]icaseWhether the pattern starts case-insensitive (Options::case_sensitive false).
Returns
The pattern REAL reads the same way.