boost::xpressive::match_results — 类模板 match_results<> 将 regex_match() 或 regex_search() 的结果保存为一组 sub_match 对象。
// In header: <boost/xpressive/match_results.hpp> template<typename BidiIter> struct match_results { // types typedef iterator_value< BidiIter >::type char_type; typedef unspecified string_type; typedef std::size_t size_type; typedef sub_match< BidiIter > value_type; typedef iterator_difference< BidiIter >::type difference_type; typedef value_type const & reference; typedef value_type const & const_reference; typedef unspecified iterator; typedef unspecified const_iterator; typedef unspecified nested_results_type; // public member functions match_results(); match_results(match_results< BidiIter > const &); ~match_results(); match_results< BidiIter > & operator=(match_results< BidiIter > const &); size_type size() const; bool empty() const; difference_type length(size_type = 0) const; difference_type position(size_type = 0) const; string_type str(size_type = 0) const; template<typename Sub> const_reference operator[](Sub const &) const; const_reference prefix() const; const_reference suffix() const; const_iterator begin() const; const_iterator end() const; operator bool_type() const; bool operator!() const; regex_id_type regex_id() const; nested_results_type const & nested_results() const; template<typename Format, typename OutputIterator> OutputIterator format(OutputIterator, Format const &, regex_constants::match_flag_type = regex_constants::format_default, unspecified = 0) const; template<typename OutputIterator> OutputIterator format(OutputIterator, char_type const *, regex_constants::match_flag_type = regex_constants::format_default) const; template<typename Format, typename OutputIterator> string_type format(Format const &, regex_constants::match_flag_type = regex_constants::format_default, unspecified = 0) const; string_type format(char_type const *, regex_constants::match_flag_type = regex_constants::format_default) const; void swap(match_results< BidiIter > &); template<typename Arg> match_results< BidiIter > & let(Arg const &); };
类模板 match_results<> 表示一个序列集合,代表正则表达式匹配的结果。该集合的存储由类 match_results<> 的成员函数按需分配和释放。
类模板 match_results<> 符合 Sequence 的要求,如 (lib.sequence.reqmts) 中所述,但只支持为 const 限定的 Sequences 定义的操作。
match_results 公有成员函数match_results();
后置条件 |
regex_id() == 0 |
后置条件 |
size() == 0 |
后置条件 |
empty() == true |
后置条件 |
match_results(match_results< BidiIter > const & that);
参数 |
|
||
后置条件 |
regex_id() == that.regex_id()。 |
||
后置条件 |
size() == that.size()。 |
||
后置条件 |
empty() == that.empty()。 |
||
后置条件 |
str(n) == that.str(n),对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
prefix() == that.prefix()。 |
||
后置条件 |
suffix() == that.suffix()。 |
||
后置条件 |
(*this)[n] == that[n],对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
length(n) == that.length(n),对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
position(n) == that.position(n),对于所有小于 that.size() 的正整数 n。 |
~match_results();
match_results< BidiIter > & operator=(match_results< BidiIter > const & that);
参数 |
|
||
后置条件 |
regex_id() == that.regex_id()。 |
||
后置条件 |
size() == that.size()。 |
||
后置条件 |
empty() == that.empty()。 |
||
后置条件 |
str(n) == that.str(n),对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
prefix() == that.prefix()。 |
||
后置条件 |
suffix() == that.suffix()。 |
||
后置条件 |
(*this)[n] == that[n],对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
length(n) == that.length(n),对于所有小于 that.size() 的正整数 n。 |
||
后置条件 |
position(n) == that.position(n),对于所有小于 that.size() 的正整数 n。 |
size_type size() const;
如果 *this 表示成功匹配的结果,则返回匹配的正则表达式中标记的子表达式数量加一。否则返回 0。
bool empty() const;
返回 size() == 0。
difference_type length(size_type sub = 0) const;
返回 (*this)[sub].length()。
difference_type position(size_type sub = 0) const;
如果 !(*this)[sub].matched,则返回 -1。否则返回 std::distance(base, (*this)[sub].first),其中 base 是被搜索序列的起始迭代器。[注意 - 除非这是与 regex_iterator 的重复搜索的一部分,否则 base 与 prefix().first - end note 相同]
string_type str(size_type sub = 0) const;
返回 (*this)[sub].str()。
template<typename Sub> const_reference operator[](Sub const & sub) const;
返回一个指向 sub_match 对象的引用,该对象表示匹配整个正则表达式的序列。如果 sub == 0,则返回一个指向 sub_match 对象的引用,该对象表示匹配整个正则表达式的序列。如果 sub >= size(),则返回一个 sub_match 对象,表示一个未匹配的子表达式。
const_reference prefix() const;
返回一个指向 sub_match 对象的引用,该对象表示从被匹配/搜索字符串的开始到找到的匹配的开始的字符序列。
要求 |
(*this)[0].matched 为 true |
const_reference suffix() const;
返回一个指向 sub_match 对象的引用,该对象表示从找到的匹配的结束到被匹配/搜索字符串的结束的字符序列。
要求 |
(*this)[0].matched 为 true |
const_iterator begin() const;
返回一个起始迭代器,该迭代器枚举 *this 中存储的所有标记的子表达式匹配。
const_iterator end() const;
返回一个终止迭代器,该迭代器枚举 *this 中存储的所有标记的子表达式匹配。
operator bool_type() const;
如果 (*this)[0].matched 为 true,则返回 true,否则返回 false。
bool operator!() const;
如果 empty() || !(*this)[0].matched,则返回 true,否则返回 false。
regex_id_type regex_id() const;
返回最近与此 match_results 对象一起使用的 basic_regex 对象的 ID。
nested_results_type const & nested_results() const;
返回一个嵌套 match_results 元素的 Sequence。
template<typename Format, typename OutputIterator> OutputIterator format(OutputIterator out, Format const & fmt, regex_constants::match_flag_type flags = regex_constants::format_default, unspecified = 0) const;
如果 Format 符合 ForwardRange 或是一个空终止字符串,则此函数将 fmt 中的字符序列复制到 OutputIterator out。对于 fmt 中的每个格式说明符或转义序列,用它所代表的字符(或字符)或它所引用的 *this 中的序列来替换该序列。flags 中指定的位掩码决定了哪些格式说明符或转义序列被识别。默认情况下,这是 ECMA-262、ECMAScript Language Specification、Chapter 15 part 5.4.11 String.prototype.replace 使用的格式。
否则,如果 Format 符合 Callable<match_results<BidiIter>, OutputIterator, regex_constants::match_flag_type>,则此函数返回 fmt(*this, out, flags)。
否则,如果 Format 符合 Callable<match_results<BidiIter>, OutputIterator>,则此函数返回 fmt(*this, out)。
否则,如果 Format 符合 Callable<match_results<BidiIter> >,则此函数返回 std::copy(x.begin(), x.end(), out),其中 x 是调用 fmt(*this) 的结果。
template<typename OutputIterator> OutputIterator format(OutputIterator out, char_type const * fmt, regex_constants::match_flag_type flags = regex_constants::format_default) const;
这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。
template<typename Format, typename OutputIterator> string_type format(Format const & fmt, regex_constants::match_flag_type flags = regex_constants::format_default, unspecified = 0) const;
如果 Format 符合 ForwardRange 或是一个空终止字符串,则此函数返回 fmt 字符序列的副本。对于 fmt 中的每个格式说明符或转义序列,用它所代表的字符(或字符)或它所引用的 *this 中的序列来替换该序列。flags 中指定的位掩码决定了哪些格式说明符或转义序列被识别。默认情况下,这是 ECMA-262、ECMAScript Language Specification、Chapter 15 part 5.4.11 String.prototype.replace 使用的格式。
否则,如果 Format 符合 Callable<match_results<BidiIter>, OutputIterator, regex_constants::match_flag_type>,则此函数返回一个 string_type 对象 x,该对象通过调用 fmt(*this, out, flags) 填充,其中 out 是 x 的一个 back_insert_iterator。
否则,如果 Format 符合 Callable<match_results<BidiIter>, OutputIterator>,则此函数返回一个 string_type 对象 x,该对象通过调用 fmt(*this, out) 填充,其中 out 是 x 的一个 back_insert_iterator。
否则,如果 Format 符合 Callable<match_results<BidiIter> >,则此函数返回 fmt(*this)。
string_type format(char_type const * fmt, regex_constants::match_flag_type flags = regex_constants::format_default) const;
这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。
void swap(match_results< BidiIter > & that);
交换两个 match_results 对象的内容。保证不抛出异常。
参数 |
|
||
后置条件 |
*this 包含 that 中存在的已匹配子表达式序列,that 包含 that 中存在的已匹配子表达式序列,*this 包含 *this 中存在的已匹配子表达式序列。 |
||
抛出 |
不会抛出异常。 |
template<typename Arg> match_results< BidiIter > & let(Arg const & arg);
TODO:文档记录