match_results 構造体テンプレート

template<typename BidiIter>
struct match_results

match_results<> クラステンプレートは regex_matchregex_search の結果を sub_match オブジェクトのコレクションとして保持する。

概要

// ヘッダ:<boost/xpressive/match_results.hpp>

template<typename BidiIter>
struct match_results {
  // 型
  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;

  // 構築、コピー、解体
  match_results();
  match_results(match_results< BidiIter > const &);
  match_results< BidiIter >& operator=(match_results< BidiIter > const &);
  ~match_results();

  // 公開メンバ関数
  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 が規定するシーケンスの要件に適合するが、const なシーケンスに対して定義された演算だけをサポートする。

match_results の構築、コピー、解体公開演算

match_results()
事後条件

regex_id() == 0

事後条件

size() == 0

事後条件

empty() == true

事後条件

str() == string_type()

match_results(match_results<BidiIter> const &that)
パラメータ

that -- コピーする match_results オブジェクト。

事後条件

regex_id() == that.regex_id()

事後条件

size() == that.size()

事後条件

empty() == that.empty()

事後条件

n < that.size() であるすべての自然数 n について str(n) == that.str(n)

事後条件

prefix() == that.prefix()

事後条件

suffix() == that.suffix()

事後条件

n < that.size() であるすべての自然数 n について (*this)[n] == that[n]

事後条件

n < that.size() であるすべての自然数 n について length(n) == that.length(n)

事後条件

n < that.size() であるすべての自然数 n について position(n) == that.position(n)

match_results<BidiIter> &operator=(match_results<BidiIter> const &that)
パラメータ

that -- コピーする match_results オブジェクト。

事後条件

regex_id() == that.regex_id()

事後条件

size() == that.size()

事後条件

empty() == that.empty()

事後条件

n < that.size() であるすべての自然数 n について str(n) == that.str(n)

事後条件

prefix() == that.prefix()

事後条件

suffix() == that.suffix()

事後条件

n < that.size() であるすべての自然数 n について (*this)[n] == that[n]

事後条件

n < that.size() であるすべての自然数 n について length(n) == that.length(n)

事後条件

n < that.size() であるすべての自然数 n について position(n) == that.position(n)

~match_results()

match_results 公開メンバ関数

size_type size() const

*this が成功したマッチ結果を表す場合は、マッチしたマーク済み部分式の総数に 1 を足した数を返す。それ以外の場合は 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 による繰り返し検索の途中でなければ、baseprefix().first と同じである。

string_type str(size_type sub = 0) const

(*this)[sub].str() を返す。

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

マーク済み部分式 sub にマッチしたシーケンスを表す sub_match オブジェクトへの参照を返す。sub == 0 であれば正規表現全体にマッチしたシーケンスを表す sub_match オブジェクトへの参照を返す。sub >= size() であればマッチしなかった部分式を表す sub_match オブジェクトへの参照を返す。

const_reference prefix() const

マッチ・検索対象文字列の先頭からマッチが見つかった位置までの文字シーケンスを表す sub_match オブジェクトへの参照を返す。

要件

(*this)[0].matched が真

const_reference suffix() const

マッチが見つかった位置の終端からマッチ・検索対象文字列の終端までの文字シーケンスを表す sub_match オブジェクトへの参照を返す。

要件

(*this)[0].matched が真

const_iterator begin() const

*this に格納されたマーク済み部分式マッチをすべて列挙する開始イテレータを返す。

const_iterator end() const

*this に格納されたマーク済み部分式マッチをすべて列挙する終了イテレータを返す。

operator bool_type() const

(*this)[0].matched であれば真を、そうでなければ偽を返す。

bool operator!() const

empty() || !(*this)[0].matched であれば真を、そうでなければ偽を返す。

regex_id_type regex_id() const

この match_results オブジェクトで最近使用した basic_regex オブジェクトの識別子を返す。

nested_results_type const &nested_results() const

入れ子の match_results 要素のシーケンスを返す。

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 か null 終端文字列であれば、fmt 内の文字シーケンスを OutputIterator である out にコピーする。fmt 内の各書式化子およびエスケープシーケンスについて、それらが表す文字(列)かそれらが参照する *this 内のシーケンスで置換する。flags で指定したビットマスクは、どの書式化子あるいはエスケープシーケンスを使用するかを決定する。既定では『ECMA-262 、ECMAScript 言語仕様 15 章 5.4.11 String.prototype.replace』が使用する書式である。

それ以外で FormatCallable<match_results<BidiIter>, OutputIterator, regex_constants::match_flag_type> であれば、この関数は fmt(*this, out, flags) を返す。

それ以外で FormatCallable<match_results<BidiIter>, OutputIterator> であれば、この関数は fmt(*this, out) を返す。

それ以外で FormatCallable<match_results<BidiIter> > であれば、この関数は std::copy(x.begin(), x.end(), out) を返す。xfmt(*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 か null 終端文字列であれば、この関数は文字シーケンス fmt のコピーを返す。fmt 内の各書式化子およびエスケープシーケンスについて、それらが表す文字(列)かそれらが参照する *this 内のシーケンスで置換する。flags で指定したビットマスクは、どの書式化子あるいはエスケープシーケンスを使用するかを決定する。既定では『ECMA-262 、ECMAScript 言語仕様 15 章 5.4.11 String.prototype.replace』が使用する書式である。

それ以外で FormatCallable<match_results<BidiIter>, OutputIterator, regex_constants::match_flag_type> であれば、この関数は fmt(*this, out, flags) 呼び出しで得られた string_type オブジェクト x を返す。outx への back_insert_iterator である。

それ以外で FormatCallable<match_results<BidiIter>, OutputIterator> であれば、この関数は fmt(*this, out) の呼び出しで得られた string_type オブジェクト x を返す。outx への back_insert_iterator である。

それ以外で FormatCallable<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)

2 つの match_results オブジェクトの内容を交換する。例外を投げないことを保証する。

パラメータ

that -- 交換する match_results オブジェクト。

事後条件

*thisthat 内にあった部分式マッチのシーケンスをもつ。that*this 内にあった部分式マッチのシーケンスをもつ。

例外

送出しない。

template<typename Arg>
match_results<BidiIter> &let(Arg const &arg)

TODO document me

注釈

訳注 この節はまだ原文がありません。