- tmp/tmpq9bklrof/{from.md → to.md} +308 -800
tmp/tmpq9bklrof/{from.md → to.md}
RENAMED
|
@@ -4,28 +4,28 @@
|
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
operations involving regular expression matching and searching.
|
| 7 |
|
| 8 |
The following subclauses describe a basic regular expression class
|
| 9 |
-
template and its traits that can handle char-like
|
| 10 |
template arguments, two specializations of this class template that
|
| 11 |
handle sequences of `char` and `wchar_t`, a class template that holds
|
| 12 |
the result of a regular expression match, a series of algorithms that
|
| 13 |
allow a character sequence to be operated upon by a regular expression,
|
| 14 |
and two iterator types for enumerating regular expression matches, as
|
| 15 |
-
|
| 16 |
|
| 17 |
-
**Table: Regular expressions library summary** <a id="
|
| 18 |
|
| 19 |
| Subclause | | Header |
|
| 20 |
| --------------- | --------------------------- | --------- |
|
| 21 |
| [[re.def]] | Definitions | |
|
| 22 |
| [[re.req]] | Requirements | |
|
| 23 |
-
| [[re.const]] | Constants |
|
| 24 |
| [[re.badexp]] | Exception type | |
|
| 25 |
| [[re.traits]] | Traits | |
|
| 26 |
-
| [[re.regex]] | Regular expression template |
|
| 27 |
| [[re.submatch]] | Submatches | |
|
| 28 |
| [[re.results]] | Match results | |
|
| 29 |
| [[re.alg]] | Algorithms | |
|
| 30 |
| [[re.iter]] | Iterators | |
|
| 31 |
| [[re.grammar]] | Grammar | |
|
|
@@ -74,46 +74,47 @@ a subset of a regular expression that has been marked by parenthesis.
|
|
| 74 |
## Requirements <a id="re.req">[[re.req]]</a>
|
| 75 |
|
| 76 |
This subclause defines requirements on classes representing regular
|
| 77 |
expression traits.
|
| 78 |
|
| 79 |
-
[*Note 1*: The class template `regex_traits`, defined in
|
| 80 |
-
|
| 81 |
|
| 82 |
-
The class template `basic_regex`, defined in
|
| 83 |
-
|
| 84 |
semantics. These types and functions are provided as a set of member
|
| 85 |
*typedef-name*s and functions in the template parameter `traits` used by
|
| 86 |
the `basic_regex` class template. This subclause defines the semantics
|
| 87 |
of these members.
|
| 88 |
|
| 89 |
To specialize class template `basic_regex` for a character container
|
| 90 |
`CharT` and its related regular expression traits class `Traits`, use
|
| 91 |
`basic_regex<CharT, Traits>`.
|
| 92 |
|
| 93 |
-
In
|
| 94 |
-
|
| 95 |
-
|
| 96 |
X`; `p` is a value of type `const charT*`; `I1` and `I2` are input
|
| 97 |
-
iterators
|
| 98 |
-
[[forward.iterators]]
|
| 99 |
object of type `X::string_type`; `cs` is an object of type
|
| 100 |
`const X::string_type`; `b` is a value of type `bool`; `I` is a value of
|
| 101 |
type `int`; `cl` is an object of type `X::char_class_type`, and `loc` is
|
| 102 |
an object of type `X::locale_type`.
|
| 103 |
|
| 104 |
[*Note 2*: The value of *I* will only be 8, 10, or 16. — *end note*]
|
| 105 |
|
| 106 |
-
[*Note 3*: Class template `regex_traits`
|
| 107 |
-
|
| 108 |
`wchar_t`. This class template is described in the header `<regex>`, and
|
| 109 |
-
is described in
|
| 110 |
|
| 111 |
## Header `<regex>` synopsis <a id="re.syn">[[re.syn]]</a>
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
-
#include <
|
|
|
|
| 115 |
|
| 116 |
namespace std {
|
| 117 |
// [re.const], regex constants
|
| 118 |
namespace regex_constants {
|
| 119 |
using syntax_option_type = T1;
|
|
@@ -148,144 +149,33 @@ namespace std {
|
|
| 148 |
|
| 149 |
// [re.submatch.op], sub_match non-member operators
|
| 150 |
template<class BiIter>
|
| 151 |
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 152 |
template<class BiIter>
|
| 153 |
-
|
| 154 |
-
template <class BiIter>
|
| 155 |
-
bool operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 156 |
-
template <class BiIter>
|
| 157 |
-
bool operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 158 |
-
template <class BiIter>
|
| 159 |
-
bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 160 |
-
template <class BiIter>
|
| 161 |
-
bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 162 |
-
|
| 163 |
-
template <class BiIter, class ST, class SA>
|
| 164 |
-
bool operator==(
|
| 165 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 166 |
-
const sub_match<BiIter>& rhs);
|
| 167 |
-
template <class BiIter, class ST, class SA>
|
| 168 |
-
bool operator!=(
|
| 169 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 170 |
-
const sub_match<BiIter>& rhs);
|
| 171 |
-
template <class BiIter, class ST, class SA>
|
| 172 |
-
bool operator<(
|
| 173 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 174 |
-
const sub_match<BiIter>& rhs);
|
| 175 |
-
template <class BiIter, class ST, class SA>
|
| 176 |
-
bool operator>(
|
| 177 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 178 |
-
const sub_match<BiIter>& rhs);
|
| 179 |
-
template <class BiIter, class ST, class SA>
|
| 180 |
-
bool operator>=(
|
| 181 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 182 |
-
const sub_match<BiIter>& rhs);
|
| 183 |
-
template <class BiIter, class ST, class SA>
|
| 184 |
-
bool operator<=(
|
| 185 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 186 |
-
const sub_match<BiIter>& rhs);
|
| 187 |
|
| 188 |
template<class BiIter, class ST, class SA>
|
| 189 |
bool operator==(
|
| 190 |
const sub_match<BiIter>& lhs,
|
| 191 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 192 |
template<class BiIter, class ST, class SA>
|
| 193 |
-
|
| 194 |
const sub_match<BiIter>& lhs,
|
| 195 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 196 |
-
template <class BiIter, class ST, class SA>
|
| 197 |
-
bool operator<(
|
| 198 |
-
const sub_match<BiIter>& lhs,
|
| 199 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 200 |
-
template <class BiIter, class ST, class SA>
|
| 201 |
-
bool operator>(
|
| 202 |
-
const sub_match<BiIter>& lhs,
|
| 203 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 204 |
-
template <class BiIter, class ST, class SA>
|
| 205 |
-
bool operator>=(
|
| 206 |
-
const sub_match<BiIter>& lhs,
|
| 207 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 208 |
-
template <class BiIter, class ST, class SA>
|
| 209 |
-
bool operator<=(
|
| 210 |
-
const sub_match<BiIter>& lhs,
|
| 211 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 212 |
-
|
| 213 |
-
template <class BiIter>
|
| 214 |
-
bool operator==(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 215 |
-
const sub_match<BiIter>& rhs);
|
| 216 |
-
template <class BiIter>
|
| 217 |
-
bool operator!=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 218 |
-
const sub_match<BiIter>& rhs);
|
| 219 |
-
template <class BiIter>
|
| 220 |
-
bool operator<(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 221 |
-
const sub_match<BiIter>& rhs);
|
| 222 |
-
template <class BiIter>
|
| 223 |
-
bool operator>(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 224 |
-
const sub_match<BiIter>& rhs);
|
| 225 |
-
template <class BiIter>
|
| 226 |
-
bool operator>=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 227 |
-
const sub_match<BiIter>& rhs);
|
| 228 |
-
template <class BiIter>
|
| 229 |
-
bool operator<=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 230 |
-
const sub_match<BiIter>& rhs);
|
| 231 |
|
| 232 |
template<class BiIter>
|
| 233 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 234 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 235 |
template<class BiIter>
|
| 236 |
-
|
| 237 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 238 |
-
template <class BiIter>
|
| 239 |
-
bool operator<(const sub_match<BiIter>& lhs,
|
| 240 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 241 |
-
template <class BiIter>
|
| 242 |
-
bool operator>(const sub_match<BiIter>& lhs,
|
| 243 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 244 |
-
template <class BiIter>
|
| 245 |
-
bool operator>=(const sub_match<BiIter>& lhs,
|
| 246 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 247 |
-
template <class BiIter>
|
| 248 |
-
bool operator<=(const sub_match<BiIter>& lhs,
|
| 249 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 250 |
|
| 251 |
-
template <class BiIter>
|
| 252 |
-
bool operator==(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 253 |
-
const sub_match<BiIter>& rhs);
|
| 254 |
-
template <class BiIter>
|
| 255 |
-
bool operator!=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 256 |
-
const sub_match<BiIter>& rhs);
|
| 257 |
-
template <class BiIter>
|
| 258 |
-
bool operator<(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 259 |
-
const sub_match<BiIter>& rhs);
|
| 260 |
-
template <class BiIter>
|
| 261 |
-
bool operator>(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 262 |
-
const sub_match<BiIter>& rhs);
|
| 263 |
-
template <class BiIter>
|
| 264 |
-
bool operator>=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 265 |
-
const sub_match<BiIter>& rhs);
|
| 266 |
-
template <class BiIter>
|
| 267 |
-
bool operator<=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 268 |
-
const sub_match<BiIter>& rhs);
|
| 269 |
-
|
| 270 |
template<class BiIter>
|
| 271 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 272 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 273 |
template<class BiIter>
|
| 274 |
-
|
| 275 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 276 |
-
template <class BiIter>
|
| 277 |
-
bool operator<(const sub_match<BiIter>& lhs,
|
| 278 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 279 |
-
template <class BiIter>
|
| 280 |
-
bool operator>(const sub_match<BiIter>& lhs,
|
| 281 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 282 |
-
template <class BiIter>
|
| 283 |
-
bool operator>=(const sub_match<BiIter>& lhs,
|
| 284 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 285 |
-
template <class BiIter>
|
| 286 |
-
bool operator<=(const sub_match<BiIter>& lhs,
|
| 287 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 288 |
|
| 289 |
template<class charT, class ST, class BiIter>
|
| 290 |
basic_ostream<charT, ST>&
|
| 291 |
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
|
|
@@ -302,13 +192,10 @@ namespace std {
|
|
| 302 |
|
| 303 |
// match_results comparisons
|
| 304 |
template<class BidirectionalIterator, class Allocator>
|
| 305 |
bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 306 |
const match_results<BidirectionalIterator, Allocator>& m2);
|
| 307 |
-
template <class BidirectionalIterator, class Allocator>
|
| 308 |
-
bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 309 |
-
const match_results<BidirectionalIterator, Allocator>& m2);
|
| 310 |
|
| 311 |
// [re.results.swap], match_results swap
|
| 312 |
template<class BidirectionalIterator, class Allocator>
|
| 313 |
void swap(match_results<BidirectionalIterator, Allocator>& m1,
|
| 314 |
match_results<BidirectionalIterator, Allocator>& m2);
|
|
@@ -487,31 +374,31 @@ namespace std::regex_constants {
|
|
| 487 |
inline constexpr syntax_option_type multiline = unspecified;
|
| 488 |
}
|
| 489 |
```
|
| 490 |
|
| 491 |
The type `syntax_option_type` is an *implementation-defined* bitmask
|
| 492 |
-
type
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
`
|
| 496 |
-
grammar
|
| 497 |
|
| 498 |
-
**Table: `syntax_option_type` effects** <a id="
|
| 499 |
|
| 500 |
| Element | Effect(s) if set |
|
| 501 |
-
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 502 |
-
| % `icase` | Specifies that matching of regular expressions against a character container sequence shall be performed without regard to case. \
|
| 503 |
-
| % `nosubs` | Specifies that no sub-expressions shall be considered to be marked, so that when a regular expression is matched against a character container sequence, no sub-expression matches shall be stored in the supplied `match_results`
|
| 504 |
-
| % `optimize` | Specifies that the regular expression engine should pay more attention to the speed with which regular expressions are matched, and less to the speed with which regular expression objects are constructed. Otherwise it has no detectable effect on the program output. \
|
| 505 |
-
| % `collate` | Specifies that character ranges of the form `"[a-b]"` shall be locale sensitive. \
|
| 506 |
-
| % `ECMAScript` | Specifies that the grammar recognized by the regular expression engine shall be that used by ECMAScript in ECMA-262, as modified in~ [[re.grammar]]. \indextext{ECMAScript}% \
|
| 507 |
-
| % `basic` | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9
|
| 508 |
-
| % `extended` | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX, Base Definitions and Headers, Section 9
|
| 509 |
-
| % `awk` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX. \indextext{\idxcode{awk}}% \
|
| 510 |
-
| % `grep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX. \indextext{\idxcode{grep}}% \
|
| 511 |
-
| % `egrep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX. \indextext{\idxcode{egrep}}% \
|
| 512 |
-
| % `multiline` | Specifies that `
|
| 513 |
|
| 514 |
|
| 515 |
### Bitmask type `match_flag_type` <a id="re.matchflag">[[re.matchflag]]</a>
|
| 516 |
|
| 517 |
``` cpp
|
|
@@ -531,37 +418,36 @@ namespace std::regex_constants {
|
|
| 531 |
inline constexpr match_flag_type format_no_copy = unspecified;
|
| 532 |
inline constexpr match_flag_type format_first_only = unspecified;
|
| 533 |
}
|
| 534 |
```
|
| 535 |
|
| 536 |
-
The type `match_flag_type` is an *implementation-defined* bitmask type
|
| 537 |
-
[[bitmask.types]]
|
| 538 |
`match_default` and `format_default`, are bitmask elements. The
|
| 539 |
`match_default` and `format_default` constants are empty bitmasks.
|
| 540 |
Matching a regular expression against a sequence of characters
|
| 541 |
\[`first`, `last`) proceeds according to the rules of the grammar
|
| 542 |
specified for the regular expression object, modified according to the
|
| 543 |
-
effects listed in
|
| 544 |
-
set.
|
| 545 |
|
| 546 |
**Table: `regex_constants::match_flag_type` effects when obtaining a match against a
|
| 547 |
-
character container sequence {[}`first`, `last`{)}.** <a id="
|
| 548 |
|
| 549 |
| Element | Effect(s) if set |
|
| 550 |
-
| -------------------------------------------------------------
|
| 551 |
-
| % \
|
| 552 |
-
| % \
|
| 553 |
-
| % \
|
| 554 |
-
| % \
|
| 555 |
-
| % \
|
| 556 |
-
| % \
|
| 557 |
-
| % \
|
| 558 |
-
| % \
|
| 559 |
-
| % \
|
| 560 |
-
| % \
|
| 561 |
-
| % \
|
| 562 |
-
| % \
|
| 563 |
|
| 564 |
|
| 565 |
### Implementation-defined `error_type` <a id="re.err">[[re.err]]</a>
|
| 566 |
|
| 567 |
``` cpp
|
|
@@ -581,15 +467,15 @@ namespace std::regex_constants {
|
|
| 581 |
inline constexpr error_type error_complexity = unspecified;
|
| 582 |
inline constexpr error_type error_stack = unspecified;
|
| 583 |
}
|
| 584 |
```
|
| 585 |
|
| 586 |
-
The type `error_type` is an *implementation-defined* enumerated type
|
| 587 |
-
[[enumerated.types]]
|
| 588 |
-
conditions described in
|
| 589 |
|
| 590 |
-
**Table: `error_type` values in the C locale** <a id="
|
| 591 |
|
| 592 |
| Value | Error condition |
|
| 593 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
| 594 |
| `error_collate` | The expression contained an invalid collating element name. |
|
| 595 |
| % `error_ctype` | The expression contained an invalid character class name. |
|
|
@@ -621,13 +507,11 @@ to report errors from the regular expression library.
|
|
| 621 |
|
| 622 |
``` cpp
|
| 623 |
regex_error(regex_constants::error_type ecode);
|
| 624 |
```
|
| 625 |
|
| 626 |
-
*
|
| 627 |
-
|
| 628 |
-
*Postconditions:* `ecode == code()`.
|
| 629 |
|
| 630 |
``` cpp
|
| 631 |
regex_constants::error_type code() const;
|
| 632 |
```
|
| 633 |
|
|
@@ -640,11 +524,11 @@ namespace std {
|
|
| 640 |
template<class charT>
|
| 641 |
struct regex_traits {
|
| 642 |
using char_type = charT;
|
| 643 |
using string_type = basic_string<char_type>;
|
| 644 |
using locale_type = locale;
|
| 645 |
-
using char_class_type =
|
| 646 |
|
| 647 |
regex_traits();
|
| 648 |
static size_t length(const char_type* p);
|
| 649 |
charT translate(charT c) const;
|
| 650 |
charT translate_nocase(charT c) const;
|
|
@@ -666,12 +550,11 @@ namespace std {
|
|
| 666 |
};
|
| 667 |
}
|
| 668 |
```
|
| 669 |
|
| 670 |
The specializations `regex_traits<char>` and `regex_traits<wchar_t>`
|
| 671 |
-
|
| 672 |
-
expression traits class ([[re.req]]).
|
| 673 |
|
| 674 |
``` cpp
|
| 675 |
using char_class_type = bitmask_type;
|
| 676 |
```
|
| 677 |
|
|
@@ -705,11 +588,11 @@ template <class ForwardIterator>
|
|
| 705 |
*Effects:* As if by:
|
| 706 |
|
| 707 |
``` cpp
|
| 708 |
string_type str(first, last);
|
| 709 |
return use_facet<collate<charT>>(
|
| 710 |
-
getloc()).transform(
|
| 711 |
```
|
| 712 |
|
| 713 |
``` cpp
|
| 714 |
template<class ForwardIterator>
|
| 715 |
string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
|
|
@@ -729,35 +612,35 @@ returns an empty string.
|
|
| 729 |
``` cpp
|
| 730 |
template<class ForwardIterator>
|
| 731 |
string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
|
| 732 |
```
|
| 733 |
|
| 734 |
-
*Returns:*
|
| 735 |
collating element consisting of the character sequence designated by the
|
| 736 |
iterator range \[`first`, `last`). Returns an empty string if the
|
| 737 |
character sequence is not a valid collating element.
|
| 738 |
|
| 739 |
``` cpp
|
| 740 |
template<class ForwardIterator>
|
| 741 |
char_class_type lookup_classname(
|
| 742 |
ForwardIterator first, ForwardIterator last, bool icase = false) const;
|
| 743 |
```
|
| 744 |
|
| 745 |
-
*Returns:*
|
| 746 |
classification named by the character sequence designated by the
|
| 747 |
iterator range \[`first`, `last`). If the parameter `icase` is `true`
|
| 748 |
then the returned mask identifies the character classification without
|
| 749 |
regard to the case of the characters being matched, otherwise it does
|
| 750 |
honor the case of the characters being matched.[^1] The value returned
|
| 751 |
shall be independent of the case of the characters in the character
|
| 752 |
sequence. If the name is not recognized then returns
|
| 753 |
`char_class_type()`.
|
| 754 |
|
| 755 |
*Remarks:* For `regex_traits<char>`, at least the narrow character names
|
| 756 |
-
in
|
| 757 |
`regex_traits<wchar_t>`, at least the wide character names in
|
| 758 |
-
|
| 759 |
|
| 760 |
``` cpp
|
| 761 |
bool isctype(charT c, char_class_type f) const;
|
| 762 |
```
|
| 763 |
|
|
@@ -771,13 +654,12 @@ classification represented by `f`.
|
|
| 771 |
template<class C>
|
| 772 |
ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
|
| 773 |
```
|
| 774 |
|
| 775 |
that returns a value in which each `ctype_base::mask` value
|
| 776 |
-
corresponding to a value in `f` named in
|
| 777 |
-
|
| 778 |
-
determined as if by:
|
| 779 |
|
| 780 |
``` cpp
|
| 781 |
ctype_base::mask m = convert<charT>(f);
|
| 782 |
const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
|
| 783 |
if (ct.is(m, c)) {
|
|
@@ -821,13 +703,13 @@ t.isctype(' ', f); // returns false
|
|
| 821 |
|
| 822 |
``` cpp
|
| 823 |
int value(charT ch, int radix) const;
|
| 824 |
```
|
| 825 |
|
| 826 |
-
*
|
| 827 |
|
| 828 |
-
*Returns:*
|
| 829 |
the character `ch` is a valid digit in base `radix`; otherwise returns
|
| 830 |
`-1`.
|
| 831 |
|
| 832 |
``` cpp
|
| 833 |
locale_type imbue(locale_type loc);
|
|
@@ -837,25 +719,25 @@ locale_type imbue(locale_type loc);
|
|
| 837 |
|
| 838 |
[*Note 1*: Calling `imbue` with a different locale than the one
|
| 839 |
currently in use invalidates all cached data held by
|
| 840 |
`*this`. — *end note*]
|
| 841 |
|
| 842 |
-
*Returns:*
|
| 843 |
global locale in effect at the time of construction of `*this`,
|
| 844 |
otherwise a copy of the last argument passed to `imbue`.
|
| 845 |
|
| 846 |
-
*
|
| 847 |
|
| 848 |
``` cpp
|
| 849 |
locale_type getloc() const;
|
| 850 |
```
|
| 851 |
|
| 852 |
-
*Returns:*
|
| 853 |
in effect at the time of construction of `*this`, otherwise a copy of
|
| 854 |
the last argument passed to `imbue`.
|
| 855 |
|
| 856 |
-
**Table: Character class names and corresponding `ctype` masks** <a id="
|
| 857 |
|
| 858 |
| Narrow character name | Wide character name | Corresponding `ctype_base::mask` value |
|
| 859 |
| --------------------- | ------------------- | -------------------------------------- |
|
| 860 |
| `"alnum"` | `L"alnum"` | `ctype_base::alnum` |
|
| 861 |
| `"alpha"` | `L"alpha"` | `ctype_base::alpha` |
|
|
@@ -888,87 +770,76 @@ converting the sequence of `charT` objects to an internal
|
|
| 888 |
representation. It is not specified what form this representation takes,
|
| 889 |
nor how it is accessed by algorithms that operate on regular
|
| 890 |
expressions.
|
| 891 |
|
| 892 |
[*Note 1*: Implementations will typically declare some function
|
| 893 |
-
templates as friends of `basic_regex` to achieve this — *end note*]
|
| 894 |
|
| 895 |
The functions described in this Clause report errors by throwing
|
| 896 |
exceptions of type `regex_error`.
|
| 897 |
|
| 898 |
``` cpp
|
| 899 |
namespace std {
|
| 900 |
template<class charT, class traits = regex_traits<charT>>
|
| 901 |
class basic_regex {
|
| 902 |
public:
|
| 903 |
-
// types
|
| 904 |
using value_type = charT;
|
| 905 |
using traits_type = traits;
|
| 906 |
using string_type = typename traits::string_type;
|
| 907 |
using flag_type = regex_constants::syntax_option_type;
|
| 908 |
using locale_type = typename traits::locale_type;
|
| 909 |
|
| 910 |
-
// [re.
|
| 911 |
-
static constexpr regex_constants::
|
| 912 |
-
|
| 913 |
-
static constexpr regex_constants::
|
| 914 |
-
|
| 915 |
-
static constexpr regex_constants::
|
| 916 |
-
|
| 917 |
-
static constexpr regex_constants::
|
| 918 |
-
|
| 919 |
-
static constexpr regex_constants::
|
| 920 |
-
|
| 921 |
-
static constexpr regex_constants::
|
| 922 |
-
basic = regex_constants::basic;
|
| 923 |
-
static constexpr regex_constants::syntax_option_type
|
| 924 |
-
extended = regex_constants::extended;
|
| 925 |
-
static constexpr regex_constants::syntax_option_type
|
| 926 |
-
awk = regex_constants::awk;
|
| 927 |
-
static constexpr regex_constants::syntax_option_type
|
| 928 |
-
grep = regex_constants::grep;
|
| 929 |
-
static constexpr regex_constants::syntax_option_type
|
| 930 |
-
egrep = regex_constants::egrep;
|
| 931 |
-
static constexpr regex_constants::syntax_option_type
|
| 932 |
-
multiline = regex_constants::multiline;
|
| 933 |
|
| 934 |
// [re.regex.construct], construct/copy/destroy
|
| 935 |
basic_regex();
|
| 936 |
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 937 |
basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
|
| 938 |
basic_regex(const basic_regex&);
|
| 939 |
basic_regex(basic_regex&&) noexcept;
|
| 940 |
template<class ST, class SA>
|
| 941 |
-
explicit basic_regex(const basic_string<charT, ST, SA>&
|
| 942 |
flag_type f = regex_constants::ECMAScript);
|
| 943 |
template<class ForwardIterator>
|
| 944 |
basic_regex(ForwardIterator first, ForwardIterator last,
|
| 945 |
flag_type f = regex_constants::ECMAScript);
|
| 946 |
-
basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
|
| 947 |
|
| 948 |
~basic_regex();
|
| 949 |
|
| 950 |
-
basic_regex& operator=(const basic_regex&);
|
| 951 |
-
basic_regex& operator=(basic_regex&&) noexcept;
|
| 952 |
-
basic_regex& operator=(const charT* ptr);
|
| 953 |
-
basic_regex& operator=(initializer_list<charT> il);
|
| 954 |
-
template <class ST, class SA>
|
| 955 |
-
basic_regex& operator=(const basic_string<charT, ST, SA>& p);
|
| 956 |
-
|
| 957 |
// [re.regex.assign], assign
|
| 958 |
-
basic_regex&
|
| 959 |
-
basic_regex&
|
| 960 |
-
basic_regex&
|
| 961 |
-
basic_regex&
|
| 962 |
-
template
|
| 963 |
-
basic_regex&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
flag_type f = regex_constants::ECMAScript);
|
| 965 |
template<class InputIterator>
|
| 966 |
basic_regex& assign(InputIterator first, InputIterator last,
|
| 967 |
flag_type f = regex_constants::ECMAScript);
|
| 968 |
basic_regex& assign(initializer_list<charT>,
|
| 969 |
-
flag_type = regex_constants::ECMAScript);
|
| 970 |
|
| 971 |
// [re.regex.operations], const operations
|
| 972 |
unsigned mark_count() const;
|
| 973 |
flag_type flags() const;
|
| 974 |
|
|
@@ -985,239 +856,198 @@ namespace std {
|
|
| 985 |
regex_constants::syntax_option_type = regex_constants::ECMAScript)
|
| 986 |
-> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
|
| 987 |
}
|
| 988 |
```
|
| 989 |
|
| 990 |
-
###
|
| 991 |
-
|
| 992 |
-
``` cpp
|
| 993 |
-
static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
|
| 994 |
-
static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
|
| 995 |
-
static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
|
| 996 |
-
static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
|
| 997 |
-
static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
|
| 998 |
-
static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
|
| 999 |
-
static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
|
| 1000 |
-
static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
|
| 1001 |
-
static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
|
| 1002 |
-
static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
|
| 1003 |
-
static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
|
| 1004 |
-
```
|
| 1005 |
-
|
| 1006 |
-
The static constant members are provided as synonyms for the constants
|
| 1007 |
-
declared in namespace `regex_constants`.
|
| 1008 |
-
|
| 1009 |
-
### `basic_regex` constructors <a id="re.regex.construct">[[re.regex.construct]]</a>
|
| 1010 |
|
| 1011 |
``` cpp
|
| 1012 |
basic_regex();
|
| 1013 |
```
|
| 1014 |
|
| 1015 |
-
*
|
| 1016 |
-
match any character sequence.
|
| 1017 |
|
| 1018 |
``` cpp
|
| 1019 |
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 1020 |
```
|
| 1021 |
|
| 1022 |
-
*
|
|
|
|
| 1023 |
|
| 1024 |
-
*
|
|
|
|
|
|
|
|
|
|
| 1025 |
|
| 1026 |
-
*
|
| 1027 |
-
|
| 1028 |
-
contained in the array of `charT` of length
|
| 1029 |
-
`char_traits<charT>::length(p)` whose first element is designated by
|
| 1030 |
-
`p`, and interpreted according to the flags `f`.
|
| 1031 |
|
| 1032 |
-
*
|
| 1033 |
-
|
| 1034 |
|
| 1035 |
``` cpp
|
| 1036 |
-
basic_regex(const charT* p, size_t len, flag_type f);
|
| 1037 |
```
|
| 1038 |
|
| 1039 |
-
*
|
| 1040 |
|
| 1041 |
-
*
|
|
|
|
|
|
|
| 1042 |
|
| 1043 |
-
*
|
| 1044 |
-
|
| 1045 |
-
contained in the sequence of characters \[`p`, `p+len`), and interpreted
|
| 1046 |
-
according the flags specified in `f`.
|
| 1047 |
|
| 1048 |
-
*
|
| 1049 |
-
|
| 1050 |
|
| 1051 |
``` cpp
|
| 1052 |
basic_regex(const basic_regex& e);
|
| 1053 |
```
|
| 1054 |
|
| 1055 |
-
*
|
| 1056 |
-
object `e`.
|
| 1057 |
-
|
| 1058 |
-
*Postconditions:* `flags()` and `mark_count()` return `e.flags()` and
|
| 1059 |
`e.mark_count()`, respectively.
|
| 1060 |
|
| 1061 |
``` cpp
|
| 1062 |
basic_regex(basic_regex&& e) noexcept;
|
| 1063 |
```
|
| 1064 |
|
| 1065 |
-
*
|
| 1066 |
-
|
| 1067 |
-
*Postconditions:* `flags()` and `mark_count()` return the values that
|
| 1068 |
`e.flags()` and `e.mark_count()`, respectively, had before construction.
|
| 1069 |
-
`e` is in a valid state with unspecified value.
|
| 1070 |
|
| 1071 |
``` cpp
|
| 1072 |
template<class ST, class SA>
|
| 1073 |
explicit basic_regex(const basic_string<charT, ST, SA>& s,
|
| 1074 |
flag_type f = regex_constants::ECMAScript);
|
| 1075 |
```
|
| 1076 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
*Throws:* `regex_error` if `s` is not a valid regular expression.
|
| 1078 |
|
| 1079 |
-
*Effects:* Constructs an object of class `basic_regex`; the object’s
|
| 1080 |
-
internal finite state machine is constructed from the regular expression
|
| 1081 |
-
contained in the string `s`, and interpreted according to the flags
|
| 1082 |
-
specified in `f`.
|
| 1083 |
-
|
| 1084 |
-
*Postconditions:* `flags()` returns `f`. `mark_count()` returns the
|
| 1085 |
-
number of marked sub-expressions within the expression.
|
| 1086 |
-
|
| 1087 |
``` cpp
|
| 1088 |
template<class ForwardIterator>
|
| 1089 |
basic_regex(ForwardIterator first, ForwardIterator last,
|
| 1090 |
flag_type f = regex_constants::ECMAScript);
|
| 1091 |
```
|
| 1092 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1093 |
*Throws:* `regex_error` if the sequence \[`first`, `last`) is not a
|
| 1094 |
valid regular expression.
|
| 1095 |
|
| 1096 |
-
*Effects:* Constructs an object of class `basic_regex`; the object’s
|
| 1097 |
-
internal finite state machine is constructed from the regular expression
|
| 1098 |
-
contained in the sequence of characters \[`first`, `last`), and
|
| 1099 |
-
interpreted according to the flags specified in `f`.
|
| 1100 |
-
|
| 1101 |
-
*Postconditions:* `flags()` returns `f`. `mark_count()` returns the
|
| 1102 |
-
number of marked sub-expressions within the expression.
|
| 1103 |
-
|
| 1104 |
``` cpp
|
| 1105 |
basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
|
| 1106 |
```
|
| 1107 |
|
| 1108 |
*Effects:* Same as `basic_regex(il.begin(), il.end(), f)`.
|
| 1109 |
|
| 1110 |
-
###
|
| 1111 |
|
| 1112 |
``` cpp
|
| 1113 |
basic_regex& operator=(const basic_regex& e);
|
| 1114 |
```
|
| 1115 |
|
| 1116 |
-
*
|
| 1117 |
-
|
| 1118 |
-
*Postconditions:* `flags()` and `mark_count()` return `e.flags()` and
|
| 1119 |
`e.mark_count()`, respectively.
|
| 1120 |
|
| 1121 |
``` cpp
|
| 1122 |
basic_regex& operator=(basic_regex&& e) noexcept;
|
| 1123 |
```
|
| 1124 |
|
| 1125 |
-
*
|
| 1126 |
-
|
| 1127 |
-
*Postconditions:* `flags()` and `mark_count()` return the values that
|
| 1128 |
`e.flags()` and `e.mark_count()`, respectively, had before assignment.
|
| 1129 |
`e` is in a valid state with unspecified value.
|
| 1130 |
|
| 1131 |
``` cpp
|
| 1132 |
-
basic_regex& operator=(const charT*
|
| 1133 |
```
|
| 1134 |
|
| 1135 |
-
*
|
| 1136 |
-
|
| 1137 |
-
*Effects:* Returns `assign(ptr)`.
|
| 1138 |
|
| 1139 |
``` cpp
|
| 1140 |
basic_regex& operator=(initializer_list<charT> il);
|
| 1141 |
```
|
| 1142 |
|
| 1143 |
-
*Effects:*
|
| 1144 |
|
| 1145 |
``` cpp
|
| 1146 |
template<class ST, class SA>
|
| 1147 |
-
basic_regex& operator=(const basic_string<charT, ST, SA>&
|
| 1148 |
```
|
| 1149 |
|
| 1150 |
-
*Effects:*
|
| 1151 |
|
| 1152 |
``` cpp
|
| 1153 |
-
basic_regex& assign(const basic_regex&
|
| 1154 |
```
|
| 1155 |
|
| 1156 |
-
*Effects:* Equivalent to `*this =
|
| 1157 |
-
|
| 1158 |
-
*Returns:* `*this`.
|
| 1159 |
|
| 1160 |
``` cpp
|
| 1161 |
-
basic_regex& assign(basic_regex&&
|
| 1162 |
```
|
| 1163 |
|
| 1164 |
-
*Effects:* Equivalent to `*this = std::move(
|
| 1165 |
-
|
| 1166 |
-
*Returns:* `*this`.
|
| 1167 |
|
| 1168 |
``` cpp
|
| 1169 |
-
basic_regex& assign(const charT*
|
| 1170 |
```
|
| 1171 |
|
| 1172 |
-
*
|
| 1173 |
|
| 1174 |
``` cpp
|
| 1175 |
-
basic_regex& assign(const charT*
|
| 1176 |
```
|
| 1177 |
|
| 1178 |
-
*
|
| 1179 |
|
| 1180 |
``` cpp
|
| 1181 |
-
template
|
| 1182 |
-
basic_regex& assign(const basic_string<charT,
|
| 1183 |
flag_type f = regex_constants::ECMAScript);
|
| 1184 |
```
|
| 1185 |
|
| 1186 |
-
*Throws:* `regex_error` if `s` is not a valid regular expression.
|
| 1187 |
-
|
| 1188 |
*Returns:* `*this`.
|
| 1189 |
|
| 1190 |
*Effects:* Assigns the regular expression contained in the string `s`,
|
| 1191 |
interpreted according the flags specified in `f`. If an exception is
|
| 1192 |
thrown, `*this` is unchanged.
|
| 1193 |
|
| 1194 |
-
*
|
| 1195 |
`mark_count()` returns the number of marked sub-expressions within the
|
| 1196 |
expression.
|
| 1197 |
|
|
|
|
|
|
|
| 1198 |
``` cpp
|
| 1199 |
template<class InputIterator>
|
| 1200 |
basic_regex& assign(InputIterator first, InputIterator last,
|
| 1201 |
flag_type f = regex_constants::ECMAScript);
|
| 1202 |
```
|
| 1203 |
|
| 1204 |
-
*
|
| 1205 |
-
an Input Iterator ([[input.iterators]]).
|
| 1206 |
-
|
| 1207 |
-
*Returns:* `assign(string_type(first, last), f)`.
|
| 1208 |
|
| 1209 |
``` cpp
|
| 1210 |
basic_regex& assign(initializer_list<charT> il,
|
| 1211 |
flag_type f = regex_constants::ECMAScript);
|
| 1212 |
```
|
| 1213 |
|
| 1214 |
-
*Effects:*
|
| 1215 |
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
### `basic_regex` constant operations <a id="re.regex.operations">[[re.regex.operations]]</a>
|
| 1219 |
|
| 1220 |
``` cpp
|
| 1221 |
unsigned mark_count() const;
|
| 1222 |
```
|
| 1223 |
|
|
@@ -1229,11 +1059,11 @@ flag_type flags() const;
|
|
| 1229 |
```
|
| 1230 |
|
| 1231 |
*Effects:* Returns a copy of the regular expression syntax flags that
|
| 1232 |
were passed to the object’s constructor or to the last call to `assign`.
|
| 1233 |
|
| 1234 |
-
###
|
| 1235 |
|
| 1236 |
``` cpp
|
| 1237 |
locale_type imbue(locale_type loc);
|
| 1238 |
```
|
| 1239 |
|
|
@@ -1248,26 +1078,24 @@ locale_type getloc() const;
|
|
| 1248 |
|
| 1249 |
*Effects:* Returns the result of `traits_inst.getloc()` where
|
| 1250 |
`traits_inst` is a (default-initialized) instance of the template
|
| 1251 |
parameter `traits` stored within the object.
|
| 1252 |
|
| 1253 |
-
###
|
| 1254 |
|
| 1255 |
``` cpp
|
| 1256 |
void swap(basic_regex& e);
|
| 1257 |
```
|
| 1258 |
|
| 1259 |
*Effects:* Swaps the contents of the two regular expressions.
|
| 1260 |
|
| 1261 |
-
*
|
| 1262 |
-
|
| 1263 |
|
| 1264 |
*Complexity:* Constant time.
|
| 1265 |
|
| 1266 |
-
###
|
| 1267 |
-
|
| 1268 |
-
#### `basic_regex` non-member swap <a id="re.regex.nmswap">[[re.regex.nmswap]]</a>
|
| 1269 |
|
| 1270 |
``` cpp
|
| 1271 |
template<class charT, class traits>
|
| 1272 |
void swap(basic_regex<charT, traits>& lhs, basic_regex<charT, traits>& rhs);
|
| 1273 |
```
|
|
@@ -1304,11 +1132,11 @@ namespace std {
|
|
| 1304 |
int compare(const value_type* s) const;
|
| 1305 |
};
|
| 1306 |
}
|
| 1307 |
```
|
| 1308 |
|
| 1309 |
-
###
|
| 1310 |
|
| 1311 |
``` cpp
|
| 1312 |
constexpr sub_match();
|
| 1313 |
```
|
| 1314 |
|
|
@@ -1349,115 +1177,31 @@ int compare(const string_type& s) const;
|
|
| 1349 |
int compare(const value_type* s) const;
|
| 1350 |
```
|
| 1351 |
|
| 1352 |
*Returns:* `str().compare(s)`.
|
| 1353 |
|
| 1354 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1355 |
|
| 1356 |
``` cpp
|
| 1357 |
template<class BiIter>
|
| 1358 |
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1359 |
```
|
| 1360 |
|
| 1361 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 1362 |
|
| 1363 |
``` cpp
|
| 1364 |
template<class BiIter>
|
| 1365 |
-
|
| 1366 |
```
|
| 1367 |
|
| 1368 |
-
*Returns:* `lhs.compare(rhs)
|
| 1369 |
-
|
| 1370 |
-
``` cpp
|
| 1371 |
-
template <class BiIter>
|
| 1372 |
-
bool operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1373 |
-
```
|
| 1374 |
-
|
| 1375 |
-
*Returns:* `lhs.compare(rhs) < 0`.
|
| 1376 |
-
|
| 1377 |
-
``` cpp
|
| 1378 |
-
template <class BiIter>
|
| 1379 |
-
bool operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1380 |
-
```
|
| 1381 |
-
|
| 1382 |
-
*Returns:* `lhs.compare(rhs) <= 0`.
|
| 1383 |
-
|
| 1384 |
-
``` cpp
|
| 1385 |
-
template <class BiIter>
|
| 1386 |
-
bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1387 |
-
```
|
| 1388 |
-
|
| 1389 |
-
*Returns:* `lhs.compare(rhs) >= 0`.
|
| 1390 |
-
|
| 1391 |
-
``` cpp
|
| 1392 |
-
template <class BiIter>
|
| 1393 |
-
bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1394 |
-
```
|
| 1395 |
-
|
| 1396 |
-
*Returns:* `lhs.compare(rhs) > 0`.
|
| 1397 |
-
|
| 1398 |
-
``` cpp
|
| 1399 |
-
template <class BiIter, class ST, class SA>
|
| 1400 |
-
bool operator==(
|
| 1401 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1402 |
-
const sub_match<BiIter>& rhs);
|
| 1403 |
-
```
|
| 1404 |
-
|
| 1405 |
-
*Returns:*
|
| 1406 |
-
|
| 1407 |
-
``` cpp
|
| 1408 |
-
rhs.compare(typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) == 0
|
| 1409 |
-
```
|
| 1410 |
-
|
| 1411 |
-
``` cpp
|
| 1412 |
-
template <class BiIter, class ST, class SA>
|
| 1413 |
-
bool operator!=(
|
| 1414 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1415 |
-
const sub_match<BiIter>& rhs);
|
| 1416 |
-
```
|
| 1417 |
-
|
| 1418 |
-
*Returns:* `!(lhs == rhs)`.
|
| 1419 |
-
|
| 1420 |
-
``` cpp
|
| 1421 |
-
template <class BiIter, class ST, class SA>
|
| 1422 |
-
bool operator<(
|
| 1423 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1424 |
-
const sub_match<BiIter>& rhs);
|
| 1425 |
-
```
|
| 1426 |
-
|
| 1427 |
-
*Returns:*
|
| 1428 |
-
|
| 1429 |
-
``` cpp
|
| 1430 |
-
rhs.compare(typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) > 0
|
| 1431 |
-
```
|
| 1432 |
-
|
| 1433 |
-
``` cpp
|
| 1434 |
-
template <class BiIter, class ST, class SA>
|
| 1435 |
-
bool operator>(
|
| 1436 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1437 |
-
const sub_match<BiIter>& rhs);
|
| 1438 |
-
```
|
| 1439 |
-
|
| 1440 |
-
*Returns:* `rhs < lhs`.
|
| 1441 |
-
|
| 1442 |
-
``` cpp
|
| 1443 |
-
template <class BiIter, class ST, class SA>
|
| 1444 |
-
bool operator>=(
|
| 1445 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1446 |
-
const sub_match<BiIter>& rhs);
|
| 1447 |
-
```
|
| 1448 |
-
|
| 1449 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1450 |
-
|
| 1451 |
-
``` cpp
|
| 1452 |
-
template <class BiIter, class ST, class SA>
|
| 1453 |
-
bool operator<=(
|
| 1454 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
|
| 1455 |
-
const sub_match<BiIter>& rhs);
|
| 1456 |
-
```
|
| 1457 |
-
|
| 1458 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1459 |
|
| 1460 |
``` cpp
|
| 1461 |
template<class BiIter, class ST, class SA>
|
| 1462 |
bool operator==(
|
| 1463 |
const sub_match<BiIter>& lhs,
|
|
@@ -1470,202 +1214,39 @@ template <class BiIter, class ST, class SA>
|
|
| 1470 |
lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0
|
| 1471 |
```
|
| 1472 |
|
| 1473 |
``` cpp
|
| 1474 |
template<class BiIter, class ST, class SA>
|
| 1475 |
-
|
| 1476 |
-
const sub_match<BiIter>& lhs,
|
| 1477 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1478 |
-
```
|
| 1479 |
-
|
| 1480 |
-
*Returns:* `!(lhs == rhs)`.
|
| 1481 |
-
|
| 1482 |
-
``` cpp
|
| 1483 |
-
template <class BiIter, class ST, class SA>
|
| 1484 |
-
bool operator<(
|
| 1485 |
const sub_match<BiIter>& lhs,
|
| 1486 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1487 |
```
|
| 1488 |
|
| 1489 |
*Returns:*
|
| 1490 |
|
| 1491 |
``` cpp
|
| 1492 |
-
|
|
|
|
|
|
|
|
|
|
| 1493 |
```
|
| 1494 |
|
| 1495 |
-
``` cpp
|
| 1496 |
-
template <class BiIter, class ST, class SA>
|
| 1497 |
-
bool operator>(
|
| 1498 |
-
const sub_match<BiIter>& lhs,
|
| 1499 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1500 |
-
```
|
| 1501 |
-
|
| 1502 |
-
*Returns:* `rhs < lhs`.
|
| 1503 |
-
|
| 1504 |
-
``` cpp
|
| 1505 |
-
template <class BiIter, class ST, class SA>
|
| 1506 |
-
bool operator>=(
|
| 1507 |
-
const sub_match<BiIter>& lhs,
|
| 1508 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1509 |
-
```
|
| 1510 |
-
|
| 1511 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1512 |
-
|
| 1513 |
-
``` cpp
|
| 1514 |
-
template <class BiIter, class ST, class SA>
|
| 1515 |
-
bool operator<=(
|
| 1516 |
-
const sub_match<BiIter>& lhs,
|
| 1517 |
-
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1518 |
-
```
|
| 1519 |
-
|
| 1520 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1521 |
-
|
| 1522 |
-
``` cpp
|
| 1523 |
-
template <class BiIter>
|
| 1524 |
-
bool operator==(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1525 |
-
const sub_match<BiIter>& rhs);
|
| 1526 |
-
```
|
| 1527 |
-
|
| 1528 |
-
*Returns:* `rhs.compare(lhs) == 0`.
|
| 1529 |
-
|
| 1530 |
-
``` cpp
|
| 1531 |
-
template <class BiIter>
|
| 1532 |
-
bool operator!=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1533 |
-
const sub_match<BiIter>& rhs);
|
| 1534 |
-
```
|
| 1535 |
-
|
| 1536 |
-
*Returns:* `!(lhs == rhs)`.
|
| 1537 |
-
|
| 1538 |
-
``` cpp
|
| 1539 |
-
template <class BiIter>
|
| 1540 |
-
bool operator<(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1541 |
-
const sub_match<BiIter>& rhs);
|
| 1542 |
-
```
|
| 1543 |
-
|
| 1544 |
-
*Returns:* `rhs.compare(lhs) > 0`.
|
| 1545 |
-
|
| 1546 |
-
``` cpp
|
| 1547 |
-
template <class BiIter>
|
| 1548 |
-
bool operator>(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1549 |
-
const sub_match<BiIter>& rhs);
|
| 1550 |
-
```
|
| 1551 |
-
|
| 1552 |
-
*Returns:* `rhs < lhs`.
|
| 1553 |
-
|
| 1554 |
-
``` cpp
|
| 1555 |
-
template <class BiIter>
|
| 1556 |
-
bool operator>=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1557 |
-
const sub_match<BiIter>& rhs);
|
| 1558 |
-
```
|
| 1559 |
-
|
| 1560 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1561 |
-
|
| 1562 |
-
``` cpp
|
| 1563 |
-
template <class BiIter>
|
| 1564 |
-
bool operator<=(const typename iterator_traits<BiIter>::value_type* lhs,
|
| 1565 |
-
const sub_match<BiIter>& rhs);
|
| 1566 |
-
```
|
| 1567 |
-
|
| 1568 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1569 |
-
|
| 1570 |
``` cpp
|
| 1571 |
template<class BiIter>
|
| 1572 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 1573 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1574 |
```
|
| 1575 |
|
| 1576 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 1577 |
|
| 1578 |
``` cpp
|
| 1579 |
template<class BiIter>
|
| 1580 |
-
|
| 1581 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1582 |
```
|
| 1583 |
|
| 1584 |
-
*Returns:* `
|
| 1585 |
-
|
| 1586 |
-
``` cpp
|
| 1587 |
-
template <class BiIter>
|
| 1588 |
-
bool operator<(const sub_match<BiIter>& lhs,
|
| 1589 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1590 |
-
```
|
| 1591 |
-
|
| 1592 |
-
*Returns:* `lhs.compare(rhs) < 0`.
|
| 1593 |
-
|
| 1594 |
-
``` cpp
|
| 1595 |
-
template <class BiIter>
|
| 1596 |
-
bool operator>(const sub_match<BiIter>& lhs,
|
| 1597 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1598 |
-
```
|
| 1599 |
-
|
| 1600 |
-
*Returns:* `rhs < lhs`.
|
| 1601 |
-
|
| 1602 |
-
``` cpp
|
| 1603 |
-
template <class BiIter>
|
| 1604 |
-
bool operator>=(const sub_match<BiIter>& lhs,
|
| 1605 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1606 |
-
```
|
| 1607 |
-
|
| 1608 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1609 |
-
|
| 1610 |
-
``` cpp
|
| 1611 |
-
template <class BiIter>
|
| 1612 |
-
bool operator<=(const sub_match<BiIter>& lhs,
|
| 1613 |
-
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1614 |
-
```
|
| 1615 |
-
|
| 1616 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1617 |
-
|
| 1618 |
-
``` cpp
|
| 1619 |
-
template <class BiIter>
|
| 1620 |
-
bool operator==(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1621 |
-
const sub_match<BiIter>& rhs);
|
| 1622 |
-
```
|
| 1623 |
-
|
| 1624 |
-
*Returns:*
|
| 1625 |
-
`rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) == 0`.
|
| 1626 |
-
|
| 1627 |
-
``` cpp
|
| 1628 |
-
template <class BiIter>
|
| 1629 |
-
bool operator!=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1630 |
-
const sub_match<BiIter>& rhs);
|
| 1631 |
-
```
|
| 1632 |
-
|
| 1633 |
-
*Returns:* `!(lhs == rhs)`.
|
| 1634 |
-
|
| 1635 |
-
``` cpp
|
| 1636 |
-
template <class BiIter>
|
| 1637 |
-
bool operator<(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1638 |
-
const sub_match<BiIter>& rhs);
|
| 1639 |
-
```
|
| 1640 |
-
|
| 1641 |
-
*Returns:*
|
| 1642 |
-
`rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) > 0`.
|
| 1643 |
-
|
| 1644 |
-
``` cpp
|
| 1645 |
-
template <class BiIter>
|
| 1646 |
-
bool operator>(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1647 |
-
const sub_match<BiIter>& rhs);
|
| 1648 |
-
```
|
| 1649 |
-
|
| 1650 |
-
*Returns:* `rhs < lhs`.
|
| 1651 |
-
|
| 1652 |
-
``` cpp
|
| 1653 |
-
template <class BiIter>
|
| 1654 |
-
bool operator>=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1655 |
-
const sub_match<BiIter>& rhs);
|
| 1656 |
-
```
|
| 1657 |
-
|
| 1658 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1659 |
-
|
| 1660 |
-
``` cpp
|
| 1661 |
-
template <class BiIter>
|
| 1662 |
-
bool operator<=(const typename iterator_traits<BiIter>::value_type& lhs,
|
| 1663 |
-
const sub_match<BiIter>& rhs);
|
| 1664 |
-
```
|
| 1665 |
-
|
| 1666 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1667 |
|
| 1668 |
``` cpp
|
| 1669 |
template<class BiIter>
|
| 1670 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 1671 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
|
@@ -1674,49 +1255,23 @@ template <class BiIter>
|
|
| 1674 |
*Returns:*
|
| 1675 |
`lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0`.
|
| 1676 |
|
| 1677 |
``` cpp
|
| 1678 |
template<class BiIter>
|
| 1679 |
-
|
| 1680 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 1681 |
-
```
|
| 1682 |
-
|
| 1683 |
-
*Returns:* `!(lhs == rhs)`.
|
| 1684 |
-
|
| 1685 |
-
``` cpp
|
| 1686 |
-
template <class BiIter>
|
| 1687 |
-
bool operator<(const sub_match<BiIter>& lhs,
|
| 1688 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 1689 |
```
|
| 1690 |
|
| 1691 |
*Returns:*
|
| 1692 |
-
`lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) < 0`.
|
| 1693 |
|
| 1694 |
``` cpp
|
| 1695 |
-
|
| 1696 |
-
|
| 1697 |
-
|
|
|
|
| 1698 |
```
|
| 1699 |
|
| 1700 |
-
*Returns:* `rhs < lhs`.
|
| 1701 |
-
|
| 1702 |
-
``` cpp
|
| 1703 |
-
template <class BiIter>
|
| 1704 |
-
bool operator>=(const sub_match<BiIter>& lhs,
|
| 1705 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 1706 |
-
```
|
| 1707 |
-
|
| 1708 |
-
*Returns:* `!(lhs < rhs)`.
|
| 1709 |
-
|
| 1710 |
-
``` cpp
|
| 1711 |
-
template <class BiIter>
|
| 1712 |
-
bool operator<=(const sub_match<BiIter>& lhs,
|
| 1713 |
-
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 1714 |
-
```
|
| 1715 |
-
|
| 1716 |
-
*Returns:* `!(rhs < lhs)`.
|
| 1717 |
-
|
| 1718 |
``` cpp
|
| 1719 |
template<class charT, class ST, class BiIter>
|
| 1720 |
basic_ostream<charT, ST>&
|
| 1721 |
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
|
| 1722 |
```
|
|
@@ -1728,16 +1283,17 @@ template <class charT, class ST, class BiIter>
|
|
| 1728 |
Class template `match_results` denotes a collection of character
|
| 1729 |
sequences representing the result of a regular expression match. Storage
|
| 1730 |
for the collection is allocated and freed as necessary by the member
|
| 1731 |
functions of class template `match_results`.
|
| 1732 |
|
| 1733 |
-
The class template `match_results`
|
| 1734 |
allocator-aware container and of a sequence container (
|
| 1735 |
[[container.requirements.general]], [[sequence.reqmts]]) except that
|
| 1736 |
-
only
|
| 1737 |
-
supported and that the semantics
|
| 1738 |
-
from those required for a
|
|
|
|
| 1739 |
|
| 1740 |
A default-constructed `match_results` object has no fully established
|
| 1741 |
result state. A match result is *ready* when, as a consequence of a
|
| 1742 |
completed regular expression match modifying such an object, its result
|
| 1743 |
state becomes fully established. The effects of calling most member
|
|
@@ -1775,11 +1331,12 @@ namespace std {
|
|
| 1775 |
using char_type =
|
| 1776 |
typename iterator_traits<BidirectionalIterator>::value_type;
|
| 1777 |
using string_type = basic_string<char_type>;
|
| 1778 |
|
| 1779 |
// [re.results.const], construct/copy/destroy
|
| 1780 |
-
|
|
|
|
| 1781 |
match_results(const match_results& m);
|
| 1782 |
match_results(match_results&& m) noexcept;
|
| 1783 |
match_results& operator=(const match_results& m);
|
| 1784 |
match_results& operator=(match_results&& m);
|
| 1785 |
~match_results();
|
|
@@ -1788,11 +1345,11 @@ namespace std {
|
|
| 1788 |
bool ready() const;
|
| 1789 |
|
| 1790 |
// [re.results.size], size
|
| 1791 |
size_type size() const;
|
| 1792 |
size_type max_size() const;
|
| 1793 |
-
bool empty() const;
|
| 1794 |
|
| 1795 |
// [re.results.acc], element access
|
| 1796 |
difference_type length(size_type sub = 0) const;
|
| 1797 |
difference_type position(size_type sub = 0) const;
|
| 1798 |
string_type str(size_type sub = 0) const;
|
|
@@ -1831,57 +1388,40 @@ namespace std {
|
|
| 1831 |
void swap(match_results& that);
|
| 1832 |
};
|
| 1833 |
}
|
| 1834 |
```
|
| 1835 |
|
| 1836 |
-
###
|
| 1837 |
-
|
| 1838 |
-
In all `match_results` constructors, a copy of the `Allocator` argument
|
| 1839 |
-
shall be used for any memory allocation performed by the constructor or
|
| 1840 |
-
member functions during the lifetime of the object.
|
| 1841 |
-
|
| 1842 |
-
``` cpp
|
| 1843 |
-
match_results(const Allocator& a = Allocator());
|
| 1844 |
-
```
|
| 1845 |
-
|
| 1846 |
-
*Effects:* Constructs an object of class `match_results`.
|
| 1847 |
-
|
| 1848 |
-
*Postconditions:* `ready()` returns `false`. `size()` returns `0`.
|
| 1849 |
|
| 1850 |
``` cpp
|
| 1851 |
-
match_results(const
|
| 1852 |
```
|
| 1853 |
|
| 1854 |
-
*
|
| 1855 |
-
`m`.
|
| 1856 |
|
| 1857 |
``` cpp
|
| 1858 |
match_results(match_results&& m) noexcept;
|
| 1859 |
```
|
| 1860 |
|
| 1861 |
-
*Effects:*
|
| 1862 |
-
satisfying the same postconditions as Table [[tab:re:results:assign]].
|
| 1863 |
-
Additionally, the stored `Allocator` value is move constructed from
|
| 1864 |
`m.get_allocator()`.
|
| 1865 |
|
| 1866 |
-
*
|
| 1867 |
|
| 1868 |
``` cpp
|
| 1869 |
match_results& operator=(const match_results& m);
|
| 1870 |
```
|
| 1871 |
|
| 1872 |
-
*
|
| 1873 |
-
are indicated in Table [[tab:re:results:assign]].
|
| 1874 |
|
| 1875 |
``` cpp
|
| 1876 |
match_results& operator=(match_results&& m);
|
| 1877 |
```
|
| 1878 |
|
| 1879 |
-
*
|
| 1880 |
-
function are indicated in Table [[tab:re:results:assign]].
|
| 1881 |
|
| 1882 |
-
**Table: `match_results` assignment operator effects** <a id="
|
| 1883 |
|
| 1884 |
| Element | Value |
|
| 1885 |
| ------------- | ----------------------------------------------- |
|
| 1886 |
| `ready()` | `m.ready()` |
|
| 1887 |
| `size()` | `m.size()` |
|
|
@@ -1891,20 +1431,20 @@ function are indicated in Table [[tab:re:results:assign]].
|
|
| 1891 |
| `(*this)[n]` | `m[n]` for all integers `n < m.size()` |
|
| 1892 |
| `length(n)` | `m.length(n)` for all integers `n < m.size()` |
|
| 1893 |
| `position(n)` | `m.position(n)` for all integers `n < m.size()` |
|
| 1894 |
|
| 1895 |
|
| 1896 |
-
###
|
| 1897 |
|
| 1898 |
``` cpp
|
| 1899 |
bool ready() const;
|
| 1900 |
```
|
| 1901 |
|
| 1902 |
*Returns:* `true` if `*this` has a fully established result state,
|
| 1903 |
otherwise `false`.
|
| 1904 |
|
| 1905 |
-
###
|
| 1906 |
|
| 1907 |
``` cpp
|
| 1908 |
size_type size() const;
|
| 1909 |
```
|
| 1910 |
|
|
@@ -1912,58 +1452,58 @@ size_type size() const;
|
|
| 1912 |
expression that was matched if `*this` represents the result of a
|
| 1913 |
successful match. Otherwise returns `0`.
|
| 1914 |
|
| 1915 |
[*Note 1*: The state of a `match_results` object can be modified only
|
| 1916 |
by passing that object to `regex_match` or `regex_search`.
|
| 1917 |
-
|
| 1918 |
-
those algorithms on their `match_results` arguments. — *end note*]
|
| 1919 |
|
| 1920 |
``` cpp
|
| 1921 |
size_type max_size() const;
|
| 1922 |
```
|
| 1923 |
|
| 1924 |
*Returns:* The maximum number of `sub_match` elements that can be stored
|
| 1925 |
in `*this`.
|
| 1926 |
|
| 1927 |
``` cpp
|
| 1928 |
-
bool empty() const;
|
| 1929 |
```
|
| 1930 |
|
| 1931 |
*Returns:* `size() == 0`.
|
| 1932 |
|
| 1933 |
-
###
|
| 1934 |
|
| 1935 |
``` cpp
|
| 1936 |
difference_type length(size_type sub = 0) const;
|
| 1937 |
```
|
| 1938 |
|
| 1939 |
-
*
|
| 1940 |
|
| 1941 |
*Returns:* `(*this)[sub].length()`.
|
| 1942 |
|
| 1943 |
``` cpp
|
| 1944 |
difference_type position(size_type sub = 0) const;
|
| 1945 |
```
|
| 1946 |
|
| 1947 |
-
*
|
| 1948 |
|
| 1949 |
*Returns:* The distance from the start of the target sequence to
|
| 1950 |
`(*this)[sub].first`.
|
| 1951 |
|
| 1952 |
``` cpp
|
| 1953 |
string_type str(size_type sub = 0) const;
|
| 1954 |
```
|
| 1955 |
|
| 1956 |
-
*
|
| 1957 |
|
| 1958 |
*Returns:* `string_type((*this)[sub])`.
|
| 1959 |
|
| 1960 |
``` cpp
|
| 1961 |
const_reference operator[](size_type n) const;
|
| 1962 |
```
|
| 1963 |
|
| 1964 |
-
*
|
| 1965 |
|
| 1966 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1967 |
character sequence that matched marked sub-expression `n`. If `n == 0`
|
| 1968 |
then returns a reference to a `sub_match` object representing the
|
| 1969 |
character sequence that matched the whole regular expression. If
|
|
@@ -1972,21 +1512,21 @@ unmatched sub-expression.
|
|
| 1972 |
|
| 1973 |
``` cpp
|
| 1974 |
const_reference prefix() const;
|
| 1975 |
```
|
| 1976 |
|
| 1977 |
-
*
|
| 1978 |
|
| 1979 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1980 |
character sequence from the start of the string being matched/searched
|
| 1981 |
to the start of the match found.
|
| 1982 |
|
| 1983 |
``` cpp
|
| 1984 |
const_reference suffix() const;
|
| 1985 |
```
|
| 1986 |
|
| 1987 |
-
*
|
| 1988 |
|
| 1989 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1990 |
character sequence from the end of the match found to the end of the
|
| 1991 |
string being matched/searched.
|
| 1992 |
|
|
@@ -2004,22 +1544,22 @@ const_iterator cend() const;
|
|
| 2004 |
```
|
| 2005 |
|
| 2006 |
*Returns:* A terminating iterator that enumerates over all the
|
| 2007 |
sub-expressions stored in `*this`.
|
| 2008 |
|
| 2009 |
-
###
|
| 2010 |
|
| 2011 |
``` cpp
|
| 2012 |
template<class OutputIter>
|
| 2013 |
OutputIter format(
|
| 2014 |
OutputIter out,
|
| 2015 |
const char_type* fmt_first, const char_type* fmt_last,
|
| 2016 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 2017 |
```
|
| 2018 |
|
| 2019 |
-
*
|
| 2020 |
-
requirements for
|
| 2021 |
|
| 2022 |
*Effects:* Copies the character sequence \[`fmt_first`, `fmt_last`) to
|
| 2023 |
OutputIter `out`. Replaces each format specifier or escape sequence in
|
| 2024 |
the copied range with either the character(s) it represents or the
|
| 2025 |
sequence of characters within `*this` to which it refers. The bitmasks
|
|
@@ -2047,11 +1587,11 @@ template <class ST, class SA>
|
|
| 2047 |
basic_string<char_type, ST, SA> format(
|
| 2048 |
const basic_string<char_type, ST, SA>& fmt,
|
| 2049 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 2050 |
```
|
| 2051 |
|
| 2052 |
-
*
|
| 2053 |
|
| 2054 |
*Effects:* Constructs an empty string `result` of type
|
| 2055 |
`basic_string<char_type, ST, SA>` and calls:
|
| 2056 |
|
| 2057 |
``` cpp
|
|
@@ -2064,42 +1604,42 @@ format(back_inserter(result), fmt, flags);
|
|
| 2064 |
string_type format(
|
| 2065 |
const char_type* fmt,
|
| 2066 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 2067 |
```
|
| 2068 |
|
| 2069 |
-
*
|
| 2070 |
|
| 2071 |
*Effects:* Constructs an empty string `result` of type `string_type` and
|
| 2072 |
calls:
|
| 2073 |
|
| 2074 |
``` cpp
|
| 2075 |
format(back_inserter(result), fmt, fmt + char_traits<char_type>::length(fmt), flags);
|
| 2076 |
```
|
| 2077 |
|
| 2078 |
*Returns:* `result`.
|
| 2079 |
|
| 2080 |
-
###
|
| 2081 |
|
| 2082 |
``` cpp
|
| 2083 |
allocator_type get_allocator() const;
|
| 2084 |
```
|
| 2085 |
|
| 2086 |
*Returns:* A copy of the Allocator that was passed to the object’s
|
| 2087 |
constructor or, if that allocator has been replaced, a copy of the most
|
| 2088 |
recent replacement.
|
| 2089 |
|
| 2090 |
-
###
|
| 2091 |
|
| 2092 |
``` cpp
|
| 2093 |
void swap(match_results& that);
|
| 2094 |
```
|
| 2095 |
|
| 2096 |
*Effects:* Swaps the contents of the two sequences.
|
| 2097 |
|
| 2098 |
-
*
|
| 2099 |
-
|
| 2100 |
-
|
| 2101 |
|
| 2102 |
*Complexity:* Constant time.
|
| 2103 |
|
| 2104 |
``` cpp
|
| 2105 |
template<class BidirectionalIterator, class Allocator>
|
|
@@ -2107,11 +1647,11 @@ template <class BidirectionalIterator, class Allocator>
|
|
| 2107 |
match_results<BidirectionalIterator, Allocator>& m2);
|
| 2108 |
```
|
| 2109 |
|
| 2110 |
*Effects:* As if by `m1.swap(m2)`.
|
| 2111 |
|
| 2112 |
-
###
|
| 2113 |
|
| 2114 |
``` cpp
|
| 2115 |
template<class BidirectionalIterator, class Allocator>
|
| 2116 |
bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 2117 |
const match_results<BidirectionalIterator, Allocator>& m2);
|
|
@@ -2128,27 +1668,19 @@ returns `true` only if:
|
|
| 2128 |
- `m1.size() == m2.size() && equal(m1.begin(), m1.end(), m2.begin())`,
|
| 2129 |
and
|
| 2130 |
- `m1.suffix() == m2.suffix()`.
|
| 2131 |
|
| 2132 |
[*Note 1*: The algorithm `equal` is defined in
|
| 2133 |
-
|
| 2134 |
-
|
| 2135 |
-
``` cpp
|
| 2136 |
-
template <class BidirectionalIterator, class Allocator>
|
| 2137 |
-
bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 2138 |
-
const match_results<BidirectionalIterator, Allocator>& m2);
|
| 2139 |
-
```
|
| 2140 |
-
|
| 2141 |
-
*Returns:* `!(m1 == m2)`.
|
| 2142 |
|
| 2143 |
## Regular expression algorithms <a id="re.alg">[[re.alg]]</a>
|
| 2144 |
|
| 2145 |
### Exceptions <a id="re.except">[[re.except]]</a>
|
| 2146 |
|
| 2147 |
-
The algorithms described in
|
| 2148 |
-
type `regex_error`. If such an exception `e` is thrown, `e.code()`
|
| 2149 |
-
return either `regex_constants::error_complexity` or
|
| 2150 |
`regex_constants::error_stack`.
|
| 2151 |
|
| 2152 |
### `regex_match` <a id="re.alg.match">[[re.alg.match]]</a>
|
| 2153 |
|
| 2154 |
``` cpp
|
|
@@ -2157,12 +1689,12 @@ template <class BidirectionalIterator, class Allocator, class charT, class trait
|
|
| 2157 |
match_results<BidirectionalIterator, Allocator>& m,
|
| 2158 |
const basic_regex<charT, traits>& e,
|
| 2159 |
regex_constants::match_flag_type flags = regex_constants::match_default);
|
| 2160 |
```
|
| 2161 |
|
| 2162 |
-
*
|
| 2163 |
-
requirements
|
| 2164 |
|
| 2165 |
*Effects:* Determines whether there is a match between the regular
|
| 2166 |
expression `e`, and all of the character sequence \[`first`, `last`).
|
| 2167 |
The parameter `flags` is used to control how the expression is matched
|
| 2168 |
against the character sequence. When determining if there is a match,
|
|
@@ -2180,16 +1712,16 @@ regex_search("GetValues", m, re); // returns true, and m[0] contains "Get"
|
|
| 2180 |
regex_match ("GetValues", m, re); // returns false
|
| 2181 |
```
|
| 2182 |
|
| 2183 |
— *end example*]
|
| 2184 |
|
| 2185 |
-
*
|
| 2186 |
-
|
| 2187 |
-
|
| 2188 |
-
|
| 2189 |
|
| 2190 |
-
**Table: Effects of `regex_match` algorithm** <a id="
|
| 2191 |
|
| 2192 |
| Element | Value |
|
| 2193 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 2194 |
| `m.size()` | `1 + e.mark_count()` |
|
| 2195 |
| `m.empty()` | `false` |
|
|
@@ -2266,25 +1798,25 @@ template <class BidirectionalIterator, class Allocator, class charT, class trait
|
|
| 2266 |
match_results<BidirectionalIterator, Allocator>& m,
|
| 2267 |
const basic_regex<charT, traits>& e,
|
| 2268 |
regex_constants::match_flag_type flags = regex_constants::match_default);
|
| 2269 |
```
|
| 2270 |
|
| 2271 |
-
*
|
| 2272 |
-
|
| 2273 |
|
| 2274 |
*Effects:* Determines whether there is some sub-sequence within
|
| 2275 |
\[`first`, `last`) that matches the regular expression `e`. The
|
| 2276 |
parameter `flags` is used to control how the expression is matched
|
| 2277 |
against the character sequence. Returns `true` if such a sequence
|
| 2278 |
exists, `false` otherwise.
|
| 2279 |
|
| 2280 |
-
*
|
| 2281 |
-
|
| 2282 |
-
|
| 2283 |
-
|
| 2284 |
|
| 2285 |
-
**Table: Effects of `regex_search` algorithm** <a id="
|
| 2286 |
|
| 2287 |
| Element | Value |
|
| 2288 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 2289 |
| `m.size()` | `1 + e.mark_count()` |
|
| 2290 |
| `m.empty()` | `false` |
|
|
@@ -2513,11 +2045,10 @@ namespace std {
|
|
| 2513 |
const regex_type&&,
|
| 2514 |
regex_constants::match_flag_type = regex_constants::match_default) = delete;
|
| 2515 |
regex_iterator(const regex_iterator&);
|
| 2516 |
regex_iterator& operator=(const regex_iterator&);
|
| 2517 |
bool operator==(const regex_iterator&) const;
|
| 2518 |
-
bool operator!=(const regex_iterator&) const;
|
| 2519 |
const value_type& operator*() const;
|
| 2520 |
const value_type* operator->() const;
|
| 2521 |
regex_iterator& operator++();
|
| 2522 |
regex_iterator operator++(int);
|
| 2523 |
|
|
@@ -2537,11 +2068,11 @@ iterator holds a *zero-length match* if `match[0].matched == true` and
|
|
| 2537 |
|
| 2538 |
[*Note 1*: For example, this can occur when the part of the regular
|
| 2539 |
expression that matched consists only of an assertion (such as `'^'`,
|
| 2540 |
`'$'`, `'\b'`, `'\B'`). — *end note*]
|
| 2541 |
|
| 2542 |
-
####
|
| 2543 |
|
| 2544 |
``` cpp
|
| 2545 |
regex_iterator();
|
| 2546 |
```
|
| 2547 |
|
|
@@ -2552,15 +2083,15 @@ regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
|
|
| 2552 |
const regex_type& re,
|
| 2553 |
regex_constants::match_flag_type m = regex_constants::match_default);
|
| 2554 |
```
|
| 2555 |
|
| 2556 |
*Effects:* Initializes `begin` and `end` to `a` and `b`, respectively,
|
| 2557 |
-
sets `pregex` to `
|
| 2558 |
`regex_search(begin, end, match, *pregex, flags)`. If this call returns
|
| 2559 |
`false` the constructor sets `*this` to the end-of-sequence iterator.
|
| 2560 |
|
| 2561 |
-
####
|
| 2562 |
|
| 2563 |
``` cpp
|
| 2564 |
bool operator==(const regex_iterator& right) const;
|
| 2565 |
```
|
| 2566 |
|
|
@@ -2573,17 +2104,11 @@ iterators or if the following conditions all hold:
|
|
| 2573 |
- `flags == right.flags`, and
|
| 2574 |
- `match[0] == right.match[0]`;
|
| 2575 |
|
| 2576 |
otherwise `false`.
|
| 2577 |
|
| 2578 |
-
|
| 2579 |
-
bool operator!=(const regex_iterator& right) const;
|
| 2580 |
-
```
|
| 2581 |
-
|
| 2582 |
-
*Returns:* `!(*this == right)`.
|
| 2583 |
-
|
| 2584 |
-
#### `regex_iterator` indirection <a id="re.regiter.deref">[[re.regiter.deref]]</a>
|
| 2585 |
|
| 2586 |
``` cpp
|
| 2587 |
const value_type& operator*() const;
|
| 2588 |
```
|
| 2589 |
|
|
@@ -2591,13 +2116,13 @@ const value_type& operator*() const;
|
|
| 2591 |
|
| 2592 |
``` cpp
|
| 2593 |
const value_type* operator->() const;
|
| 2594 |
```
|
| 2595 |
|
| 2596 |
-
*Returns:* `
|
| 2597 |
|
| 2598 |
-
####
|
| 2599 |
|
| 2600 |
``` cpp
|
| 2601 |
regex_iterator& operator++();
|
| 2602 |
```
|
| 2603 |
|
|
@@ -2639,11 +2164,11 @@ offset from the sequence passed in the call to
|
|
| 2639 |
`regex_search`. — *end note*]
|
| 2640 |
|
| 2641 |
It is unspecified how the implementation makes these adjustments.
|
| 2642 |
|
| 2643 |
[*Note 2*: This means that a compiler may call an
|
| 2644 |
-
implementation-specific search function, in which case a
|
| 2645 |
specialization of `regex_search` will not be called. — *end note*]
|
| 2646 |
|
| 2647 |
``` cpp
|
| 2648 |
regex_iterator operator++(int);
|
| 2649 |
```
|
|
@@ -2759,11 +2284,10 @@ namespace std {
|
|
| 2759 |
regex_constants::match_flag_type m =
|
| 2760 |
regex_constants::match_default) = delete;
|
| 2761 |
regex_token_iterator(const regex_token_iterator&);
|
| 2762 |
regex_token_iterator& operator=(const regex_token_iterator&);
|
| 2763 |
bool operator==(const regex_token_iterator&) const;
|
| 2764 |
-
bool operator!=(const regex_token_iterator&) const;
|
| 2765 |
const value_type& operator*() const;
|
| 2766 |
const value_type* operator->() const;
|
| 2767 |
regex_token_iterator& operator++();
|
| 2768 |
regex_token_iterator operator++(int);
|
| 2769 |
|
|
@@ -2786,16 +2310,16 @@ suffix iterator the member `result` holds a pointer to the data member
|
|
| 2786 |
`suffix.first` points to the beginning of the final sequence, and
|
| 2787 |
`suffix.second` points to the end of the final sequence.
|
| 2788 |
|
| 2789 |
[*Note 1*: For a suffix iterator, data member `suffix.first` is the
|
| 2790 |
same as the end of the last match found, and `suffix.second` is the same
|
| 2791 |
-
as the end of the target sequence — *end note*]
|
| 2792 |
|
| 2793 |
The *current match* is `(*position).prefix()` if `subs[N] == -1`, or
|
| 2794 |
`(*position)[subs[N]]` for any other value of `subs[N]`.
|
| 2795 |
|
| 2796 |
-
####
|
| 2797 |
|
| 2798 |
``` cpp
|
| 2799 |
regex_token_iterator();
|
| 2800 |
```
|
| 2801 |
|
|
@@ -2822,30 +2346,28 @@ template <size_t N>
|
|
| 2822 |
const regex_type& re,
|
| 2823 |
const int (&submatches)[N],
|
| 2824 |
regex_constants::match_flag_type m = regex_constants::match_default);
|
| 2825 |
```
|
| 2826 |
|
| 2827 |
-
*
|
| 2828 |
`>= -1`.
|
| 2829 |
|
| 2830 |
*Effects:* The first constructor initializes the member `subs` to hold
|
| 2831 |
-
the single value `submatch`. The second
|
| 2832 |
-
member `subs` to hold a copy of the
|
| 2833 |
-
|
| 2834 |
-
|
| 2835 |
-
\[`submatches.begin()`, `submatches.end()`) and \[`&submatches`,
|
| 2836 |
-
`&submatches + N`), respectively.
|
| 2837 |
|
| 2838 |
Each constructor then sets `N` to 0, and `position` to
|
| 2839 |
`position_iterator(a, b, re, m)`. If `position` is not an
|
| 2840 |
end-of-sequence iterator the constructor sets `result` to the address of
|
| 2841 |
the current match. Otherwise if any of the values stored in `subs` is
|
| 2842 |
equal to -1 the constructor sets `*this` to a suffix iterator that
|
| 2843 |
points to the range \[`a`, `b`), otherwise the constructor sets `*this`
|
| 2844 |
to an end-of-sequence iterator.
|
| 2845 |
|
| 2846 |
-
####
|
| 2847 |
|
| 2848 |
``` cpp
|
| 2849 |
bool operator==(const regex_token_iterator& right) const;
|
| 2850 |
```
|
| 2851 |
|
|
@@ -2854,17 +2376,11 @@ iterators, or if `*this` and `right` are both suffix iterators and
|
|
| 2854 |
`suffix == right.suffix`; otherwise returns `false` if `*this` or
|
| 2855 |
`right` is an end-of-sequence iterator or a suffix iterator. Otherwise
|
| 2856 |
returns `true` if `position == right.position`, `N == right.N`, and
|
| 2857 |
`subs == right.subs`. Otherwise returns `false`.
|
| 2858 |
|
| 2859 |
-
|
| 2860 |
-
bool operator!=(const regex_token_iterator& right) const;
|
| 2861 |
-
```
|
| 2862 |
-
|
| 2863 |
-
*Returns:* `!(*this == right)`.
|
| 2864 |
-
|
| 2865 |
-
#### `regex_token_iterator` indirection <a id="re.tokiter.deref">[[re.tokiter.deref]]</a>
|
| 2866 |
|
| 2867 |
``` cpp
|
| 2868 |
const value_type& operator*() const;
|
| 2869 |
```
|
| 2870 |
|
|
@@ -2874,11 +2390,11 @@ const value_type& operator*() const;
|
|
| 2874 |
const value_type* operator->() const;
|
| 2875 |
```
|
| 2876 |
|
| 2877 |
*Returns:* `result`.
|
| 2878 |
|
| 2879 |
-
####
|
| 2880 |
|
| 2881 |
``` cpp
|
| 2882 |
regex_token_iterator& operator++();
|
| 2883 |
```
|
| 2884 |
|
|
@@ -2927,58 +2443,57 @@ including the formatted string input functions. Instead they shall call
|
|
| 2927 |
the appropriate traits member function to achieve the required effect.
|
| 2928 |
|
| 2929 |
The following productions within the ECMAScript grammar are modified as
|
| 2930 |
follows:
|
| 2931 |
|
| 2932 |
-
```
|
| 2933 |
ClassAtom::
|
| 2934 |
-
-
|
| 2935 |
ClassAtomNoDash
|
| 2936 |
ClassAtomExClass
|
| 2937 |
ClassAtomCollatingElement
|
| 2938 |
ClassAtomEquivalence
|
| 2939 |
|
| 2940 |
IdentityEscape::
|
| 2941 |
-
SourceCharacter but not c
|
| 2942 |
```
|
| 2943 |
|
| 2944 |
The following new productions are then added:
|
| 2945 |
|
| 2946 |
-
```
|
| 2947 |
ClassAtomExClass::
|
| 2948 |
-
[: ClassName :]
|
| 2949 |
|
| 2950 |
ClassAtomCollatingElement::
|
| 2951 |
-
[. ClassName .]
|
| 2952 |
|
| 2953 |
ClassAtomEquivalence::
|
| 2954 |
-
[= ClassName =]
|
| 2955 |
|
| 2956 |
ClassName::
|
| 2957 |
ClassNameCharacter
|
| 2958 |
ClassNameCharacter ClassName
|
| 2959 |
|
| 2960 |
ClassNameCharacter::
|
| 2961 |
-
SourceCharacter but not one of
|
| 2962 |
```
|
| 2963 |
|
| 2964 |
-
The productions
|
| 2965 |
-
`ClassAtomEquivalence` provide functionality equivalent to that of the
|
| 2966 |
same features in regular expressions in POSIX.
|
| 2967 |
|
| 2968 |
The regular expression grammar may be modified by any
|
| 2969 |
`regex_constants::syntax_option_type` flags specified when constructing
|
| 2970 |
an object of type specialization of `basic_regex` according to the rules
|
| 2971 |
-
in
|
| 2972 |
|
| 2973 |
-
A
|
| 2974 |
-
|
| 2975 |
-
recognized as valid
|
| 2976 |
-
|
| 2977 |
-
`
|
| 2978 |
-
`
|
| 2979 |
-
|
| 2980 |
|
| 2981 |
``` cpp
|
| 2982 |
\d and [[:digit:]]
|
| 2983 |
|
| 2984 |
\D and [^[:digit:]]
|
|
@@ -2990,22 +2505,22 @@ following expressions shall be equivalent:
|
|
| 2990 |
\w and [_[:alnum:]]
|
| 2991 |
|
| 2992 |
\W and [^_[:alnum:]]
|
| 2993 |
```
|
| 2994 |
|
| 2995 |
-
A
|
| 2996 |
-
|
| 2997 |
-
|
| 2998 |
|
| 2999 |
The results from multiple calls to `traits_inst.lookup_classname` can be
|
| 3000 |
-
bitwise
|
| 3001 |
|
| 3002 |
-
A
|
| 3003 |
-
|
| 3004 |
-
|
| 3005 |
-
the
|
| 3006 |
-
|
| 3007 |
|
| 3008 |
When the sequence of characters being transformed to a finite state
|
| 3009 |
machine contains an invalid class name the translator shall throw an
|
| 3010 |
exception object of type `regex_error`.
|
| 3011 |
|
|
@@ -3020,13 +2535,13 @@ Where the regular expression grammar requires the conversion of a
|
|
| 3020 |
sequence of characters to an integral value, this is accomplished by
|
| 3021 |
calling `traits_inst.value`.
|
| 3022 |
|
| 3023 |
The behavior of the internal finite state machine representation when
|
| 3024 |
used to match a sequence of characters is as described in ECMA-262. The
|
| 3025 |
-
behavior is modified according to any match_flag_type flags
|
| 3026 |
-
[[re.matchflag]]
|
| 3027 |
-
one of the regular expression algorithms
|
| 3028 |
also localized by interaction with the traits class template parameter
|
| 3029 |
as follows:
|
| 3030 |
|
| 3031 |
- During matching of a regular expression finite state machine against a
|
| 3032 |
sequence of characters, two characters `c` and `d` are compared using
|
|
@@ -3039,24 +2554,24 @@ as follows:
|
|
| 3039 |
`traits_inst.translate(c) == traits_inst.translate(d)`;
|
| 3040 |
- otherwise, the two characters are equal if `c == d`.
|
| 3041 |
- During matching of a regular expression finite state machine against a
|
| 3042 |
sequence of characters, comparison of a collating element range
|
| 3043 |
`c1-c2` against a character `c` is conducted as follows: if
|
| 3044 |
-
`flags() & regex_constants::collate` is false then the character `c`
|
| 3045 |
is matched if `c1
|
| 3046 |
<= c && c <= c2`, otherwise `c` is matched in accordance with the
|
| 3047 |
following algorithm:
|
| 3048 |
``` cpp
|
| 3049 |
string_type str1 = string_type(1,
|
| 3050 |
flags() & icase ?
|
| 3051 |
-
traits_inst.translate_nocase(c1) : traits_inst.translate(c1);
|
| 3052 |
string_type str2 = string_type(1,
|
| 3053 |
flags() & icase ?
|
| 3054 |
-
traits_inst.translate_nocase(c2) : traits_inst.translate(c2);
|
| 3055 |
string_type str = string_type(1,
|
| 3056 |
flags() & icase ?
|
| 3057 |
-
traits_inst.translate_nocase(c) : traits_inst.translate(c);
|
| 3058 |
return traits_inst.transform(str1.begin(), str1.end())
|
| 3059 |
<= traits_inst.transform(str.begin(), str.end())
|
| 3060 |
&& traits_inst.transform(str.begin(), str.end())
|
| 3061 |
<= traits_inst.transform(str2.begin(), str2.end());
|
| 3062 |
```
|
|
@@ -3070,10 +2585,12 @@ as follows:
|
|
| 3070 |
sequence of characters, a character `c` is a member of a character
|
| 3071 |
class designated by an iterator range \[`first`, `last`) if
|
| 3072 |
`traits_inst.isctype(c, traits_inst.lookup_classname(first, last, flags() & icase))`
|
| 3073 |
is `true`.
|
| 3074 |
|
|
|
|
|
|
|
| 3075 |
<!-- Link reference definitions -->
|
| 3076 |
[algorithms]: algorithms.md#algorithms
|
| 3077 |
[bidirectional.iterators]: iterators.md#bidirectional.iterators
|
| 3078 |
[bitmask.types]: library.md#bitmask.types
|
| 3079 |
[container.requirements.general]: containers.md#container.requirements.general
|
|
@@ -3095,14 +2612,12 @@ as follows:
|
|
| 3095 |
[re.grammar]: #re.grammar
|
| 3096 |
[re.iter]: #re.iter
|
| 3097 |
[re.matchflag]: #re.matchflag
|
| 3098 |
[re.regex]: #re.regex
|
| 3099 |
[re.regex.assign]: #re.regex.assign
|
| 3100 |
-
[re.regex.const]: #re.regex.const
|
| 3101 |
[re.regex.construct]: #re.regex.construct
|
| 3102 |
[re.regex.locale]: #re.regex.locale
|
| 3103 |
-
[re.regex.nmswap]: #re.regex.nmswap
|
| 3104 |
[re.regex.nonmemb]: #re.regex.nonmemb
|
| 3105 |
[re.regex.operations]: #re.regex.operations
|
| 3106 |
[re.regex.swap]: #re.regex.swap
|
| 3107 |
[re.regiter]: #re.regiter
|
| 3108 |
[re.regiter.cnstr]: #re.regiter.cnstr
|
|
@@ -3120,27 +2635,20 @@ as follows:
|
|
| 3120 |
[re.results.state]: #re.results.state
|
| 3121 |
[re.results.swap]: #re.results.swap
|
| 3122 |
[re.submatch]: #re.submatch
|
| 3123 |
[re.submatch.members]: #re.submatch.members
|
| 3124 |
[re.submatch.op]: #re.submatch.op
|
|
|
|
| 3125 |
[re.syn]: #re.syn
|
| 3126 |
[re.synopt]: #re.synopt
|
| 3127 |
[re.tokiter]: #re.tokiter
|
| 3128 |
[re.tokiter.cnstr]: #re.tokiter.cnstr
|
| 3129 |
[re.tokiter.comp]: #re.tokiter.comp
|
| 3130 |
[re.tokiter.deref]: #re.tokiter.deref
|
| 3131 |
[re.tokiter.incr]: #re.tokiter.incr
|
| 3132 |
[re.traits]: #re.traits
|
|
|
|
| 3133 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 3134 |
[strings.general]: strings.md#strings.general
|
| 3135 |
-
[tab:re.lib.summary]: #tab:re.lib.summary
|
| 3136 |
-
[tab:re.traits.classnames]: #tab:re.traits.classnames
|
| 3137 |
-
[tab:re:RegexpTraits]: #tab:re:RegexpTraits
|
| 3138 |
-
[tab:re:alg:match]: #tab:re:alg:match
|
| 3139 |
-
[tab:re:alg:search]: #tab:re:alg:search
|
| 3140 |
-
[tab:re:errortype]: #tab:re:errortype
|
| 3141 |
-
[tab:re:matchflag]: #tab:re:matchflag
|
| 3142 |
-
[tab:re:results:assign]: #tab:re:results:assign
|
| 3143 |
-
[tab:re:syntaxoption]: #tab:re:syntaxoption
|
| 3144 |
|
| 3145 |
[^1]: For example, if the parameter `icase` is `true` then `[[:lower:]]`
|
| 3146 |
is the same as `[[:alpha:]]`.
|
|
|
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
operations involving regular expression matching and searching.
|
| 7 |
|
| 8 |
The following subclauses describe a basic regular expression class
|
| 9 |
+
template and its traits that can handle char-like [[strings.general]]
|
| 10 |
template arguments, two specializations of this class template that
|
| 11 |
handle sequences of `char` and `wchar_t`, a class template that holds
|
| 12 |
the result of a regular expression match, a series of algorithms that
|
| 13 |
allow a character sequence to be operated upon by a regular expression,
|
| 14 |
and two iterator types for enumerating regular expression matches, as
|
| 15 |
+
summarized in [[re.summary]].
|
| 16 |
|
| 17 |
+
**Table: Regular expressions library summary** <a id="re.summary">[re.summary]</a>
|
| 18 |
|
| 19 |
| Subclause | | Header |
|
| 20 |
| --------------- | --------------------------- | --------- |
|
| 21 |
| [[re.def]] | Definitions | |
|
| 22 |
| [[re.req]] | Requirements | |
|
| 23 |
+
| [[re.const]] | Constants | `<regex>` |
|
| 24 |
| [[re.badexp]] | Exception type | |
|
| 25 |
| [[re.traits]] | Traits | |
|
| 26 |
+
| [[re.regex]] | Regular expression template | |
|
| 27 |
| [[re.submatch]] | Submatches | |
|
| 28 |
| [[re.results]] | Match results | |
|
| 29 |
| [[re.alg]] | Algorithms | |
|
| 30 |
| [[re.iter]] | Iterators | |
|
| 31 |
| [[re.grammar]] | Grammar | |
|
|
|
|
| 74 |
## Requirements <a id="re.req">[[re.req]]</a>
|
| 75 |
|
| 76 |
This subclause defines requirements on classes representing regular
|
| 77 |
expression traits.
|
| 78 |
|
| 79 |
+
[*Note 1*: The class template `regex_traits`, defined in [[re.traits]],
|
| 80 |
+
meets these requirements. — *end note*]
|
| 81 |
|
| 82 |
+
The class template `basic_regex`, defined in [[re.regex]], needs a set
|
| 83 |
+
of related types and functions to complete the definition of its
|
| 84 |
semantics. These types and functions are provided as a set of member
|
| 85 |
*typedef-name*s and functions in the template parameter `traits` used by
|
| 86 |
the `basic_regex` class template. This subclause defines the semantics
|
| 87 |
of these members.
|
| 88 |
|
| 89 |
To specialize class template `basic_regex` for a character container
|
| 90 |
`CharT` and its related regular expression traits class `Traits`, use
|
| 91 |
`basic_regex<CharT, Traits>`.
|
| 92 |
|
| 93 |
+
In [[re.req]] `X` denotes a traits class defining types and functions
|
| 94 |
+
for the character container type `charT`; `u` is an object of type `X`;
|
| 95 |
+
`v` is an object of type `const
|
| 96 |
X`; `p` is a value of type `const charT*`; `I1` and `I2` are input
|
| 97 |
+
iterators [[input.iterators]]; `F1` and `F2` are forward iterators
|
| 98 |
+
[[forward.iterators]]; `c` is a value of type `const charT`; `s` is an
|
| 99 |
object of type `X::string_type`; `cs` is an object of type
|
| 100 |
`const X::string_type`; `b` is a value of type `bool`; `I` is a value of
|
| 101 |
type `int`; `cl` is an object of type `X::char_class_type`, and `loc` is
|
| 102 |
an object of type `X::locale_type`.
|
| 103 |
|
| 104 |
[*Note 2*: The value of *I* will only be 8, 10, or 16. — *end note*]
|
| 105 |
|
| 106 |
+
[*Note 3*: Class template `regex_traits` meets the requirements for a
|
| 107 |
+
regular expression traits class when it is specialized for `char` or
|
| 108 |
`wchar_t`. This class template is described in the header `<regex>`, and
|
| 109 |
+
is described in [[re.traits]]. — *end note*]
|
| 110 |
|
| 111 |
## Header `<regex>` synopsis <a id="re.syn">[[re.syn]]</a>
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
+
#include <compare> // see [compare.syn]
|
| 115 |
+
#include <initializer_list> // see [initializer.list.syn]
|
| 116 |
|
| 117 |
namespace std {
|
| 118 |
// [re.const], regex constants
|
| 119 |
namespace regex_constants {
|
| 120 |
using syntax_option_type = T1;
|
|
|
|
| 149 |
|
| 150 |
// [re.submatch.op], sub_match non-member operators
|
| 151 |
template<class BiIter>
|
| 152 |
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 153 |
template<class BiIter>
|
| 154 |
+
auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
template<class BiIter, class ST, class SA>
|
| 157 |
bool operator==(
|
| 158 |
const sub_match<BiIter>& lhs,
|
| 159 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 160 |
template<class BiIter, class ST, class SA>
|
| 161 |
+
auto operator<=>(
|
| 162 |
const sub_match<BiIter>& lhs,
|
| 163 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
template<class BiIter>
|
| 166 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 167 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 168 |
template<class BiIter>
|
| 169 |
+
auto operator<=>(const sub_match<BiIter>& lhs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
template<class BiIter>
|
| 173 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 174 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 175 |
template<class BiIter>
|
| 176 |
+
auto operator<=>(const sub_match<BiIter>& lhs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 178 |
|
| 179 |
template<class charT, class ST, class BiIter>
|
| 180 |
basic_ostream<charT, ST>&
|
| 181 |
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
|
|
|
|
| 192 |
|
| 193 |
// match_results comparisons
|
| 194 |
template<class BidirectionalIterator, class Allocator>
|
| 195 |
bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 196 |
const match_results<BidirectionalIterator, Allocator>& m2);
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
// [re.results.swap], match_results swap
|
| 199 |
template<class BidirectionalIterator, class Allocator>
|
| 200 |
void swap(match_results<BidirectionalIterator, Allocator>& m1,
|
| 201 |
match_results<BidirectionalIterator, Allocator>& m2);
|
|
|
|
| 374 |
inline constexpr syntax_option_type multiline = unspecified;
|
| 375 |
}
|
| 376 |
```
|
| 377 |
|
| 378 |
The type `syntax_option_type` is an *implementation-defined* bitmask
|
| 379 |
+
type [[bitmask.types]]. Setting its elements has the effects listed in
|
| 380 |
+
[[re.synopt]]. A valid value of type `syntax_option_type` shall have at
|
| 381 |
+
most one of the grammar elements `ECMAScript`, `basic`, `extended`,
|
| 382 |
+
`awk`, `grep`, `egrep`, set. If no grammar element is set, the default
|
| 383 |
+
grammar is `ECMAScript`.
|
| 384 |
|
| 385 |
+
**Table: `syntax_option_type` effects** <a id="re.synopt">[re.synopt]</a>
|
| 386 |
|
| 387 |
| Element | Effect(s) if set |
|
| 388 |
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 389 |
+
| % `icase` | Specifies that matching of regular expressions against a character container sequence shall be performed without regard to case. \indexlibrarymember{syntax_option_type}{icase}% |
|
| 390 |
+
| % `nosubs` | Specifies that no sub-expressions shall be considered to be marked, so that when a regular expression is matched against a character container sequence, no sub-expression matches shall be stored in the supplied `match_results` object. \indexlibrarymember{syntax_option_type}{nosubs}% |
|
| 391 |
+
| % `optimize` | Specifies that the regular expression engine should pay more attention to the speed with which regular expressions are matched, and less to the speed with which regular expression objects are constructed. Otherwise it has no detectable effect on the program output. \indexlibrarymember{syntax_option_type}{optimize}% |
|
| 392 |
+
| % `collate` | Specifies that character ranges of the form `"[a-b]"` shall be locale sensitive. \indexlibrarymember{syntax_option_type}{collate}% \indextext{locale}% |
|
| 393 |
+
| % `ECMAScript` | Specifies that the grammar recognized by the regular expression engine shall be that used by ECMAScript in ECMA-262, as modified in~ [[re.grammar]]. \xref ECMA-262 15.10 \indextext{ECMAScript}% \indexlibrarymember{syntax_option_type}{ECMAScript}% |
|
| 394 |
+
| % `basic` | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX. \xref POSIX, Base Definitions and Headers, Section 9.3 \indextext{POSIX!regular expressions}% \indexlibrarymember{syntax_option_type}{basic}% |
|
| 395 |
+
| % `extended` | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX. \xref POSIX, Base Definitions and Headers, Section 9.4 \indextext{POSIX!extended regular expressions}% \indexlibrarymember{syntax_option_type}{extended}% |
|
| 396 |
+
| % `awk` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX. \indextext{\idxcode{awk}}% \indexlibrarymember{syntax_option_type}{awk}% |
|
| 397 |
+
| % `grep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX. \indextext{\idxcode{grep}}% \indexlibrarymember{syntax_option_type}{grep}% |
|
| 398 |
+
| % `egrep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX. \indextext{\idxcode{egrep}}% \indexlibrarymember{syntax_option_type}{egrep}% |
|
| 399 |
+
| % `multiline` | Specifies that `^` shall match the beginning of a line and `$` shall match the end of a line, if the `ECMAScript` engine is selected. \indextext{\idxcode{multiline}}% \indexlibrarymember{syntax_option_type}{multiline}% |
|
| 400 |
|
| 401 |
|
| 402 |
### Bitmask type `match_flag_type` <a id="re.matchflag">[[re.matchflag]]</a>
|
| 403 |
|
| 404 |
``` cpp
|
|
|
|
| 418 |
inline constexpr match_flag_type format_no_copy = unspecified;
|
| 419 |
inline constexpr match_flag_type format_first_only = unspecified;
|
| 420 |
}
|
| 421 |
```
|
| 422 |
|
| 423 |
+
The type `match_flag_type` is an *implementation-defined* bitmask type
|
| 424 |
+
[[bitmask.types]]. The constants of that type, except for
|
| 425 |
`match_default` and `format_default`, are bitmask elements. The
|
| 426 |
`match_default` and `format_default` constants are empty bitmasks.
|
| 427 |
Matching a regular expression against a sequence of characters
|
| 428 |
\[`first`, `last`) proceeds according to the rules of the grammar
|
| 429 |
specified for the regular expression object, modified according to the
|
| 430 |
+
effects listed in [[re.matchflag]] for any bitmask elements set.
|
|
|
|
| 431 |
|
| 432 |
**Table: `regex_constants::match_flag_type` effects when obtaining a match against a
|
| 433 |
+
character container sequence {[}`first`, `last`{)}.** <a id="re.matchflag">[re.matchflag]</a>
|
| 434 |
|
| 435 |
| Element | Effect(s) if set |
|
| 436 |
+
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 437 |
+
| % \indexlibraryglobal{match_not_bol}% `match_not_bol` | The first character in the sequence {[}`first`, `last`{)} shall be treated as though it is not at the beginning of a line, so the character \verb|^| in the regular expression shall not match {[}`first`, `first`{)}. |
|
| 438 |
+
| % \indexlibraryglobal{match_not_eol}% `match_not_eol` | The last character in the sequence {[}`first`, `last`{)} shall be treated as though it is not at the end of a line, so the character \verb|"$"| in the regular expression shall not match {[}`last`, `last`{)}. |
|
| 439 |
+
| % \indexlibraryglobal{match_not_bow}% `match_not_bow` | The expression \verb|"b"| shall not match the sub-sequence {[}`first`, `first`{)}. |
|
| 440 |
+
| % \indexlibraryglobal{match_not_eow}% `match_not_eow` | The expression \verb|"b"| shall not match the sub-sequence {[}`last`, `last`{)}. |
|
| 441 |
+
| % \indexlibraryglobal{match_any}% `match_any` | If more than one match is possible then any match is an acceptable result. |
|
| 442 |
+
| % \indexlibraryglobal{match_not_null}% `match_not_null` | The expression shall not match an empty sequence. |
|
| 443 |
+
| % \indexlibraryglobal{match_continuous}% `match_continuous` | The expression shall only match a sub-sequence that begins at `first`. |
|
| 444 |
+
| % \indexlibraryglobal{match_prev_avail}% `match_prev_avail` | \verb!--first! is a valid iterator position. When this flag is set the flags `match_not_bol` and `match_not_bow` shall be ignored by the regular expression algorithms [[re.alg]] and iterators [[re.iter]]. |
|
| 445 |
+
| % \indexlibraryglobal{format_default}% `format_default` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the ECMAScript replace function in ECMA-262, part 15.5.4.11 String.prototype.replace. In addition, during search and replace operations all non-overlapping occurrences of the regular expression shall be located and replaced, and sections of the input that did not match the expression shall be copied unchanged to the output string. |
|
| 446 |
+
| % \indexlibraryglobal{format_sed}% `format_sed` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the sed utility in POSIX. |
|
| 447 |
+
| % \indexlibraryglobal{format_no_copy}% `format_no_copy` | During a search and replace operation, sections of the character container sequence being searched that do not match the regular expression shall not be copied to the output string. |
|
| 448 |
+
| % \indexlibraryglobal{format_first_only}% `format_first_only` | When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced. |
|
| 449 |
|
| 450 |
|
| 451 |
### Implementation-defined `error_type` <a id="re.err">[[re.err]]</a>
|
| 452 |
|
| 453 |
``` cpp
|
|
|
|
| 467 |
inline constexpr error_type error_complexity = unspecified;
|
| 468 |
inline constexpr error_type error_stack = unspecified;
|
| 469 |
}
|
| 470 |
```
|
| 471 |
|
| 472 |
+
The type `error_type` is an *implementation-defined* enumerated type
|
| 473 |
+
[[enumerated.types]]. Values of type `error_type` represent the error
|
| 474 |
+
conditions described in [[re.err]]:
|
| 475 |
|
| 476 |
+
**Table: `error_type` values in the C locale** <a id="re.err">[re.err]</a>
|
| 477 |
|
| 478 |
| Value | Error condition |
|
| 479 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
| 480 |
| `error_collate` | The expression contained an invalid collating element name. |
|
| 481 |
| % `error_ctype` | The expression contained an invalid character class name. |
|
|
|
|
| 507 |
|
| 508 |
``` cpp
|
| 509 |
regex_error(regex_constants::error_type ecode);
|
| 510 |
```
|
| 511 |
|
| 512 |
+
*Ensures:* `ecode == code()`.
|
|
|
|
|
|
|
| 513 |
|
| 514 |
``` cpp
|
| 515 |
regex_constants::error_type code() const;
|
| 516 |
```
|
| 517 |
|
|
|
|
| 524 |
template<class charT>
|
| 525 |
struct regex_traits {
|
| 526 |
using char_type = charT;
|
| 527 |
using string_type = basic_string<char_type>;
|
| 528 |
using locale_type = locale;
|
| 529 |
+
using char_class_type = bitmask_type;
|
| 530 |
|
| 531 |
regex_traits();
|
| 532 |
static size_t length(const char_type* p);
|
| 533 |
charT translate(charT c) const;
|
| 534 |
charT translate_nocase(charT c) const;
|
|
|
|
| 550 |
};
|
| 551 |
}
|
| 552 |
```
|
| 553 |
|
| 554 |
The specializations `regex_traits<char>` and `regex_traits<wchar_t>`
|
| 555 |
+
meet the requirements for a regular expression traits class [[re.req]].
|
|
|
|
| 556 |
|
| 557 |
``` cpp
|
| 558 |
using char_class_type = bitmask_type;
|
| 559 |
```
|
| 560 |
|
|
|
|
| 588 |
*Effects:* As if by:
|
| 589 |
|
| 590 |
``` cpp
|
| 591 |
string_type str(first, last);
|
| 592 |
return use_facet<collate<charT>>(
|
| 593 |
+
getloc()).transform(str.data(), str.data() + str.length());
|
| 594 |
```
|
| 595 |
|
| 596 |
``` cpp
|
| 597 |
template<class ForwardIterator>
|
| 598 |
string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
|
|
|
|
| 612 |
``` cpp
|
| 613 |
template<class ForwardIterator>
|
| 614 |
string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
|
| 615 |
```
|
| 616 |
|
| 617 |
+
*Returns:* A sequence of one or more characters that represents the
|
| 618 |
collating element consisting of the character sequence designated by the
|
| 619 |
iterator range \[`first`, `last`). Returns an empty string if the
|
| 620 |
character sequence is not a valid collating element.
|
| 621 |
|
| 622 |
``` cpp
|
| 623 |
template<class ForwardIterator>
|
| 624 |
char_class_type lookup_classname(
|
| 625 |
ForwardIterator first, ForwardIterator last, bool icase = false) const;
|
| 626 |
```
|
| 627 |
|
| 628 |
+
*Returns:* An unspecified value that represents the character
|
| 629 |
classification named by the character sequence designated by the
|
| 630 |
iterator range \[`first`, `last`). If the parameter `icase` is `true`
|
| 631 |
then the returned mask identifies the character classification without
|
| 632 |
regard to the case of the characters being matched, otherwise it does
|
| 633 |
honor the case of the characters being matched.[^1] The value returned
|
| 634 |
shall be independent of the case of the characters in the character
|
| 635 |
sequence. If the name is not recognized then returns
|
| 636 |
`char_class_type()`.
|
| 637 |
|
| 638 |
*Remarks:* For `regex_traits<char>`, at least the narrow character names
|
| 639 |
+
in [[re.traits.classnames]] shall be recognized. For
|
| 640 |
`regex_traits<wchar_t>`, at least the wide character names in
|
| 641 |
+
[[re.traits.classnames]] shall be recognized.
|
| 642 |
|
| 643 |
``` cpp
|
| 644 |
bool isctype(charT c, char_class_type f) const;
|
| 645 |
```
|
| 646 |
|
|
|
|
| 654 |
template<class C>
|
| 655 |
ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
|
| 656 |
```
|
| 657 |
|
| 658 |
that returns a value in which each `ctype_base::mask` value
|
| 659 |
+
corresponding to a value in `f` named in [[re.traits.classnames]] is
|
| 660 |
+
set, then the result is determined as if by:
|
|
|
|
| 661 |
|
| 662 |
``` cpp
|
| 663 |
ctype_base::mask m = convert<charT>(f);
|
| 664 |
const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
|
| 665 |
if (ct.is(m, c)) {
|
|
|
|
| 703 |
|
| 704 |
``` cpp
|
| 705 |
int value(charT ch, int radix) const;
|
| 706 |
```
|
| 707 |
|
| 708 |
+
*Preconditions:* The value of `radix` is 8, 10, or 16.
|
| 709 |
|
| 710 |
+
*Returns:* The value represented by the digit `ch` in base `radix` if
|
| 711 |
the character `ch` is a valid digit in base `radix`; otherwise returns
|
| 712 |
`-1`.
|
| 713 |
|
| 714 |
``` cpp
|
| 715 |
locale_type imbue(locale_type loc);
|
|
|
|
| 719 |
|
| 720 |
[*Note 1*: Calling `imbue` with a different locale than the one
|
| 721 |
currently in use invalidates all cached data held by
|
| 722 |
`*this`. — *end note*]
|
| 723 |
|
| 724 |
+
*Returns:* If no locale has been previously imbued then a copy of the
|
| 725 |
global locale in effect at the time of construction of `*this`,
|
| 726 |
otherwise a copy of the last argument passed to `imbue`.
|
| 727 |
|
| 728 |
+
*Ensures:* `getloc() == loc`.
|
| 729 |
|
| 730 |
``` cpp
|
| 731 |
locale_type getloc() const;
|
| 732 |
```
|
| 733 |
|
| 734 |
+
*Returns:* If no locale has been imbued then a copy of the global locale
|
| 735 |
in effect at the time of construction of `*this`, otherwise a copy of
|
| 736 |
the last argument passed to `imbue`.
|
| 737 |
|
| 738 |
+
**Table: Character class names and corresponding `ctype` masks** <a id="re.traits.classnames">[re.traits.classnames]</a>
|
| 739 |
|
| 740 |
| Narrow character name | Wide character name | Corresponding `ctype_base::mask` value |
|
| 741 |
| --------------------- | ------------------- | -------------------------------------- |
|
| 742 |
| `"alnum"` | `L"alnum"` | `ctype_base::alnum` |
|
| 743 |
| `"alpha"` | `L"alpha"` | `ctype_base::alpha` |
|
|
|
|
| 770 |
representation. It is not specified what form this representation takes,
|
| 771 |
nor how it is accessed by algorithms that operate on regular
|
| 772 |
expressions.
|
| 773 |
|
| 774 |
[*Note 1*: Implementations will typically declare some function
|
| 775 |
+
templates as friends of `basic_regex` to achieve this. — *end note*]
|
| 776 |
|
| 777 |
The functions described in this Clause report errors by throwing
|
| 778 |
exceptions of type `regex_error`.
|
| 779 |
|
| 780 |
``` cpp
|
| 781 |
namespace std {
|
| 782 |
template<class charT, class traits = regex_traits<charT>>
|
| 783 |
class basic_regex {
|
| 784 |
public:
|
| 785 |
+
// types
|
| 786 |
using value_type = charT;
|
| 787 |
using traits_type = traits;
|
| 788 |
using string_type = typename traits::string_type;
|
| 789 |
using flag_type = regex_constants::syntax_option_type;
|
| 790 |
using locale_type = typename traits::locale_type;
|
| 791 |
|
| 792 |
+
// [re.synopt], constants
|
| 793 |
+
static constexpr flag_type icase = regex_constants::icase;
|
| 794 |
+
static constexpr flag_type nosubs = regex_constants::nosubs;
|
| 795 |
+
static constexpr flag_type optimize = regex_constants::optimize;
|
| 796 |
+
static constexpr flag_type collate = regex_constants::collate;
|
| 797 |
+
static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
|
| 798 |
+
static constexpr flag_type basic = regex_constants::basic;
|
| 799 |
+
static constexpr flag_type extended = regex_constants::extended;
|
| 800 |
+
static constexpr flag_type awk = regex_constants::awk;
|
| 801 |
+
static constexpr flag_type grep = regex_constants::grep;
|
| 802 |
+
static constexpr flag_type egrep = regex_constants::egrep;
|
| 803 |
+
static constexpr flag_type multiline = regex_constants::multiline;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
|
| 805 |
// [re.regex.construct], construct/copy/destroy
|
| 806 |
basic_regex();
|
| 807 |
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 808 |
basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
|
| 809 |
basic_regex(const basic_regex&);
|
| 810 |
basic_regex(basic_regex&&) noexcept;
|
| 811 |
template<class ST, class SA>
|
| 812 |
+
explicit basic_regex(const basic_string<charT, ST, SA>& s,
|
| 813 |
flag_type f = regex_constants::ECMAScript);
|
| 814 |
template<class ForwardIterator>
|
| 815 |
basic_regex(ForwardIterator first, ForwardIterator last,
|
| 816 |
flag_type f = regex_constants::ECMAScript);
|
| 817 |
+
basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
|
| 818 |
|
| 819 |
~basic_regex();
|
| 820 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 821 |
// [re.regex.assign], assign
|
| 822 |
+
basic_regex& operator=(const basic_regex& e);
|
| 823 |
+
basic_regex& operator=(basic_regex&& e) noexcept;
|
| 824 |
+
basic_regex& operator=(const charT* p);
|
| 825 |
+
basic_regex& operator=(initializer_list<charT> il);
|
| 826 |
+
template<class ST, class SA>
|
| 827 |
+
basic_regex& operator=(const basic_string<charT, ST, SA>& s);
|
| 828 |
+
|
| 829 |
+
basic_regex& assign(const basic_regex& e);
|
| 830 |
+
basic_regex& assign(basic_regex&& e) noexcept;
|
| 831 |
+
basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 832 |
+
basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
|
| 833 |
+
template<class ST, class SA>
|
| 834 |
+
basic_regex& assign(const basic_string<charT, ST, SA>& s,
|
| 835 |
flag_type f = regex_constants::ECMAScript);
|
| 836 |
template<class InputIterator>
|
| 837 |
basic_regex& assign(InputIterator first, InputIterator last,
|
| 838 |
flag_type f = regex_constants::ECMAScript);
|
| 839 |
basic_regex& assign(initializer_list<charT>,
|
| 840 |
+
flag_type f = regex_constants::ECMAScript);
|
| 841 |
|
| 842 |
// [re.regex.operations], const operations
|
| 843 |
unsigned mark_count() const;
|
| 844 |
flag_type flags() const;
|
| 845 |
|
|
|
|
| 856 |
regex_constants::syntax_option_type = regex_constants::ECMAScript)
|
| 857 |
-> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
|
| 858 |
}
|
| 859 |
```
|
| 860 |
|
| 861 |
+
### Constructors <a id="re.regex.construct">[[re.regex.construct]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
|
| 863 |
``` cpp
|
| 864 |
basic_regex();
|
| 865 |
```
|
| 866 |
|
| 867 |
+
*Ensures:* `*this` does not match any character sequence.
|
|
|
|
| 868 |
|
| 869 |
``` cpp
|
| 870 |
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 871 |
```
|
| 872 |
|
| 873 |
+
*Preconditions:* \[`p`, `p + char_traits<charT>::length(p)`) is a valid
|
| 874 |
+
range.
|
| 875 |
|
| 876 |
+
*Effects:* The object’s internal finite state machine is constructed
|
| 877 |
+
from the regular expression contained in the sequence of characters
|
| 878 |
+
\[`p`, `p + char_traits<charT>::length(p)`), and interpreted according
|
| 879 |
+
to the flags `f`.
|
| 880 |
|
| 881 |
+
*Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
|
| 882 |
+
marked sub-expressions within the expression.
|
|
|
|
|
|
|
|
|
|
| 883 |
|
| 884 |
+
*Throws:* `regex_error` if \[`p`, `p + char_traits<charT>::length(p)`)
|
| 885 |
+
is not a valid regular expression.
|
| 886 |
|
| 887 |
``` cpp
|
| 888 |
+
basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
|
| 889 |
```
|
| 890 |
|
| 891 |
+
*Preconditions:* \[`p`, `p + len`) is a valid range.
|
| 892 |
|
| 893 |
+
*Effects:* The object’s internal finite state machine is constructed
|
| 894 |
+
from the regular expression contained in the sequence of characters
|
| 895 |
+
\[`p`, `p + len`), and interpreted according the flags specified in `f`.
|
| 896 |
|
| 897 |
+
*Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
|
| 898 |
+
marked sub-expressions within the expression.
|
|
|
|
|
|
|
| 899 |
|
| 900 |
+
*Throws:* `regex_error` if \[`p`, `p + len`) is not a valid regular
|
| 901 |
+
expression.
|
| 902 |
|
| 903 |
``` cpp
|
| 904 |
basic_regex(const basic_regex& e);
|
| 905 |
```
|
| 906 |
|
| 907 |
+
*Ensures:* `flags()` and `mark_count()` return `e.flags()` and
|
|
|
|
|
|
|
|
|
|
| 908 |
`e.mark_count()`, respectively.
|
| 909 |
|
| 910 |
``` cpp
|
| 911 |
basic_regex(basic_regex&& e) noexcept;
|
| 912 |
```
|
| 913 |
|
| 914 |
+
*Ensures:* `flags()` and `mark_count()` return the values that
|
|
|
|
|
|
|
| 915 |
`e.flags()` and `e.mark_count()`, respectively, had before construction.
|
|
|
|
| 916 |
|
| 917 |
``` cpp
|
| 918 |
template<class ST, class SA>
|
| 919 |
explicit basic_regex(const basic_string<charT, ST, SA>& s,
|
| 920 |
flag_type f = regex_constants::ECMAScript);
|
| 921 |
```
|
| 922 |
|
| 923 |
+
*Effects:* The object’s internal finite state machine is constructed
|
| 924 |
+
from the regular expression contained in the string `s`, and interpreted
|
| 925 |
+
according to the flags specified in `f`.
|
| 926 |
+
|
| 927 |
+
*Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
|
| 928 |
+
marked sub-expressions within the expression.
|
| 929 |
+
|
| 930 |
*Throws:* `regex_error` if `s` is not a valid regular expression.
|
| 931 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 932 |
``` cpp
|
| 933 |
template<class ForwardIterator>
|
| 934 |
basic_regex(ForwardIterator first, ForwardIterator last,
|
| 935 |
flag_type f = regex_constants::ECMAScript);
|
| 936 |
```
|
| 937 |
|
| 938 |
+
*Effects:* The object’s internal finite state machine is constructed
|
| 939 |
+
from the regular expression contained in the sequence of characters
|
| 940 |
+
\[`first`, `last`), and interpreted according to the flags specified in
|
| 941 |
+
`f`.
|
| 942 |
+
|
| 943 |
+
*Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
|
| 944 |
+
marked sub-expressions within the expression.
|
| 945 |
+
|
| 946 |
*Throws:* `regex_error` if the sequence \[`first`, `last`) is not a
|
| 947 |
valid regular expression.
|
| 948 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
``` cpp
|
| 950 |
basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
|
| 951 |
```
|
| 952 |
|
| 953 |
*Effects:* Same as `basic_regex(il.begin(), il.end(), f)`.
|
| 954 |
|
| 955 |
+
### Assignment <a id="re.regex.assign">[[re.regex.assign]]</a>
|
| 956 |
|
| 957 |
``` cpp
|
| 958 |
basic_regex& operator=(const basic_regex& e);
|
| 959 |
```
|
| 960 |
|
| 961 |
+
*Ensures:* `flags()` and `mark_count()` return `e.flags()` and
|
|
|
|
|
|
|
| 962 |
`e.mark_count()`, respectively.
|
| 963 |
|
| 964 |
``` cpp
|
| 965 |
basic_regex& operator=(basic_regex&& e) noexcept;
|
| 966 |
```
|
| 967 |
|
| 968 |
+
*Ensures:* `flags()` and `mark_count()` return the values that
|
|
|
|
|
|
|
| 969 |
`e.flags()` and `e.mark_count()`, respectively, had before assignment.
|
| 970 |
`e` is in a valid state with unspecified value.
|
| 971 |
|
| 972 |
``` cpp
|
| 973 |
+
basic_regex& operator=(const charT* p);
|
| 974 |
```
|
| 975 |
|
| 976 |
+
*Effects:* Equivalent to: `return assign(p);`
|
|
|
|
|
|
|
| 977 |
|
| 978 |
``` cpp
|
| 979 |
basic_regex& operator=(initializer_list<charT> il);
|
| 980 |
```
|
| 981 |
|
| 982 |
+
*Effects:* Equivalent to: `return assign(il.begin(), il.end());`
|
| 983 |
|
| 984 |
``` cpp
|
| 985 |
template<class ST, class SA>
|
| 986 |
+
basic_regex& operator=(const basic_string<charT, ST, SA>& s);
|
| 987 |
```
|
| 988 |
|
| 989 |
+
*Effects:* Equivalent to: `return assign(s);`
|
| 990 |
|
| 991 |
``` cpp
|
| 992 |
+
basic_regex& assign(const basic_regex& e);
|
| 993 |
```
|
| 994 |
|
| 995 |
+
*Effects:* Equivalent to: `return *this = e;`
|
|
|
|
|
|
|
| 996 |
|
| 997 |
``` cpp
|
| 998 |
+
basic_regex& assign(basic_regex&& e) noexcept;
|
| 999 |
```
|
| 1000 |
|
| 1001 |
+
*Effects:* Equivalent to: `return *this = std::move(e);`
|
|
|
|
|
|
|
| 1002 |
|
| 1003 |
``` cpp
|
| 1004 |
+
basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
|
| 1005 |
```
|
| 1006 |
|
| 1007 |
+
*Effects:* Equivalent to: `return assign(string_type(p), f);`
|
| 1008 |
|
| 1009 |
``` cpp
|
| 1010 |
+
basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
|
| 1011 |
```
|
| 1012 |
|
| 1013 |
+
*Effects:* Equivalent to: `return assign(string_type(p, len), f);`
|
| 1014 |
|
| 1015 |
``` cpp
|
| 1016 |
+
template<class ST, class SA>
|
| 1017 |
+
basic_regex& assign(const basic_string<charT, ST, SA>& s,
|
| 1018 |
flag_type f = regex_constants::ECMAScript);
|
| 1019 |
```
|
| 1020 |
|
|
|
|
|
|
|
| 1021 |
*Returns:* `*this`.
|
| 1022 |
|
| 1023 |
*Effects:* Assigns the regular expression contained in the string `s`,
|
| 1024 |
interpreted according the flags specified in `f`. If an exception is
|
| 1025 |
thrown, `*this` is unchanged.
|
| 1026 |
|
| 1027 |
+
*Ensures:* If no exception is thrown, `flags()` returns `f` and
|
| 1028 |
`mark_count()` returns the number of marked sub-expressions within the
|
| 1029 |
expression.
|
| 1030 |
|
| 1031 |
+
*Throws:* `regex_error` if `s` is not a valid regular expression.
|
| 1032 |
+
|
| 1033 |
``` cpp
|
| 1034 |
template<class InputIterator>
|
| 1035 |
basic_regex& assign(InputIterator first, InputIterator last,
|
| 1036 |
flag_type f = regex_constants::ECMAScript);
|
| 1037 |
```
|
| 1038 |
|
| 1039 |
+
*Effects:* Equivalent to: `return assign(string_type(first, last), f);`
|
|
|
|
|
|
|
|
|
|
| 1040 |
|
| 1041 |
``` cpp
|
| 1042 |
basic_regex& assign(initializer_list<charT> il,
|
| 1043 |
flag_type f = regex_constants::ECMAScript);
|
| 1044 |
```
|
| 1045 |
|
| 1046 |
+
*Effects:* Equivalent to: `return assign(il.begin(), il.end(), f);`
|
| 1047 |
|
| 1048 |
+
### Constant operations <a id="re.regex.operations">[[re.regex.operations]]</a>
|
|
|
|
|
|
|
| 1049 |
|
| 1050 |
``` cpp
|
| 1051 |
unsigned mark_count() const;
|
| 1052 |
```
|
| 1053 |
|
|
|
|
| 1059 |
```
|
| 1060 |
|
| 1061 |
*Effects:* Returns a copy of the regular expression syntax flags that
|
| 1062 |
were passed to the object’s constructor or to the last call to `assign`.
|
| 1063 |
|
| 1064 |
+
### Locale <a id="re.regex.locale">[[re.regex.locale]]</a>
|
| 1065 |
|
| 1066 |
``` cpp
|
| 1067 |
locale_type imbue(locale_type loc);
|
| 1068 |
```
|
| 1069 |
|
|
|
|
| 1078 |
|
| 1079 |
*Effects:* Returns the result of `traits_inst.getloc()` where
|
| 1080 |
`traits_inst` is a (default-initialized) instance of the template
|
| 1081 |
parameter `traits` stored within the object.
|
| 1082 |
|
| 1083 |
+
### Swap <a id="re.regex.swap">[[re.regex.swap]]</a>
|
| 1084 |
|
| 1085 |
``` cpp
|
| 1086 |
void swap(basic_regex& e);
|
| 1087 |
```
|
| 1088 |
|
| 1089 |
*Effects:* Swaps the contents of the two regular expressions.
|
| 1090 |
|
| 1091 |
+
*Ensures:* `*this` contains the regular expression that was in `e`, `e`
|
| 1092 |
+
contains the regular expression that was in `*this`.
|
| 1093 |
|
| 1094 |
*Complexity:* Constant time.
|
| 1095 |
|
| 1096 |
+
### Non-member functions <a id="re.regex.nonmemb">[[re.regex.nonmemb]]</a>
|
|
|
|
|
|
|
| 1097 |
|
| 1098 |
``` cpp
|
| 1099 |
template<class charT, class traits>
|
| 1100 |
void swap(basic_regex<charT, traits>& lhs, basic_regex<charT, traits>& rhs);
|
| 1101 |
```
|
|
|
|
| 1132 |
int compare(const value_type* s) const;
|
| 1133 |
};
|
| 1134 |
}
|
| 1135 |
```
|
| 1136 |
|
| 1137 |
+
### Members <a id="re.submatch.members">[[re.submatch.members]]</a>
|
| 1138 |
|
| 1139 |
``` cpp
|
| 1140 |
constexpr sub_match();
|
| 1141 |
```
|
| 1142 |
|
|
|
|
| 1177 |
int compare(const value_type* s) const;
|
| 1178 |
```
|
| 1179 |
|
| 1180 |
*Returns:* `str().compare(s)`.
|
| 1181 |
|
| 1182 |
+
### Non-member operators <a id="re.submatch.op">[[re.submatch.op]]</a>
|
| 1183 |
+
|
| 1184 |
+
Let `SM-CAT(I)` be
|
| 1185 |
+
|
| 1186 |
+
``` cpp
|
| 1187 |
+
compare_three_way_result_t<basic_string<typename iterator_traits<I>::value_type>>
|
| 1188 |
+
```
|
| 1189 |
|
| 1190 |
``` cpp
|
| 1191 |
template<class BiIter>
|
| 1192 |
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1193 |
```
|
| 1194 |
|
| 1195 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 1196 |
|
| 1197 |
``` cpp
|
| 1198 |
template<class BiIter>
|
| 1199 |
+
auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
|
| 1200 |
```
|
| 1201 |
|
| 1202 |
+
*Returns:* `static_cast<`*`SM-CAT`*`(BiIter)>(lhs.compare(rhs) <=> 0)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1203 |
|
| 1204 |
``` cpp
|
| 1205 |
template<class BiIter, class ST, class SA>
|
| 1206 |
bool operator==(
|
| 1207 |
const sub_match<BiIter>& lhs,
|
|
|
|
| 1214 |
lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0
|
| 1215 |
```
|
| 1216 |
|
| 1217 |
``` cpp
|
| 1218 |
template<class BiIter, class ST, class SA>
|
| 1219 |
+
auto operator<=>(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
const sub_match<BiIter>& lhs,
|
| 1221 |
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
|
| 1222 |
```
|
| 1223 |
|
| 1224 |
*Returns:*
|
| 1225 |
|
| 1226 |
``` cpp
|
| 1227 |
+
static_cast<SM-CAT(BiIter)>(lhs.compare(
|
| 1228 |
+
typename sub_match<BiIter>::string_type(rhs.data(), rhs.size()))
|
| 1229 |
+
<=> 0
|
| 1230 |
+
)
|
| 1231 |
```
|
| 1232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1233 |
``` cpp
|
| 1234 |
template<class BiIter>
|
| 1235 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 1236 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1237 |
```
|
| 1238 |
|
| 1239 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 1240 |
|
| 1241 |
``` cpp
|
| 1242 |
template<class BiIter>
|
| 1243 |
+
auto operator<=>(const sub_match<BiIter>& lhs,
|
| 1244 |
const typename iterator_traits<BiIter>::value_type* rhs);
|
| 1245 |
```
|
| 1246 |
|
| 1247 |
+
*Returns:* `static_cast<`*`SM-CAT`*`(BiIter)>(lhs.compare(rhs) <=> 0)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1248 |
|
| 1249 |
``` cpp
|
| 1250 |
template<class BiIter>
|
| 1251 |
bool operator==(const sub_match<BiIter>& lhs,
|
| 1252 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
|
|
|
| 1255 |
*Returns:*
|
| 1256 |
`lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0`.
|
| 1257 |
|
| 1258 |
``` cpp
|
| 1259 |
template<class BiIter>
|
| 1260 |
+
auto operator<=>(const sub_match<BiIter>& lhs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1261 |
const typename iterator_traits<BiIter>::value_type& rhs);
|
| 1262 |
```
|
| 1263 |
|
| 1264 |
*Returns:*
|
|
|
|
| 1265 |
|
| 1266 |
``` cpp
|
| 1267 |
+
static_cast<SM-CAT(BiIter)>(lhs.compare(
|
| 1268 |
+
typename sub_match<BiIter>::string_type(1, rhs))
|
| 1269 |
+
<=> 0
|
| 1270 |
+
)
|
| 1271 |
```
|
| 1272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1273 |
``` cpp
|
| 1274 |
template<class charT, class ST, class BiIter>
|
| 1275 |
basic_ostream<charT, ST>&
|
| 1276 |
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
|
| 1277 |
```
|
|
|
|
| 1283 |
Class template `match_results` denotes a collection of character
|
| 1284 |
sequences representing the result of a regular expression match. Storage
|
| 1285 |
for the collection is allocated and freed as necessary by the member
|
| 1286 |
functions of class template `match_results`.
|
| 1287 |
|
| 1288 |
+
The class template `match_results` meets the requirements of an
|
| 1289 |
allocator-aware container and of a sequence container (
|
| 1290 |
[[container.requirements.general]], [[sequence.reqmts]]) except that
|
| 1291 |
+
only copy assignment, move assignment, and operations defined for
|
| 1292 |
+
const-qualified sequence containers are supported and that the semantics
|
| 1293 |
+
of comparison functions are different from those required for a
|
| 1294 |
+
container.
|
| 1295 |
|
| 1296 |
A default-constructed `match_results` object has no fully established
|
| 1297 |
result state. A match result is *ready* when, as a consequence of a
|
| 1298 |
completed regular expression match modifying such an object, its result
|
| 1299 |
state becomes fully established. The effects of calling most member
|
|
|
|
| 1331 |
using char_type =
|
| 1332 |
typename iterator_traits<BidirectionalIterator>::value_type;
|
| 1333 |
using string_type = basic_string<char_type>;
|
| 1334 |
|
| 1335 |
// [re.results.const], construct/copy/destroy
|
| 1336 |
+
match_results() : match_results(Allocator()) {}
|
| 1337 |
+
explicit match_results(const Allocator&);
|
| 1338 |
match_results(const match_results& m);
|
| 1339 |
match_results(match_results&& m) noexcept;
|
| 1340 |
match_results& operator=(const match_results& m);
|
| 1341 |
match_results& operator=(match_results&& m);
|
| 1342 |
~match_results();
|
|
|
|
| 1345 |
bool ready() const;
|
| 1346 |
|
| 1347 |
// [re.results.size], size
|
| 1348 |
size_type size() const;
|
| 1349 |
size_type max_size() const;
|
| 1350 |
+
[[nodiscard]] bool empty() const;
|
| 1351 |
|
| 1352 |
// [re.results.acc], element access
|
| 1353 |
difference_type length(size_type sub = 0) const;
|
| 1354 |
difference_type position(size_type sub = 0) const;
|
| 1355 |
string_type str(size_type sub = 0) const;
|
|
|
|
| 1388 |
void swap(match_results& that);
|
| 1389 |
};
|
| 1390 |
}
|
| 1391 |
```
|
| 1392 |
|
| 1393 |
+
### Constructors <a id="re.results.const">[[re.results.const]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1394 |
|
| 1395 |
``` cpp
|
| 1396 |
+
explicit match_results(const Allocator& a);
|
| 1397 |
```
|
| 1398 |
|
| 1399 |
+
*Ensures:* `ready()` returns `false`. `size()` returns `0`.
|
|
|
|
| 1400 |
|
| 1401 |
``` cpp
|
| 1402 |
match_results(match_results&& m) noexcept;
|
| 1403 |
```
|
| 1404 |
|
| 1405 |
+
*Effects:* The stored `Allocator` value is move constructed from
|
|
|
|
|
|
|
| 1406 |
`m.get_allocator()`.
|
| 1407 |
|
| 1408 |
+
*Ensures:* As specified in [[re.results.const]].
|
| 1409 |
|
| 1410 |
``` cpp
|
| 1411 |
match_results& operator=(const match_results& m);
|
| 1412 |
```
|
| 1413 |
|
| 1414 |
+
*Ensures:* As specified in [[re.results.const]].
|
|
|
|
| 1415 |
|
| 1416 |
``` cpp
|
| 1417 |
match_results& operator=(match_results&& m);
|
| 1418 |
```
|
| 1419 |
|
| 1420 |
+
*Ensures:* As specified in [[re.results.const]].
|
|
|
|
| 1421 |
|
| 1422 |
+
**Table: `match_results` assignment operator effects** <a id="re.results.const">[re.results.const]</a>
|
| 1423 |
|
| 1424 |
| Element | Value |
|
| 1425 |
| ------------- | ----------------------------------------------- |
|
| 1426 |
| `ready()` | `m.ready()` |
|
| 1427 |
| `size()` | `m.size()` |
|
|
|
|
| 1431 |
| `(*this)[n]` | `m[n]` for all integers `n < m.size()` |
|
| 1432 |
| `length(n)` | `m.length(n)` for all integers `n < m.size()` |
|
| 1433 |
| `position(n)` | `m.position(n)` for all integers `n < m.size()` |
|
| 1434 |
|
| 1435 |
|
| 1436 |
+
### State <a id="re.results.state">[[re.results.state]]</a>
|
| 1437 |
|
| 1438 |
``` cpp
|
| 1439 |
bool ready() const;
|
| 1440 |
```
|
| 1441 |
|
| 1442 |
*Returns:* `true` if `*this` has a fully established result state,
|
| 1443 |
otherwise `false`.
|
| 1444 |
|
| 1445 |
+
### Size <a id="re.results.size">[[re.results.size]]</a>
|
| 1446 |
|
| 1447 |
``` cpp
|
| 1448 |
size_type size() const;
|
| 1449 |
```
|
| 1450 |
|
|
|
|
| 1452 |
expression that was matched if `*this` represents the result of a
|
| 1453 |
successful match. Otherwise returns `0`.
|
| 1454 |
|
| 1455 |
[*Note 1*: The state of a `match_results` object can be modified only
|
| 1456 |
by passing that object to `regex_match` or `regex_search`.
|
| 1457 |
+
Subclauses [[re.alg.match]] and [[re.alg.search]] specify the effects
|
| 1458 |
+
of those algorithms on their `match_results` arguments. — *end note*]
|
| 1459 |
|
| 1460 |
``` cpp
|
| 1461 |
size_type max_size() const;
|
| 1462 |
```
|
| 1463 |
|
| 1464 |
*Returns:* The maximum number of `sub_match` elements that can be stored
|
| 1465 |
in `*this`.
|
| 1466 |
|
| 1467 |
``` cpp
|
| 1468 |
+
[[nodiscard]] bool empty() const;
|
| 1469 |
```
|
| 1470 |
|
| 1471 |
*Returns:* `size() == 0`.
|
| 1472 |
|
| 1473 |
+
### Element access <a id="re.results.acc">[[re.results.acc]]</a>
|
| 1474 |
|
| 1475 |
``` cpp
|
| 1476 |
difference_type length(size_type sub = 0) const;
|
| 1477 |
```
|
| 1478 |
|
| 1479 |
+
*Preconditions:* `ready() == true`.
|
| 1480 |
|
| 1481 |
*Returns:* `(*this)[sub].length()`.
|
| 1482 |
|
| 1483 |
``` cpp
|
| 1484 |
difference_type position(size_type sub = 0) const;
|
| 1485 |
```
|
| 1486 |
|
| 1487 |
+
*Preconditions:* `ready() == true`.
|
| 1488 |
|
| 1489 |
*Returns:* The distance from the start of the target sequence to
|
| 1490 |
`(*this)[sub].first`.
|
| 1491 |
|
| 1492 |
``` cpp
|
| 1493 |
string_type str(size_type sub = 0) const;
|
| 1494 |
```
|
| 1495 |
|
| 1496 |
+
*Preconditions:* `ready() == true`.
|
| 1497 |
|
| 1498 |
*Returns:* `string_type((*this)[sub])`.
|
| 1499 |
|
| 1500 |
``` cpp
|
| 1501 |
const_reference operator[](size_type n) const;
|
| 1502 |
```
|
| 1503 |
|
| 1504 |
+
*Preconditions:* `ready() == true`.
|
| 1505 |
|
| 1506 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1507 |
character sequence that matched marked sub-expression `n`. If `n == 0`
|
| 1508 |
then returns a reference to a `sub_match` object representing the
|
| 1509 |
character sequence that matched the whole regular expression. If
|
|
|
|
| 1512 |
|
| 1513 |
``` cpp
|
| 1514 |
const_reference prefix() const;
|
| 1515 |
```
|
| 1516 |
|
| 1517 |
+
*Preconditions:* `ready() == true`.
|
| 1518 |
|
| 1519 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1520 |
character sequence from the start of the string being matched/searched
|
| 1521 |
to the start of the match found.
|
| 1522 |
|
| 1523 |
``` cpp
|
| 1524 |
const_reference suffix() const;
|
| 1525 |
```
|
| 1526 |
|
| 1527 |
+
*Preconditions:* `ready() == true`.
|
| 1528 |
|
| 1529 |
*Returns:* A reference to the `sub_match` object representing the
|
| 1530 |
character sequence from the end of the match found to the end of the
|
| 1531 |
string being matched/searched.
|
| 1532 |
|
|
|
|
| 1544 |
```
|
| 1545 |
|
| 1546 |
*Returns:* A terminating iterator that enumerates over all the
|
| 1547 |
sub-expressions stored in `*this`.
|
| 1548 |
|
| 1549 |
+
### Formatting <a id="re.results.form">[[re.results.form]]</a>
|
| 1550 |
|
| 1551 |
``` cpp
|
| 1552 |
template<class OutputIter>
|
| 1553 |
OutputIter format(
|
| 1554 |
OutputIter out,
|
| 1555 |
const char_type* fmt_first, const char_type* fmt_last,
|
| 1556 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 1557 |
```
|
| 1558 |
|
| 1559 |
+
*Preconditions:* `ready() == true` and `OutputIter` meets the
|
| 1560 |
+
requirements for a *Cpp17OutputIterator*[[output.iterators]].
|
| 1561 |
|
| 1562 |
*Effects:* Copies the character sequence \[`fmt_first`, `fmt_last`) to
|
| 1563 |
OutputIter `out`. Replaces each format specifier or escape sequence in
|
| 1564 |
the copied range with either the character(s) it represents or the
|
| 1565 |
sequence of characters within `*this` to which it refers. The bitmasks
|
|
|
|
| 1587 |
basic_string<char_type, ST, SA> format(
|
| 1588 |
const basic_string<char_type, ST, SA>& fmt,
|
| 1589 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 1590 |
```
|
| 1591 |
|
| 1592 |
+
*Preconditions:* `ready() == true`.
|
| 1593 |
|
| 1594 |
*Effects:* Constructs an empty string `result` of type
|
| 1595 |
`basic_string<char_type, ST, SA>` and calls:
|
| 1596 |
|
| 1597 |
``` cpp
|
|
|
|
| 1604 |
string_type format(
|
| 1605 |
const char_type* fmt,
|
| 1606 |
regex_constants::match_flag_type flags = regex_constants::format_default) const;
|
| 1607 |
```
|
| 1608 |
|
| 1609 |
+
*Preconditions:* `ready() == true`.
|
| 1610 |
|
| 1611 |
*Effects:* Constructs an empty string `result` of type `string_type` and
|
| 1612 |
calls:
|
| 1613 |
|
| 1614 |
``` cpp
|
| 1615 |
format(back_inserter(result), fmt, fmt + char_traits<char_type>::length(fmt), flags);
|
| 1616 |
```
|
| 1617 |
|
| 1618 |
*Returns:* `result`.
|
| 1619 |
|
| 1620 |
+
### Allocator <a id="re.results.all">[[re.results.all]]</a>
|
| 1621 |
|
| 1622 |
``` cpp
|
| 1623 |
allocator_type get_allocator() const;
|
| 1624 |
```
|
| 1625 |
|
| 1626 |
*Returns:* A copy of the Allocator that was passed to the object’s
|
| 1627 |
constructor or, if that allocator has been replaced, a copy of the most
|
| 1628 |
recent replacement.
|
| 1629 |
|
| 1630 |
+
### Swap <a id="re.results.swap">[[re.results.swap]]</a>
|
| 1631 |
|
| 1632 |
``` cpp
|
| 1633 |
void swap(match_results& that);
|
| 1634 |
```
|
| 1635 |
|
| 1636 |
*Effects:* Swaps the contents of the two sequences.
|
| 1637 |
|
| 1638 |
+
*Ensures:* `*this` contains the sequence of matched sub-expressions that
|
| 1639 |
+
were in `that`, `that` contains the sequence of matched sub-expressions
|
| 1640 |
+
that were in `*this`.
|
| 1641 |
|
| 1642 |
*Complexity:* Constant time.
|
| 1643 |
|
| 1644 |
``` cpp
|
| 1645 |
template<class BidirectionalIterator, class Allocator>
|
|
|
|
| 1647 |
match_results<BidirectionalIterator, Allocator>& m2);
|
| 1648 |
```
|
| 1649 |
|
| 1650 |
*Effects:* As if by `m1.swap(m2)`.
|
| 1651 |
|
| 1652 |
+
### Non-member functions <a id="re.results.nonmember">[[re.results.nonmember]]</a>
|
| 1653 |
|
| 1654 |
``` cpp
|
| 1655 |
template<class BidirectionalIterator, class Allocator>
|
| 1656 |
bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
|
| 1657 |
const match_results<BidirectionalIterator, Allocator>& m2);
|
|
|
|
| 1668 |
- `m1.size() == m2.size() && equal(m1.begin(), m1.end(), m2.begin())`,
|
| 1669 |
and
|
| 1670 |
- `m1.suffix() == m2.suffix()`.
|
| 1671 |
|
| 1672 |
[*Note 1*: The algorithm `equal` is defined in
|
| 1673 |
+
[[algorithms]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1674 |
|
| 1675 |
## Regular expression algorithms <a id="re.alg">[[re.alg]]</a>
|
| 1676 |
|
| 1677 |
### Exceptions <a id="re.except">[[re.except]]</a>
|
| 1678 |
|
| 1679 |
+
The algorithms described in subclause [[re.alg]] may throw an exception
|
| 1680 |
+
of type `regex_error`. If such an exception `e` is thrown, `e.code()`
|
| 1681 |
+
shall return either `regex_constants::error_complexity` or
|
| 1682 |
`regex_constants::error_stack`.
|
| 1683 |
|
| 1684 |
### `regex_match` <a id="re.alg.match">[[re.alg.match]]</a>
|
| 1685 |
|
| 1686 |
``` cpp
|
|
|
|
| 1689 |
match_results<BidirectionalIterator, Allocator>& m,
|
| 1690 |
const basic_regex<charT, traits>& e,
|
| 1691 |
regex_constants::match_flag_type flags = regex_constants::match_default);
|
| 1692 |
```
|
| 1693 |
|
| 1694 |
+
*Preconditions:* `BidirectionalIterator` meets the
|
| 1695 |
+
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]].
|
| 1696 |
|
| 1697 |
*Effects:* Determines whether there is a match between the regular
|
| 1698 |
expression `e`, and all of the character sequence \[`first`, `last`).
|
| 1699 |
The parameter `flags` is used to control how the expression is matched
|
| 1700 |
against the character sequence. When determining if there is a match,
|
|
|
|
| 1712 |
regex_match ("GetValues", m, re); // returns false
|
| 1713 |
```
|
| 1714 |
|
| 1715 |
— *end example*]
|
| 1716 |
|
| 1717 |
+
*Ensures:* `m.ready() == true` in all cases. If the function returns
|
| 1718 |
+
`false`, then the effect on parameter `m` is unspecified except that
|
| 1719 |
+
`m.size()` returns `0` and `m.empty()` returns `true`. Otherwise the
|
| 1720 |
+
effects on parameter `m` are given in [[re.alg.match]].
|
| 1721 |
|
| 1722 |
+
**Table: Effects of `regex_match` algorithm** <a id="re.alg.match">[re.alg.match]</a>
|
| 1723 |
|
| 1724 |
| Element | Value |
|
| 1725 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 1726 |
| `m.size()` | `1 + e.mark_count()` |
|
| 1727 |
| `m.empty()` | `false` |
|
|
|
|
| 1798 |
match_results<BidirectionalIterator, Allocator>& m,
|
| 1799 |
const basic_regex<charT, traits>& e,
|
| 1800 |
regex_constants::match_flag_type flags = regex_constants::match_default);
|
| 1801 |
```
|
| 1802 |
|
| 1803 |
+
*Preconditions:* `BidirectionalIterator` meets the
|
| 1804 |
+
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]].
|
| 1805 |
|
| 1806 |
*Effects:* Determines whether there is some sub-sequence within
|
| 1807 |
\[`first`, `last`) that matches the regular expression `e`. The
|
| 1808 |
parameter `flags` is used to control how the expression is matched
|
| 1809 |
against the character sequence. Returns `true` if such a sequence
|
| 1810 |
exists, `false` otherwise.
|
| 1811 |
|
| 1812 |
+
*Ensures:* `m.ready() == true` in all cases. If the function returns
|
| 1813 |
+
`false`, then the effect on parameter `m` is unspecified except that
|
| 1814 |
+
`m.size()` returns `0` and `m.empty()` returns `true`. Otherwise the
|
| 1815 |
+
effects on parameter `m` are given in [[re.alg.search]].
|
| 1816 |
|
| 1817 |
+
**Table: Effects of `regex_search` algorithm** <a id="re.alg.search">[re.alg.search]</a>
|
| 1818 |
|
| 1819 |
| Element | Value |
|
| 1820 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 1821 |
| `m.size()` | `1 + e.mark_count()` |
|
| 1822 |
| `m.empty()` | `false` |
|
|
|
|
| 2045 |
const regex_type&&,
|
| 2046 |
regex_constants::match_flag_type = regex_constants::match_default) = delete;
|
| 2047 |
regex_iterator(const regex_iterator&);
|
| 2048 |
regex_iterator& operator=(const regex_iterator&);
|
| 2049 |
bool operator==(const regex_iterator&) const;
|
|
|
|
| 2050 |
const value_type& operator*() const;
|
| 2051 |
const value_type* operator->() const;
|
| 2052 |
regex_iterator& operator++();
|
| 2053 |
regex_iterator operator++(int);
|
| 2054 |
|
|
|
|
| 2068 |
|
| 2069 |
[*Note 1*: For example, this can occur when the part of the regular
|
| 2070 |
expression that matched consists only of an assertion (such as `'^'`,
|
| 2071 |
`'$'`, `'\b'`, `'\B'`). — *end note*]
|
| 2072 |
|
| 2073 |
+
#### Constructors <a id="re.regiter.cnstr">[[re.regiter.cnstr]]</a>
|
| 2074 |
|
| 2075 |
``` cpp
|
| 2076 |
regex_iterator();
|
| 2077 |
```
|
| 2078 |
|
|
|
|
| 2083 |
const regex_type& re,
|
| 2084 |
regex_constants::match_flag_type m = regex_constants::match_default);
|
| 2085 |
```
|
| 2086 |
|
| 2087 |
*Effects:* Initializes `begin` and `end` to `a` and `b`, respectively,
|
| 2088 |
+
sets `pregex` to `addressof(re)`, sets `flags` to `m`, then calls
|
| 2089 |
`regex_search(begin, end, match, *pregex, flags)`. If this call returns
|
| 2090 |
`false` the constructor sets `*this` to the end-of-sequence iterator.
|
| 2091 |
|
| 2092 |
+
#### Comparisons <a id="re.regiter.comp">[[re.regiter.comp]]</a>
|
| 2093 |
|
| 2094 |
``` cpp
|
| 2095 |
bool operator==(const regex_iterator& right) const;
|
| 2096 |
```
|
| 2097 |
|
|
|
|
| 2104 |
- `flags == right.flags`, and
|
| 2105 |
- `match[0] == right.match[0]`;
|
| 2106 |
|
| 2107 |
otherwise `false`.
|
| 2108 |
|
| 2109 |
+
#### Indirection <a id="re.regiter.deref">[[re.regiter.deref]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2110 |
|
| 2111 |
``` cpp
|
| 2112 |
const value_type& operator*() const;
|
| 2113 |
```
|
| 2114 |
|
|
|
|
| 2116 |
|
| 2117 |
``` cpp
|
| 2118 |
const value_type* operator->() const;
|
| 2119 |
```
|
| 2120 |
|
| 2121 |
+
*Returns:* `addressof(match)`.
|
| 2122 |
|
| 2123 |
+
#### Increment <a id="re.regiter.incr">[[re.regiter.incr]]</a>
|
| 2124 |
|
| 2125 |
``` cpp
|
| 2126 |
regex_iterator& operator++();
|
| 2127 |
```
|
| 2128 |
|
|
|
|
| 2164 |
`regex_search`. — *end note*]
|
| 2165 |
|
| 2166 |
It is unspecified how the implementation makes these adjustments.
|
| 2167 |
|
| 2168 |
[*Note 2*: This means that a compiler may call an
|
| 2169 |
+
implementation-specific search function, in which case a program-defined
|
| 2170 |
specialization of `regex_search` will not be called. — *end note*]
|
| 2171 |
|
| 2172 |
``` cpp
|
| 2173 |
regex_iterator operator++(int);
|
| 2174 |
```
|
|
|
|
| 2284 |
regex_constants::match_flag_type m =
|
| 2285 |
regex_constants::match_default) = delete;
|
| 2286 |
regex_token_iterator(const regex_token_iterator&);
|
| 2287 |
regex_token_iterator& operator=(const regex_token_iterator&);
|
| 2288 |
bool operator==(const regex_token_iterator&) const;
|
|
|
|
| 2289 |
const value_type& operator*() const;
|
| 2290 |
const value_type* operator->() const;
|
| 2291 |
regex_token_iterator& operator++();
|
| 2292 |
regex_token_iterator operator++(int);
|
| 2293 |
|
|
|
|
| 2310 |
`suffix.first` points to the beginning of the final sequence, and
|
| 2311 |
`suffix.second` points to the end of the final sequence.
|
| 2312 |
|
| 2313 |
[*Note 1*: For a suffix iterator, data member `suffix.first` is the
|
| 2314 |
same as the end of the last match found, and `suffix.second` is the same
|
| 2315 |
+
as the end of the target sequence. — *end note*]
|
| 2316 |
|
| 2317 |
The *current match* is `(*position).prefix()` if `subs[N] == -1`, or
|
| 2318 |
`(*position)[subs[N]]` for any other value of `subs[N]`.
|
| 2319 |
|
| 2320 |
+
#### Constructors <a id="re.tokiter.cnstr">[[re.tokiter.cnstr]]</a>
|
| 2321 |
|
| 2322 |
``` cpp
|
| 2323 |
regex_token_iterator();
|
| 2324 |
```
|
| 2325 |
|
|
|
|
| 2346 |
const regex_type& re,
|
| 2347 |
const int (&submatches)[N],
|
| 2348 |
regex_constants::match_flag_type m = regex_constants::match_default);
|
| 2349 |
```
|
| 2350 |
|
| 2351 |
+
*Preconditions:* Each of the initialization values of `submatches` is
|
| 2352 |
`>= -1`.
|
| 2353 |
|
| 2354 |
*Effects:* The first constructor initializes the member `subs` to hold
|
| 2355 |
+
the single value `submatch`. The second, third, and fourth constructors
|
| 2356 |
+
initialize the member `subs` to hold a copy of the sequence of integer
|
| 2357 |
+
values pointed to by the iterator range \[`begin(submatches)`,
|
| 2358 |
+
`end(submatches)`).
|
|
|
|
|
|
|
| 2359 |
|
| 2360 |
Each constructor then sets `N` to 0, and `position` to
|
| 2361 |
`position_iterator(a, b, re, m)`. If `position` is not an
|
| 2362 |
end-of-sequence iterator the constructor sets `result` to the address of
|
| 2363 |
the current match. Otherwise if any of the values stored in `subs` is
|
| 2364 |
equal to -1 the constructor sets `*this` to a suffix iterator that
|
| 2365 |
points to the range \[`a`, `b`), otherwise the constructor sets `*this`
|
| 2366 |
to an end-of-sequence iterator.
|
| 2367 |
|
| 2368 |
+
#### Comparisons <a id="re.tokiter.comp">[[re.tokiter.comp]]</a>
|
| 2369 |
|
| 2370 |
``` cpp
|
| 2371 |
bool operator==(const regex_token_iterator& right) const;
|
| 2372 |
```
|
| 2373 |
|
|
|
|
| 2376 |
`suffix == right.suffix`; otherwise returns `false` if `*this` or
|
| 2377 |
`right` is an end-of-sequence iterator or a suffix iterator. Otherwise
|
| 2378 |
returns `true` if `position == right.position`, `N == right.N`, and
|
| 2379 |
`subs == right.subs`. Otherwise returns `false`.
|
| 2380 |
|
| 2381 |
+
#### Indirection <a id="re.tokiter.deref">[[re.tokiter.deref]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2382 |
|
| 2383 |
``` cpp
|
| 2384 |
const value_type& operator*() const;
|
| 2385 |
```
|
| 2386 |
|
|
|
|
| 2390 |
const value_type* operator->() const;
|
| 2391 |
```
|
| 2392 |
|
| 2393 |
*Returns:* `result`.
|
| 2394 |
|
| 2395 |
+
#### Increment <a id="re.tokiter.incr">[[re.tokiter.incr]]</a>
|
| 2396 |
|
| 2397 |
``` cpp
|
| 2398 |
regex_token_iterator& operator++();
|
| 2399 |
```
|
| 2400 |
|
|
|
|
| 2443 |
the appropriate traits member function to achieve the required effect.
|
| 2444 |
|
| 2445 |
The following productions within the ECMAScript grammar are modified as
|
| 2446 |
follows:
|
| 2447 |
|
| 2448 |
+
``` bnf
|
| 2449 |
ClassAtom::
|
| 2450 |
+
'-'
|
| 2451 |
ClassAtomNoDash
|
| 2452 |
ClassAtomExClass
|
| 2453 |
ClassAtomCollatingElement
|
| 2454 |
ClassAtomEquivalence
|
| 2455 |
|
| 2456 |
IdentityEscape::
|
| 2457 |
+
SourceCharacter but not 'c'
|
| 2458 |
```
|
| 2459 |
|
| 2460 |
The following new productions are then added:
|
| 2461 |
|
| 2462 |
+
``` bnf
|
| 2463 |
ClassAtomExClass::
|
| 2464 |
+
'[:' ClassName ':]'
|
| 2465 |
|
| 2466 |
ClassAtomCollatingElement::
|
| 2467 |
+
'[.' ClassName '.]'
|
| 2468 |
|
| 2469 |
ClassAtomEquivalence::
|
| 2470 |
+
'[=' ClassName '=]'
|
| 2471 |
|
| 2472 |
ClassName::
|
| 2473 |
ClassNameCharacter
|
| 2474 |
ClassNameCharacter ClassName
|
| 2475 |
|
| 2476 |
ClassNameCharacter::
|
| 2477 |
+
SourceCharacter but not one of '.' or '=' or ':'
|
| 2478 |
```
|
| 2479 |
|
| 2480 |
+
The productions , and provide functionality equivalent to that of the
|
|
|
|
| 2481 |
same features in regular expressions in POSIX.
|
| 2482 |
|
| 2483 |
The regular expression grammar may be modified by any
|
| 2484 |
`regex_constants::syntax_option_type` flags specified when constructing
|
| 2485 |
an object of type specialization of `basic_regex` according to the rules
|
| 2486 |
+
in [[re.synopt]].
|
| 2487 |
|
| 2488 |
+
A production, when used in , is not valid if
|
| 2489 |
+
`traits_inst.lookup_classname` returns zero for that name. The names
|
| 2490 |
+
recognized as valid s are determined by the type of the traits class,
|
| 2491 |
+
but at least the following names shall be recognized: `alnum`, `alpha`,
|
| 2492 |
+
`blank`, `cntrl`, `digit`, `graph`, `lower`, `print`, `punct`, `space`,
|
| 2493 |
+
`upper`, `xdigit`, `d`, `s`, `w`. In addition the following expressions
|
| 2494 |
+
shall be equivalent:
|
| 2495 |
|
| 2496 |
``` cpp
|
| 2497 |
\d and [[:digit:]]
|
| 2498 |
|
| 2499 |
\D and [^[:digit:]]
|
|
|
|
| 2505 |
\w and [_[:alnum:]]
|
| 2506 |
|
| 2507 |
\W and [^_[:alnum:]]
|
| 2508 |
```
|
| 2509 |
|
| 2510 |
+
A production when used in a production is not valid if the value
|
| 2511 |
+
returned by `traits_inst.lookup_collatename` for that name is an empty
|
| 2512 |
+
string.
|
| 2513 |
|
| 2514 |
The results from multiple calls to `traits_inst.lookup_classname` can be
|
| 2515 |
+
bitwise ’ed together and subsequently passed to `traits_inst.isctype`.
|
| 2516 |
|
| 2517 |
+
A production when used in a production is not valid if the value
|
| 2518 |
+
returned by `traits_inst.lookup_collatename` for that name is an empty
|
| 2519 |
+
string or if the value returned by `traits_inst.transform_primary` for
|
| 2520 |
+
the result of the call to `traits_inst.lookup_collatename` is an empty
|
| 2521 |
+
string.
|
| 2522 |
|
| 2523 |
When the sequence of characters being transformed to a finite state
|
| 2524 |
machine contains an invalid class name the translator shall throw an
|
| 2525 |
exception object of type `regex_error`.
|
| 2526 |
|
|
|
|
| 2535 |
sequence of characters to an integral value, this is accomplished by
|
| 2536 |
calling `traits_inst.value`.
|
| 2537 |
|
| 2538 |
The behavior of the internal finite state machine representation when
|
| 2539 |
used to match a sequence of characters is as described in ECMA-262. The
|
| 2540 |
+
behavior is modified according to any `match_flag_type` flags
|
| 2541 |
+
[[re.matchflag]] specified when using the regular expression object in
|
| 2542 |
+
one of the regular expression algorithms [[re.alg]]. The behavior is
|
| 2543 |
also localized by interaction with the traits class template parameter
|
| 2544 |
as follows:
|
| 2545 |
|
| 2546 |
- During matching of a regular expression finite state machine against a
|
| 2547 |
sequence of characters, two characters `c` and `d` are compared using
|
|
|
|
| 2554 |
`traits_inst.translate(c) == traits_inst.translate(d)`;
|
| 2555 |
- otherwise, the two characters are equal if `c == d`.
|
| 2556 |
- During matching of a regular expression finite state machine against a
|
| 2557 |
sequence of characters, comparison of a collating element range
|
| 2558 |
`c1-c2` against a character `c` is conducted as follows: if
|
| 2559 |
+
`flags() & regex_constants::collate` is `false` then the character `c`
|
| 2560 |
is matched if `c1
|
| 2561 |
<= c && c <= c2`, otherwise `c` is matched in accordance with the
|
| 2562 |
following algorithm:
|
| 2563 |
``` cpp
|
| 2564 |
string_type str1 = string_type(1,
|
| 2565 |
flags() & icase ?
|
| 2566 |
+
traits_inst.translate_nocase(c1) : traits_inst.translate(c1));
|
| 2567 |
string_type str2 = string_type(1,
|
| 2568 |
flags() & icase ?
|
| 2569 |
+
traits_inst.translate_nocase(c2) : traits_inst.translate(c2));
|
| 2570 |
string_type str = string_type(1,
|
| 2571 |
flags() & icase ?
|
| 2572 |
+
traits_inst.translate_nocase(c) : traits_inst.translate(c));
|
| 2573 |
return traits_inst.transform(str1.begin(), str1.end())
|
| 2574 |
<= traits_inst.transform(str.begin(), str.end())
|
| 2575 |
&& traits_inst.transform(str.begin(), str.end())
|
| 2576 |
<= traits_inst.transform(str2.begin(), str2.end());
|
| 2577 |
```
|
|
|
|
| 2585 |
sequence of characters, a character `c` is a member of a character
|
| 2586 |
class designated by an iterator range \[`first`, `last`) if
|
| 2587 |
`traits_inst.isctype(c, traits_inst.lookup_classname(first, last, flags() & icase))`
|
| 2588 |
is `true`.
|
| 2589 |
|
| 2590 |
+
ECMA-262 15.10
|
| 2591 |
+
|
| 2592 |
<!-- Link reference definitions -->
|
| 2593 |
[algorithms]: algorithms.md#algorithms
|
| 2594 |
[bidirectional.iterators]: iterators.md#bidirectional.iterators
|
| 2595 |
[bitmask.types]: library.md#bitmask.types
|
| 2596 |
[container.requirements.general]: containers.md#container.requirements.general
|
|
|
|
| 2612 |
[re.grammar]: #re.grammar
|
| 2613 |
[re.iter]: #re.iter
|
| 2614 |
[re.matchflag]: #re.matchflag
|
| 2615 |
[re.regex]: #re.regex
|
| 2616 |
[re.regex.assign]: #re.regex.assign
|
|
|
|
| 2617 |
[re.regex.construct]: #re.regex.construct
|
| 2618 |
[re.regex.locale]: #re.regex.locale
|
|
|
|
| 2619 |
[re.regex.nonmemb]: #re.regex.nonmemb
|
| 2620 |
[re.regex.operations]: #re.regex.operations
|
| 2621 |
[re.regex.swap]: #re.regex.swap
|
| 2622 |
[re.regiter]: #re.regiter
|
| 2623 |
[re.regiter.cnstr]: #re.regiter.cnstr
|
|
|
|
| 2635 |
[re.results.state]: #re.results.state
|
| 2636 |
[re.results.swap]: #re.results.swap
|
| 2637 |
[re.submatch]: #re.submatch
|
| 2638 |
[re.submatch.members]: #re.submatch.members
|
| 2639 |
[re.submatch.op]: #re.submatch.op
|
| 2640 |
+
[re.summary]: #re.summary
|
| 2641 |
[re.syn]: #re.syn
|
| 2642 |
[re.synopt]: #re.synopt
|
| 2643 |
[re.tokiter]: #re.tokiter
|
| 2644 |
[re.tokiter.cnstr]: #re.tokiter.cnstr
|
| 2645 |
[re.tokiter.comp]: #re.tokiter.comp
|
| 2646 |
[re.tokiter.deref]: #re.tokiter.deref
|
| 2647 |
[re.tokiter.incr]: #re.tokiter.incr
|
| 2648 |
[re.traits]: #re.traits
|
| 2649 |
+
[re.traits.classnames]: #re.traits.classnames
|
| 2650 |
[sequence.reqmts]: containers.md#sequence.reqmts
|
| 2651 |
[strings.general]: strings.md#strings.general
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2652 |
|
| 2653 |
[^1]: For example, if the parameter `icase` is `true` then `[[:lower:]]`
|
| 2654 |
is the same as `[[:alpha:]]`.
|