match_results クラス
サブマッチのシーケンスを保持します。
構文
template <class BidIt, class Alloc>
class match_results
パラメーター
BidIt
サブマッチ用の反復子の型。
Alloc
ストレージを管理するためのアロケーターの型です。
注釈
このクラス テンプレートは、正規表現の検索で生成された sub_match<BidIt> 型の要素の変更不可能なシーケンスを制御するオブジェクトを表します。 各要素は、それに対応するキャプチャ グループと一致したサブシーケンスを指します。
コンストラクター
| コンストラクター | 説明 |
|---|---|
| match_results | オブジェクトを構築します。 |
Typedefs
| 型名 | 説明 |
|---|---|
| allocator_type | ストレージを管理するためのアロケーターの型です。 |
| char_type | 要素の型。 |
| const_iterator | サブマッチ用の const 反復子の型。 |
| const_reference | 要素の定数参照の型。 |
| difference_type | 反復子の差の型です。 |
| Iterator | サブマッチ用の反復子の型。 |
| reference | 要素の参照の型。 |
| size_type | サブマッチ数の型。 |
| string_type | 文字列の型。 |
| value_type | サブマッチの型。 |
メンバー関数
| メンバー関数 | 説明 |
|---|---|
| begin | サブマッチのシーケンスの最初を指定します。 |
| empty | サブマッチが存在しないかどうかをテストします。 |
| end | サブマッチのシーケンスの最後を指定します。 |
| format | サブマッチの形式を設定します。 |
| get_allocator | 格納されているアロケーターを返します。 |
| length | サブマッチの長さを返します。 |
| max_size | サブマッチの最大数を取得します。 |
| position | サブグループの開始オフセットを取得します。 |
| prefix | 最初のサブマッチの前のシーケンスを取得します。 |
| size | サブマッチの数をカウントします。 |
| str | サブマッチが返されます。 |
| suffix | 最後のサブマッチ後に、シーケンスを取得します。 |
| スワップ | 2 つの match_results オブジェクトを交換します。 |
演算子
| 演算子 | 説明 |
|---|---|
| operator= | match_results オブジェクトをコピーします。 |
| operator[] | サブオブジェクトにアクセスします。 |
要件
ヘッダー:<regex>
名前空間: std
例
// std__regex__match_results.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::cout << "prefix: matched == " << std::boolalpha
<< mr.prefix().matched
<< ", value == " << mr.prefix() << std::endl;
std::cout << "whole match: " << mr.length() << " chars, value == "
<< mr.str() << std::endl;
std::cout << "suffix: matched == " << std::boolalpha
<< mr.suffix().matched
<< ", value == " << mr.suffix() << std::endl;
std::cout << std::endl;
std::string fmt("\"c(a*)|(b)\" matched \"$&\"\n"
"\"(a*)\" matched \"$1\"\n"
"\"(b)\" matched \"$2\"\n");
std::cout << mr.format(fmt) << std::endl;
std::cout << std::endl;
// index through submatches
for (size_t n = 0; n < mr.size(); ++n)
{
std::cout << "submatch[" << n << "]: matched == " << std::boolalpha
<< mr[n].matched <<
" at position " << mr.position(n) << std::endl;
std::cout << " " << mr.length(n)
<< " chars, value == " << mr[n] << std::endl;
}
std::cout << std::endl;
// iterate through submatches
for (std::cmatch::iterator it = mr.begin(); it != mr.end(); ++it)
{
std::cout << "next submatch: matched == " << std::boolalpha
<< it->matched << std::endl;
std::cout << " " << it->length()
<< " chars, value == " << *it << std::endl;
}
std::cout << std::endl;
// other members
std::cout << "empty == " << std::boolalpha << mr.empty() << std::endl;
std::cmatch::allocator_type al = mr.get_allocator();
std::cmatch::string_type str = std::string("x");
std::cmatch::size_type maxsiz = mr.max_size();
std::cmatch::char_type ch = 'x';
std::cmatch::difference_type dif = mr.begin() - mr.end();
std::cmatch::const_iterator cit = mr.begin();
std::cmatch::value_type val = *cit;
std::cmatch::const_reference cref = val;
std::cmatch::reference ref = val;
maxsiz = maxsiz; // to quiet "unused" warnings
if (ref == cref)
ch = ch;
dif = dif;
return (0);
}
prefix: matched == true, value == x
whole match: 4 chars, value == caaa
suffix: matched == true, value == y
"c(a*)|(b)" matched "caaa"
"(a*)" matched "aaa"
"(b)" matched ""
submatch[0]: matched == true at position 1
4 chars, value == caaa
submatch[1]: matched == true at position 2
3 chars, value == aaa
submatch[2]: matched == false at position 6
0 chars, value ==
next submatch: matched == true
4 chars, value == caaa
next submatch: matched == true
3 chars, value == aaa
next submatch: matched == false
0 chars, value ==
empty == false
match_results::allocator_type
ストレージを管理するためのアロケーターの型です。
typedef Alloc allocator_type;
注釈
この typedef は、テンプレート引数 Alloc の同意語です。
match_results::begin
サブマッチのシーケンスの最初を指定します。
const_iterator begin() const;
注釈
このメンバー関数は、シーケンスの最初の要素 (または空のシーケンスの末尾の次の位置) を示すランダム アクセス反復子を返します。
match_results::char_type
要素の型。
typedef typename iterator_traits<BidIt>::value_type char_type;
注釈
この typedef は、検索された文字シーケンスの要素の型である iterator_traits<BidIt>::value_type型のシノニムです。
match_results::const_iterator
サブマッチ用の const 反復子の型。
typedef T0 const_iterator;
注釈
typedef は、被制御シーケンスの定数ランダム アクセス反復子として使用できるオブジェクトを表します。
match_results::const_reference
要素の定数参照の型。
typedef const typename Alloc::const_reference const_reference;
注釈
この typedef は、被制御シーケンスの要素への定数参照として使用できるオブジェクトを表します。
match_results::difference_type
反復子の差の型です。
typedef typename iterator_traits<BidIt>::difference_type difference_type;
注釈
typedef は iterator_traits<BidIt>::difference_type型の同意語です。被制御シーケンスの要素を指す任意の 2 つの反復子の差を表現することが可能なオブジェクトを表します。
match_results::empty
サブマッチが存在しないかどうかをテストします。
bool empty() const;
注釈
このメンバー関数は、正規表現検索に失敗した場合にのみ true を返します。
match_results::end
サブマッチのシーケンスの最後を指定します。
const_iterator end() const;
注釈
このメンバー関数は、シーケンスの最後を越えたところを示す反復子を返します。
match_results::format
サブマッチの形式を設定します。
template <class OutIt>
OutIt format(OutIt out,
const string_type& fmt, match_flag_type flags = format_default) const;
string_type format(const string_type& fmt, match_flag_type flags = format_default) const;
パラメーター
OutIt
出力反復子の型。
out
書き込み先の出力ストリーム。
fmt
書式指定文字列。
flags
書式指定フラグ。
注釈
各メンバー関数は、fmt の形式に従って書式指定されたテキストを生成します。 1 つ目のメンバー関数は、書式設定されたテキストを引数 out によって定義されたシーケンスに書き込み、out を返します。2 番目のメンバー関数は、書式設定されたテキストのコピーを保持する文字列オブジェクトを返します。
書式指定されたテキストを生成する際、 書式指定文字列内のリテラル テキストは、ターゲット シーケンスにコピーされるのが一般的です。 書式指定文字列内の各エスケープ シーケンスは、それが表すテキストに置き換えられます。 コピーと置換の詳細な動作は、関数に渡された書式指定フラグによって制御されます。
match_results::get_allocator
格納されているアロケーターを返します。
allocator_type get_allocator() const;
注釈
このメンバー関数は sub_match オブジェクトを割り当てる *this で使用されるアロケーター オブジェクトのコピーを返します。
match_results::iterator
サブマッチ用の反復子の型。
typedef const_iterator iterator;
注釈
この型は、被制御シーケンスのランダム アクセス反復子として使用できるオブジェクトを表します。
match_results::length
サブマッチの長さを返します。
difference_type length(size_type sub = 0) const;
パラメーター
sub
サブマッチのインデックス。
注釈
このメンバー関数は、(*this)[sub].length() を返します。
match_results::match_results
オブジェクトを構築します。
explicit match_results(const Alloc& alloc = Alloc());
match_results(const match_results& right);
パラメーター
alloc
格納するアロケーター オブジェクト。
right
コピーする match_results オブジェクトです。
注釈
1 つ目のコンストラクターは、サブマッチを保持しない match_results オブジェクトを構築します。 2 番目のコンストラクターは、right オブジェクトのコピーである match_results を構築します。
match_results::max_size
サブマッチの最大数を取得します。
size_type max_size() const;
注釈
このメンバー関数は、オブジェクトが制御できる最も長いシーケンスの長さを返します。
match_results::operator=
match_results オブジェクトをコピーします。
match_results& operator=(const match_results& right);
パラメーター
right
コピーする match_results オブジェクトです。
注釈
メンバー演算子は、*this によって制御されるシーケンスを right によって制御されるシーケンスのコピーと置き換えます。
match_results::operator[]
サブオブジェクトにアクセスします。
const_reference operator[](size_type n) const;
パラメーター
n
サブマッチのインデックス。
注釈
メンバー関数は、被制御シーケンスの要素 n への参照、またはキャプチャ グループ n が一致の一部ではない場合size() <= nは空sub_matchのオブジェクトへの参照を返します。
match_results::position
サブグループの開始オフセットを取得します。
difference_type position(size_type sub = 0) const;
パラメーター
sub
サブマッチのインデックス。
注釈
このメンバー関数は、 std::distance(prefix().first, (*this)[sub].first)、つまり、ターゲット シーケンス内の最初の文字から被制御シーケンスの要素 n によって示されるサブマッチ内の最初の文字までの距離を返します。
match_results::prefix
最初のサブマッチの前のシーケンスを取得します。
const_reference prefix() const;
注釈
このメンバー関数は、ターゲット シーケンスの先頭から始まって sub_match<BidIt> で終わる文字シーケンスを指す、(*this)[0].first 型のオブジェクトへの参照を返します。つまり、この参照は一致したサブシーケンスの直前のテキストを指すことになります。
match_results::reference
要素の参照の型。
typedef const_reference reference;
注釈
この型は、 const_reference型のシノニムです。
match_results::size
サブマッチの数をカウントします。
size_type size() const;
注釈
このメンバー関数は、検索に使用された正規表現内のキャプチャ グループの数 + 1 を返します。検索が実行されなかった場合は 0 を返します。
match_results::size_type
サブマッチ数の型。
typedef typename Alloc::size_type size_type;
注釈
この型は、 Alloc::size_type型のシノニムです。
match_results::str
サブマッチが返されます。
string_type str(size_type sub = 0) const;
パラメーター
sub
サブマッチのインデックス。
注釈
このメンバー関数は、string_type((*this)[sub]) を返します。
match_results::string_type
文字列の型。
typedef basic_string<char_type> string_type;
注釈
この型は、 basic_string<char_type>型のシノニムです。
match_results::suffix
最後のサブマッチ後に、シーケンスを取得します。
const_reference suffix() const;
注釈
このメンバー関数は、 sub_match<BidIt> から始まってターゲット シーケンスの末尾で終わる文字シーケンスを指す (つまり、一致したサブシーケンスに続くテキストを指す) (*this)[size() - 1].second 型のオブジェクトへの参照を返します。
match_results::swap
2 つの match_results オブジェクトを交換します。
void swap(const match_results& right) throw();
パラメーター
right
交換する match_results オブジェクト。
注釈
メンバー関数は、定数時間で内容と右の*this内容を入れ替え、例外をスローしません。
match_results::value_type
サブマッチの型。
typedef sub_match<BidIt> value_type;
注釈
typedef は、型 sub_match<BidIt> の同意語です。