fork download
  1. /// $ g++ -std=c++11 *.cc && ./a.out
  2.  
  3. #include <locale>
  4. #include <regex>
  5.  
  6. namespace {
  7. // From http://stackoverflow.com/questions/11254232/do-c11-regular-expressions-work-with-utf-8-strings
  8.  
  9. bool test_unicode()
  10. {
  11. std::locale old;
  12. std::locale::global(std::locale("en_US.UTF-8"));
  13.  
  14. std::regex pattern("[[:alpha:]]+", std::regex_constants::extended);
  15. bool result = std::regex_match(std::string("abcdéfg"), pattern);
  16.  
  17. std::locale::global(old);
  18.  
  19. return result;
  20. }
  21.  
  22. bool test_unicode2()
  23. {
  24. std::locale old;
  25. std::locale::global(std::locale("en_US.UTF-8"));
  26.  
  27. std::regex pattern("[[:alpha:]]+", std::regex_constants::extended);
  28. bool result = std::regex_match(std::string("abcd\xC3\xA9""fg"), pattern);
  29.  
  30. std::locale::global(old);
  31.  
  32. return result;
  33. }
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. return !(test_unicode() or test_unicode2()); // return 0 if *any* of
  40. // the tests succeed
  41. }
  42.  
Runtime error #stdin #stdout 0s 17008KB
stdin
Standard input is empty
stdout
Standard output is empty