std::regex_traits<CharT>:: lookup_classname
|
template
<
class
ForwardIt
>
char_class_type lookup_classname
(
ForwardIt first,
|
||
文字シーケンス
[
first
,
last
)
が現在設定されているロケールにおける有効な文字クラス名(すなわち、正規表現における
[:
と
:]
の間の文字列)を表す場合、その文字クラスを表す実装定義の値を返します。それ以外の場合、ゼロを返します。
パラメータ
icase
が
true
の場合、文字クラスは大文字小文字を区別しません。例えば、
[:lower:]
という正規表現と
std::regex_constants::icase
を組み合わせると、
std::
regex_traits
<>
::
lookup_classname
(
)
が呼び出され、
[
first
,
last
)
で示される文字列
"lower"
と
icase
==
true
が渡されます。この呼び出しは、
[:alpha:]
という正規表現と
icase
==
false
を組み合わせた場合に生成される呼び出しと同じビットマスクを返します。
以下のナロー文字およびワイド文字クラス名は、常に std:: regex_traits < char > および std:: regex_traits < wchar_t > によってそれぞれ認識され、返される分類( icase == false の場合)は、以下のようにインプットされたロケールの std::ctype ファセットによって得られる一致する分類に対応します:
| 文字クラス名 | std::ctype 分類 | |
|---|---|---|
| ナロー | ワイド | |
| "alnum" | L "alnum" | std::ctype_base::alnum |
| "alpha" | L "alpha" | std::ctype_base::alpha |
| "blank" | L "blank" | std::ctype_base::blank |
| "cntrl" | L "cntrl" | std::ctype_base::cntrl |
| "digit" | L "digit" | std::ctype_base::digit |
| "graph" | L "graph" | std::ctype_base::graph |
| "lower" | L "lower" | std::ctype_base::lower |
| "print" | L "print" | std::ctype_base::print |
| "punct" | L "punct" | std::ctype_base::punct |
| "space" | L "space" | std::ctype_base::space |
| "upper" | L "upper" | std::ctype_base::upper |
| "xdigit" | L "xdigit" | std::ctype_base::xdigit |
| "d" | L "d" | std::ctype_base::digit |
| "s" | L "s" | std::ctype_base::space |
| "w" | L "w" |
std::ctype_base::alnum
に '_' がオプションで追加される |
文字列に対して返される分類 "w" は "alnum" と完全に同じ場合があり、その場合 isctype() は明示的に '_' を追加します。
追加の分類、例えば "jdigit" や "jkanji" は、システム提供のロケールによって提供される場合があります(その場合、これらは std::wctype を通じてもアクセス可能です)。
目次 |
パラメータ
| first, last | - | 文字クラスの名前を表す文字シーケンスを決定するイテレータのペア |
| icase | - | もし true の場合、文字分類における大文字/小文字の区別を無視する |
| 型要件 | ||
-
ForwardIt
は
LegacyForwardIterator
の要件を満たさなければならない。
|
||
戻り値
指定された文字クラスによって決定される文字分類を表すビットマスク、または char_class_type ( ) クラスが不明な場合。
例
lookup_classname()
/
isctype()
のカスタム正規表現特性実装を実演します:
#include <cwctype> #include <iostream> #include <locale> #include <regex> // This custom regex traits uses wctype/iswctype to implement lookup_classname/isctype. struct wctype_traits : std::regex_traits<wchar_t> { using char_class_type = std::wctype_t; template<class It> char_class_type lookup_classname(It first, It last, bool = false) const { return std::wctype(std::string(first, last).c_str()); } bool isctype(wchar_t c, char_class_type f) const { return std::iswctype(c, f); } }; int main() { std::locale::global(std::locale("ja_JP.utf8")); std::wcout.sync_with_stdio(false); std::wcout.imbue(std::locale()); std::wsmatch m; std::wstring in = L"風の谷のナウシカ"; // matches all characters (they are classified as alnum) std::regex_search(in, m, std::wregex(L"([[:alnum:]]+)")); std::wcout << "alnums: " << m[1] << '\n'; // prints "風の谷のナウシカ" // matches only the katakana std::regex_search(in, m, std::basic_regex<wchar_t, wctype_traits>(L"([[:jkata:]]+)")); std::wcout << "katakana: " << m[1] << '\n'; // prints "ナウシカ" }
出力:
alnums: 風の谷のナウシカ katakana: ナウシカ
関連項目
|
文字クラスへの所属を示す
(公開メンバ関数) |
|
|
現在のCロケールで文字分類カテゴリを検索する
(関数) |