Last active
January 24, 2021 07:52
-
-
Save yutannihilation/1ce85a2abdeea4f59ce86fda44dd8ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rcpp::cppFunction(' | |
void foo() { | |
// works fine if I change the pattern to one without [] | |
std::regex reg("[0-9]"); | |
} | |
', includes = "#include <regex>") | |
# works | |
Sys.setlocale("LC_ALL", 'English') | |
foo() | |
# freezes | |
Sys.setlocale("LC_ALL", 'Japanese') | |
foo() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpp11::cpp_source( | |
code = | |
'#include <regex> | |
[[cpp11::register]] | |
void foo() { | |
std::regex reg("[0-9]"); | |
} | |
') | |
# works | |
Sys.setlocale("LC_ALL", 'English') | |
foo() | |
# freezes | |
Sys.setlocale("LC_ALL", 'Japanese') | |
foo() |
cpp11::cpp_source(
code = '
#include <regex>
[[cpp11::register]]
bool grepl(const std::string pattern_, const std::string x) {
std::regex::flag_type ECMA_no_collate = static_cast<std::regex::flag_type>(std::regex::ECMAScript & !std::regex::collate);
std::regex pattern(pattern_, ECMA_no_collate);
std::smatch match;
return std::regex_search(x, match, pattern);
}
')
grepl("[f]", "foo")
grepl("[e]", "foo")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work...
c.f. https://en.cppreference.com/w/cpp/regex/syntax_option_type