Boost C++ 库

……世界上评价最高、设计最精妙的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

结构体模板 match_results - Boost C++ 函数库
PrevUpHomeNext

结构体模板 match_results

boost::xpressive::match_results — 类模板 match_results<> 保存 regex_match()regex_search() 的结果,作为 sub_match 对象的集合。

提要

// In header: <boost/xpressive/xpressive_fwd.hpp>

template<typename BidiIter> 
struct match_results {

  // 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<> 符合 (lib.sequence.reqmts) 中指定的 Sequence 的要求,但只支持为 const 限定的 Sequences 定义的操作。

match_results 公共成员函数

  1. match_results();

    后置条件

    regex_id() == 0

    后置条件

    size() == 0

    后置条件

    empty() == true

    后置条件

    str() == string_type()

  2. match_results(match_results< BidiIter > const & that);

    参数

    那个

    要复制的 match_results 对象

    后置条件

    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。

  3. ~match_results();
  4. match_results< BidiIter > & operator=(match_results< BidiIter > const & that);

    参数

    那个

    要复制的 match_results 对象。

    后置条件

    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。

  5. size_type size() const;

    如果 *this 代表成功匹配的结果,则返回比最近用于匹配的正则表达式中的标记子表达式数量多一个的值。否则返回 0。

  6. bool empty() const;

    返回 size() == 0。

  7. difference_type length(size_type sub = 0) const;

    返回 (*this)[sub].length()

  8. difference_type position(size_type sub = 0) const;

    如果 !(*this)[sub].matched 则返回 -1。否则返回 std::distance(base, (*this)[sub].first),其中 base 是被搜索序列的起始迭代器。[注意 - 除非这是与 regex_iterator 的重复搜索的一部分,否则 base 与 prefix().first 相同 - 结束注意]

  9. string_type str(size_type sub = 0) const;

    返回 (*this)[sub].str()

  10. template<typename Sub> const_reference operator[](Sub const & sub) const;

    返回表示与标记子表达式 sub 匹配的序列的 sub_match 对象。如果 sub == 0,则返回表示与整个正则表达式匹配的序列的 sub_match 对象。如果 sub >= size(),则返回一个表示未匹配子表达式的 sub_match 对象。

  11. const_reference prefix() const;

    返回表示从被匹配/搜索的字符串开头到找到的匹配开头的字符序列的 sub_match 对象。

    要求

    (*this)[0].matched 为 true

  12. const_reference suffix() const;

    返回表示从找到的匹配结尾到被匹配/搜索的字符串结尾的字符序列的 sub_match 对象。

    要求

    (*this)[0].matched 为 true

  13. const_iterator begin() const;

    返回一个起始迭代器,该迭代器枚举 *this 中存储的所有标记子表达式匹配。

  14. const_iterator end() const;

    返回一个终止迭代器,该迭代器枚举 *this 中存储的所有标记子表达式匹配。

  15. operator bool_type() const;

    如果 (*this)[0].matched,则返回 true,否则返回 false。

  16. bool operator!() const;

    如果 empty() || !(*this)[0].matched,则返回 true,否则返回 false。

  17. regex_id_type regex_id() const;

    返回最近与此 match_results 对象一起使用的 basic_regex 对象的 ID。

  18. nested_results_type const & nested_results() const;

    返回嵌套 match_results 元素的 Sequence。

  19. 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) 的结果。

  20. template<typename OutputIterator> 
      OutputIterator 
      format(OutputIterator out, char_type const * fmt, 
             regex_constants::match_flag_type flags = regex_constants::format_default) const;

    这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。

  21. 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) 填充,其中 outx 的一个 back_insert_iterator

    否则,如果 Format 建模 Callable<match_results<BidiIter>, OutputIterator>,则此函数返回一个 string_type 对象 x,该对象通过调用 fmt(*this, out) 填充,其中 outx 的一个 back_insert_iterator

    否则,如果 Format 建模 Callable<match_results<BidiIter> >,则此函数返回 fmt(*this)

  22. string_type format(char_type const * fmt, 
                       regex_constants::match_flag_type flags = regex_constants::format_default) const;

    这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。

  23. void swap(match_results< BidiIter > & that);

    交换两个 match_results 对象的内容。保证不抛出异常。

    参数

    那个

    要与之交换的 match_results 对象。

    后置条件

    *this 包含 that 中的已匹配子表达式序列,that 包含 *this 中的已匹配子表达式序列。

    抛出

    不会抛出异常。
  24. template<typename Arg> match_results< BidiIter > & let(Arg const & arg);

    待文档化


PrevUpHomeNext