我可以在char16_t的字符串上使用STL正则表达式库吗? [英] Can I use the STL regex library on strings of char16_t?
本文介绍了我可以在char16_t的字符串上使用STL正则表达式库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简而言之,下面的代码本质上是什么问题?
In short, what is inherently wrong with the following code?
#include <regex>
int main() {
std::regex_match(u" ", std::basic_regex<char16_t>{u" "});
}
错误
$ g++ -std=c++17 main.cpp -o main
$ ./main
terminate called after throwing an instance of 'std::bad_cast'
what(): std::bad_cast
Aborted (core dumped)
更多信息:
$ g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
推荐答案
C ++标准库不支持使用char16_t或char32_t Unicode的正则表达式.有解决此问题的建议,但在C ++ 20中却没有:
The C++ standard library does not support regex with char16_t or char32_t Unicode. There is a proposal to address this, but it is not in C++20: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html
这篇关于我可以在char16_t的字符串上使用STL正则表达式库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文