|
Boost Users : |
From: Josue Andrade Gomes (josuegomes_at_[hidden])
Date: 2021-05-24 20:29:30
It seems that Boost.Locale cannot be used with std::regex. See the code below:
#include <regex>
#include <boost/locale.hpp>
int main()
{
try {
boost::locale::generator gen;
std::locale de_DE(gen("de_DE.UTF-8"));
std::wstring in(L"Grün GRÃN grün");
std::wregex rx;
rx.imbue(de_DE);
rx.assign(L"grün", std::regex::icase);
std::wcout << std::regex_replace(in, rx, L"green") << L"\n";
}
catch (std::exception &e) {
std::cout << "Exception: " << e.what() << "\n";
}
}
Outputs:
green GRÃN green
However this:
#include <regex>
#include <locale>
int main()
{
try {
std::locale de_DE("de_DE.UTF-8");
std::wstring in(L"Grün GRÃN grün");
std::wregex rx;
rx.imbue(de_DE);
rx.assign(L"grün", std::regex::icase);
std::wcout << std::regex_replace(in, rx, L"green") << L"\n";
}
catch (std::exception &e) {
std::cout << "Exception: " << e.what() << "\n";
}
}
Correctly outputs:
green green green
Tested on Ubuntu 20.04.2. g++ 10.2, Boost.Locale built with ICU
support using vcpkg (thus static link).
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net