std::regex_traits::lookup_collatename

template< class ForwardIt >
string_type lookup_collatename( ForwardIt first, ForwardIt last ) const;

若字符序列 [first, last) 表示当前感染的 locale 中合法对照元素的名称,则返回该对照元素之名。否则,返回空字符串。

对照元素是在 POSIX 正则表达式的 [..] 之间找到的符号。例如, [.a.] 在 C 本地环境中匹配字符 a 。而 [.tilde.] 在 C 本地环境中匹配 ~[.ch.] 在捷克语本地环境中匹配双标符 ch ,但在大多数其他本地环境中生成错误码为 std::regex_constants::error_collatestd::regex_error

参数

first, last - 一对迭代器,确定表示对照元素名的字符序列
类型要求
-
ForwardIt 必须满足 ForwardIterator 的要求。

返回值

具名对照元素作为字符串的表示。

示例

#include <iostream>
#include <string>
#include <regex>
 
struct noisy_traits : std::regex_traits<char> {
 
    template< class Iter >
    string_type lookup_collatename( Iter first, Iter last ) const {
        string_type result = regex_traits::lookup_collatename(first, last);
        std::cout << "regex_traits<>::lookup_collatename(\""
                  << string_type(first, last)
                  << "\") returns \"" << result << "\"\n";
        return result;
    }
};
 
int main()
{
    std::string str = "z|}a"; // C 本地环境对照顺序: x,y,z,{,|,},~
    std::basic_regex<char, noisy_traits> re("[x-[.tilde.]]*a", std::regex::basic);
    std::cout << std::boolalpha << std::regex_match(str, re) << '\n';
}

输出:

regex_traits<>::lookup_collatename("tilde") returns "~"
true

版本历史

  • (当前 | 先前 2017年10月13日 (五) 09:12Fruderica讨论 | 贡献. . (1,940字节) (-1,225). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:07P12bot讨论 | 贡献 . . (3,165字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:14P12bot讨论 | 贡献 . . (3,165字节) (-59). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 11:33P12bot讨论 | 贡献 . . (3,224字节) (+393). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 12:11P12讨论 | 贡献 . . (2,831字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,831字节) (-34). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 15:33P12讨论 | 贡献 . . (2,865字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,865字节) (+2,865). . (Translated from the English version using Google Translate)