c++ - boost 正则表达式 :switching between ascii and unicode

标签 c++ boost unicode utf-8

在boost.regex中有没有方便的方式在ascii和utf之间切换?

我现在看到的唯一方法是,例如,在 boost::u32regexboost::regex 之间切换。

这是在 unicode 和 ascii 之间切换的唯一方法吗?
我希望能够只传递一个参数来 boost ,指定我的字符编码,这样就不必重复很多代码。

最佳答案

Is this the only way to switch between unicode and ascii?

差不多。你认为的 boost::regex 实际上是一个类型别名:

namespace boost{
    template <class charT, class traits = regex_traits<charT>  >
    class basic_regex;

    typedef basic_regex<char>      regex;
    typedef basic_regex<wchar_t>   wregex;
}

请注意,字符类型是模板参数 - 它不是运行时参数。自 boost::regex建立在 char 上,它不支持 unicode。

boost::u32regex 也是一样的:

typedef basic_regex<UChar32,icu_regex_traits> u32regex;

为了真正在它们之间进行概括,您也必须将所有内容都写成模板。而不是服用 boost::regex , 你拿一个 boost::basic_regex<charT, traits> .这是模板的缺点之一 - 它们几乎渗透到所有内容中。

关于c++ - boost 正则表达式 :switching between ascii and unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37076856/

相关文章:

c++ - boost 认识 child

delphi - 如何在 TMenuOption 中显示希腊符号

python - utf-8 中的汉字字符

c++ - 创建没有指定大小的对象数组

c++ - WriteConsoleOutputCharacter 使控制台应用程序崩溃

在 Boost 模板参数中发现 C++ 奇怪的语法

在 Elastic Search 中按分配给该记录的点 boost 记录

c++ - 将 unicode 转换为 char

android - OpenCv C++ 裁剪图像

c++ - 理性类和 move 语义不起作用