...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::xpressive::regex_compiler — Class template regex_compiler is a factory for building basic_regex objects from a string.
// In header: <boost/xpressive/regex_compiler.hpp> template<typename BidiIter, typename RegexTraits, typename CompilerTraits> struct regex_compiler { // types typedef BidiIter iterator_type; typedef iterator_value< BidiIter >::type char_type; typedef regex_constants::syntax_option_type flag_type; typedef RegexTraits traits_type; typedef traits_type::string_type string_type; typedef traits_type::locale_type locale_type; typedef traits_type::char_class_type char_class_type; // construct/copy/destruct explicit regex_compiler(RegexTraits const & = RegexTraits()); // public member functions locale_type imbue(locale_type); locale_type getloc() const; template<typename InputIter> basic_regex< BidiIter > compile(InputIter, InputIter, flag_type = regex_constants::ECMAScript); template<typename InputRange> disable_if< is_pointer< InputRange >, basic_regex< BidiIter > >::type compile(InputRange const &, flag_type = regex_constants::ECMAScript); basic_regex< BidiIter > compile(char_type const *, flag_type = regex_constants::ECMAScript); basic_regex< BidiIter > compile(char_type const *, std::size_t, flag_type); basic_regex< BidiIter > & operator[](string_type const &); basic_regex< BidiIter > const & operator[](string_type const &) const; // private member functions bool is_upper_(char_type) const; };
Class template regex_compiler is used to construct a basic_regex object from a string. The string should contain a valid regular expression. You can imbue a regex_compiler object with a locale, after which all basic_regex objects created with that regex_compiler object will use that locale. After creating a regex_compiler object, and optionally imbueing it with a locale, you can call the compile() method to construct a basic_regex object, passing it the string representing the regular expression. You can call compile() multiple times on the same regex_compiler object. Two basic_regex objects compiled from the same string will have different regex_id's.
regex_compiler
public member functionslocale_type imbue(locale_type loc);
Specify the locale to be used by a regex_compiler
.
Parameters: |
|
||
Returns: |
The previous locale. |
locale_type getloc() const;
Get the locale used by a regex_compiler
.
Returns: |
The locale used by this regex_compiler. |
template<typename InputIter> basic_regex< BidiIter > compile(InputIter begin, InputIter end, flag_type flags = regex_constants::ECMAScript);
Builds a basic_regex
object from a range of characters.
Parameters: |
|
||||||
Requires: |
InputIter is a model of the InputIterator concept. [begin,end) is a valid range. The range of characters specified by [begin,end) contains a valid string-based representation of a regular expression. |
||||||
Returns: |
A basic_regex object corresponding to the regular expression represented by the character range. |
||||||
Throws: |
regex_error when the range of characters has invalid regular expression syntax. |
template<typename InputRange> disable_if< is_pointer< InputRange >, basic_regex< BidiIter > >::type compile(InputRange const & pat, flag_type flags = regex_constants::ECMAScript);
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
basic_regex< BidiIter > compile(char_type const * begin, flag_type flags = regex_constants::ECMAScript);
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
basic_regex< BidiIter > compile(char_type const * begin, std::size_t size, flag_type flags);
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
basic_regex< BidiIter > & operator[](string_type const & name);
Return a reference to the named regular expression. If no such named regular expression exists, create a new regular expression and return a reference to it.
Parameters: |
|
||
Requires: |
The string is not empty. |
||
Throws: |
bad_alloc on allocation failure. |
basic_regex< BidiIter > const & operator[](string_type const & name) const;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.