Files
2025-10-25 03:02:53 +03:00

274 lines
9.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[re.regiter]
# 28 Text processing library [[text]](./#text)
## 28.6 Regular expressions library [[re]](re#regiter)
### 28.6.11 Regular expression iterators [[re.iter]](re.iter#re.regiter)
#### 28.6.11.1 Class template regex_iterator [re.regiter]
#### [28.6.11.1.1](#general) General [[re.regiter.general]](re.regiter.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12225)
The class template regex_iterator is an iterator adaptor[.](#general-1.sentence-1)
It represents a new view of an existing iterator sequence, by
enumerating all the occurrences of a regular expression within that
sequence[.](#general-1.sentence-2)
A regex_iterator uses regex_search to find successive
regular expression matches within the sequence from which it was
constructed[.](#general-1.sentence-3)
After the iterator is constructed, and every time operator++ is
used, the iterator finds and stores a value ofmatch_results<BidirectionalIterator>[.](#general-1.sentence-4)
If the end of the sequence is
reached (regex_search returns false), the iterator becomes equal to
the end-of-sequence iterator value[.](#general-1.sentence-5)
The default constructor
constructs an end-of-sequence iterator object,
which is the only legitimate iterator to be used for the end
condition[.](#general-1.sentence-6)
The result of operator* on an end-of-sequence iterator is not
defined[.](#general-1.sentence-7)
For any other iterator value aconst match_results<BidirectionalIterator>& is returned[.](#general-1.sentence-8)
The result ofoperator-> on an end-of-sequence iterator is not defined[.](#general-1.sentence-9)
For any other
iterator value a const match_results<BidirectionalIterator>* is
returned[.](#general-1.sentence-10)
It is impossible to store things into regex_iterators[.](#general-1.sentence-11)
Two
end-of-sequence iterators are always equal[.](#general-1.sentence-12)
An end-of-sequence
iterator is not equal to a non-end-of-sequence iterator[.](#general-1.sentence-13)
Two
non-end-of-sequence iterators are equal when they are constructed from
the same arguments[.](#general-1.sentence-14)
namespace std {template<class BidirectionalIterator, class charT = typename iterator_traits<BidirectionalIterator>::value_type, class traits = regex_traits<charT>>class regex_iterator {public:using regex_type = basic_regex<charT, traits>; using iterator_category = forward_iterator_tag; using iterator_concept = input_iterator_tag; using value_type = match_results<BidirectionalIterator>; using difference_type = ptrdiff_t; using pointer = const value_type*; using reference = const value_type&;
regex_iterator();
regex_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_iterator(BidirectionalIterator, BidirectionalIterator, const regex_type&&,
regex_constants::match_flag_type = regex_constants::match_default) = delete;
regex_iterator(const regex_iterator&);
regex_iterator& operator=(const regex_iterator&); bool operator==(const regex_iterator&) const; bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }const value_type& operator*() const; const value_type* operator->() const;
regex_iterator& operator++();
regex_iterator operator++(int); private: BidirectionalIterator begin; // *exposition only* BidirectionalIterator end; // *exposition only*const regex_type* pregex; // *exposition only* regex_constants::match_flag_type flags; // *exposition only* match_results<BidirectionalIterator> match; // *exposition only*};}
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12292)
An object of type regex_iterator that is not an end-of-sequence iterator
holds a *zero-length match* if match[0].matched == true andmatch[0].first == match[0].second[.](#general-2.sentence-1)
[*Note [1](#general-note-1)*:
For
example, this can occur when the part of the regular expression that
matched consists only of an assertion (such as `'^'`, `'$'`,'\b', '\B')[.](#general-2.sentence-2)
— *end note*]
#### [28.6.11.1.2](#cnstr) Constructors [[re.regiter.cnstr]](re.regiter.cnstr)
[🔗](#lib:regex_iterator,constructor)
`regex_iterator();
`
[1](#cnstr-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12311)
*Effects*: Constructs an end-of-sequence iterator[.](#cnstr-1.sentence-1)
[🔗](#lib:regex_iterator,constructor_)
`regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
regex_constants::match_flag_type m = regex_constants::match_default);
`
[2](#cnstr-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12324)
*Effects*: Initializes begin and end toa and b, respectively, setspregex to addressof(re), sets flags tom, then calls regex_search(begin, end, match, *pregex, flags)[.](#cnstr-2.sentence-1)
If this
call returns false the constructor sets *this to the end-of-sequence
iterator[.](#cnstr-2.sentence-2)
#### [28.6.11.1.3](#comp) Comparisons [[re.regiter.comp]](re.regiter.comp)
[🔗](#lib:regex_iterator,operator==)
`bool operator==(const regex_iterator& right) const;
`
[1](#comp-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12342)
*Returns*: true if *this and right are both end-of-sequence
iterators or if the following conditions all hold:
- [(1.1)](#comp-1.1)
begin == right.begin,
- [(1.2)](#comp-1.2)
end == right.end,
- [(1.3)](#comp-1.3)
pregex == right.pregex,
- [(1.4)](#comp-1.4)
flags == right.flags, and
- [(1.5)](#comp-1.5)
match[0] == right.match[0];
otherwise false[.](#comp-1.sentence-1)
#### [28.6.11.1.4](#deref) Indirection [[re.regiter.deref]](re.regiter.deref)
[🔗](#lib:regex_iterator,operator*)
`const value_type& operator*() const;
`
[1](#deref-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12364)
*Returns*: match[.](#deref-1.sentence-1)
[🔗](#lib:operator-%3e,regex_iterator)
`const value_type* operator->() const;
`
[2](#deref-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12375)
*Returns*: addressof(match)[.](#deref-2.sentence-1)
#### [28.6.11.1.5](#incr) Increment [[re.regiter.incr]](re.regiter.incr)
[🔗](#lib:regex_iterator,operator++)
`regex_iterator& operator++();
`
[1](#incr-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12389)
*Effects*: Constructs a local variable start of type BidirectionalIterator and
initializes it with the value of match[0].second[.](#incr-1.sentence-1)
[2](#incr-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12394)
If the iterator holds a zero-length match and start == end the operator
sets *this to the end-of-sequence iterator and returns *this[.](#incr-2.sentence-1)
[3](#incr-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12398)
Otherwise, if the iterator holds a zero-length match, the operator calls:regex_search(start, end, match, *pregex,
flags | regex_constants::match_not_null | regex_constants::match_continuous)
If the call returns true the operator
returns *this[.](#incr-3.sentence-2)
Otherwise the operator increments start and continues as if
the most recent match was not a zero-length match[.](#incr-3.sentence-3)
[4](#incr-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12410)
If the most recent match was not a zero-length match, the operator setsflags to flags | regex_constants::match_prev_avail and
calls regex_search(start, end, match, *pregex, flags)[.](#incr-4.sentence-1)
If the call returnsfalse the iterator sets *this to the end-of-sequence iterator[.](#incr-4.sentence-2)
The
iterator then returns *this[.](#incr-4.sentence-3)
[5](#incr-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12418)
In all cases in which the call to regex_search returns true,match.prefix().first shall be equal to the previous value ofmatch[0].second, and for each index i in the half-open range
[0, match.size()) for which match[i].matched is true,match.position(i) shall return distance(begin, match[i].first)[.](#incr-5.sentence-1)
[6](#incr-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12426)
[*Note [1](#incr-note-1)*:
This means that match.position(i) gives the
offset from the beginning of the target sequence, which is often not
the same as the offset from the sequence passed in the call
to regex_search[.](#incr-6.sentence-1)
— *end note*]
[7](#incr-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12434)
It is unspecified how the implementation makes these adjustments[.](#incr-7.sentence-1)
[8](#incr-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12437)
[*Note [2](#incr-note-2)*:
This means that an implementation can call an
implementation-specific search function, in which case a program-defined
specialization of regex_search will not be
called[.](#incr-8.sentence-1)
— *end note*]
[🔗](#lib:regex_iterator,operator++_)
`regex_iterator operator++(int);
`
[9](#incr-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12452)
*Effects*: As if by:regex_iterator tmp = *this;++(*this);return tmp;