std::regex_token_iterator
来自cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
template< class BidirIt, |
(C++11 起) | |
std::regex_token_iterator
是一个只读的ForwardIterator
访问的各个子匹配正则表达式的的底层字符序列内的每场比赛。它也可以被用于访问由给定的正则表达式(例如,作为一个tokenizer)不匹配的部分的序列.Original:
std::regex_token_iterator
is a read-only ForwardIterator
that accesses the individual sub-matches of every match of a regular expression within the underlying character sequence. It can also be used to access the parts of the sequence that were not matched by the given regular expression (e.g. as a tokenizer).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
在建筑上,它构造了一个std::regex_iterator每增加步骤,通过请求的子匹配从目前的match_results,递增的基础regex_iterator递增距离最后的个子匹配时,.
Original:
On construction, it constructs an std::regex_iterator and on every increment it steps through the requested sub-matches from the current match_results, incrementing the underlying regex_iterator when incrementing away from the last submatch.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
默认构造
std::regex_token_iterator
是最终的序列迭代器。当一个有效的std::regex_token_iterator
后递增到达最后的submatch的最后匹配,它变得等于序列结束迭代器。提领或递增的进一步调用未定义的行为.Original:
The default-constructed
std::regex_token_iterator
is the end-of-sequence iterator. When a valid std::regex_token_iterator
is incremented after reaching the last submatch of the last match, it becomes equal to the end-of-sequence iterator. Dereferencing or incrementing it further invokes undefined behavior.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
成为最终的序列的迭代器,前std::regex_token_iterator可能成为一个“后缀迭代器”,如果该指数-1(非匹配片段)出现在列表中的子匹配的指标。这样的迭代器,如果废弃时,返回一个match_results相应的字符序列之间的最后一场比赛结束的序列.
Original:
Just before becoming the end-of-sequence iterator, a std::regex_token_iterator may become a suffix iterator, if the index -1 (non-matched fragment) appears in the list of the requested submatch indexes. Such iterator, if dereferenced, returns a match_results corresponding to the sequence of characters between the last match and the end of sequence.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
一个典型的实施
std::regex_token_iterator
持有底层std::regex_iterator的请求的submatch索引,一个容器(例如std::vector<int>),内部计数器等于子匹配的索引,指针std::match_results指向当前匹配当前的submatch,和一个std::match_results对象,其中包含的最后一个非匹配的字符序列(用来标记生成模式).Original:
A typical implementation of
std::regex_token_iterator
holds the underlying std::regex_iterator, a container (e.g. std::vector<int>) of the requested submatch indexes, the internal counter equal to the index of the submatch, a pointer to std::match_results, pointing at the current submatch of the current match, and a std::match_results object containing the last non-matched character sequence (used in tokenizer mode).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 类型要求
-BidirIt must meet the requirements of BidirectionalIterator .
|
[编辑] 专业化
常见的字符序列类型的几个专业的定义
Original:
Several specializations for common character sequence types are defined:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Defined in header
<regex> | |
类型
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
cregex_token_iterator
|
regex_token_iterator<const char*> |
wcregex_token_iterator
|
regex_token_iterator<const wchar_t*> |
sregex_token_iterator
|
regex_token_iterator<std::string::const_iterator> |
wsregex_token_iterator
|
regex_token_iterator<std::wstring::const_iterator> |
[编辑] 会员类型
会员类型
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
std::sub_match<BidirIt> |
difference_type
|
std::ptrdiff_t |
pointer
|
const value_type* |
reference
|
const value_type& |
iterator_category
|
std::forward_iterator_tag |
regex_type
|
basic_regex<CharT, Traits> |
[编辑] 成员函数
构造一个新的regex_token_iterator Original: constructs a new regex_token_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
(destructor) (隐式声明) |
destructs a regex_token_iterator, including the cached value (公共成员函数) |
取代了regex_token_iterator Original: replaces a regex_token_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
比较2 regex_token_iterators Original: compares two regex_token_iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
accsses当前的submatch Original: accsses current submatch The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
regex_token_iterator推进到下一个子匹配的 Original: advances the regex_token_iterator to the next submatch The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) |
[编辑] 注释
这是程序员的责任,以确保std::basic_regex对象传递给迭代器的构造函数会超越的迭代器。因为迭代器存储std::regex_iterator存储一个指向正则表达式,递增迭代器的正则表达式被破坏后导致未定义的行为.
Original:
It is the programmer's responsibility to ensure that the std::basic_regex object passed to the iterator's constructor outlives the iterator. Because the iterator stores a std::regex_iterator which stores a pointer to the regex, incrementing the iterator after the regex was destroyed results in undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <fstream> #include <iostream> #include <algorithm> #include <iterator> #include <regex> int main() { std::string text = "Quick brown fox."; // tokenization (non-matched fragments) // Note that regex is matched only two times: when the third value is obtained // the iterator is a suffix iterator. std::regex ws_re("\\s+"); // whitespace std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1), std::sregex_token_iterator(), std::ostream_iterator<std::string>(std::cout, "\n")); // iterating the first submatches std::string html = "<p><a href=\"http://google.com\">google</a> " "< a HREF =\"http://cppreference.com\">cppreference</a>\n</p>"; std::regex url_re("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", std::regex::icase); std::copy( std::sregex_token_iterator(html.begin(), html.end(), url_re, 1), std::sregex_token_iterator(), std::ostream_iterator<std::string>(std::cout, "\n")); }
Output:
Quick brown fox. http://google.com http://cppreference.com