在boost.regex中,是否有一种方便的方法可以在ASCII和UTF之间切换?
我目前唯一看到的方法是,例如在boost::u32regex
和boost::regex
之间切换。
这是在Unicode和ASCII之间切换的唯一方法吗?
我希望能够只需传递一个参数给boost,指定我的字符编码,从而不必重复大量的代码。
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>
。这就是模板的缺点 - 它们会渗透到所有东西中。