1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // NetBSD does not support LC_COLLATE at the moment 10 // XFAIL: netbsd 11 12 // REQUIRES: locale.cs_CZ.ISO8859-2 13 14 // <regex> 15 16 // template <class BidirectionalIterator, class Allocator, class charT, class traits> 17 // bool 18 // regex_match(BidirectionalIterator first, BidirectionalIterator last, 19 // match_results<BidirectionalIterator, Allocator>& m, 20 // const basic_regex<charT, traits>& e, 21 // regex_constants::match_flag_type flags = regex_constants::match_default); 22 23 // TODO: investigation needed 24 // XFAIL: target={{.*}}-linux-gnu{{.*}}, freebsd 25 26 #include <regex> 27 #include <cassert> 28 #include "test_macros.h" 29 #include "test_iterators.h" 30 31 #include "platform_support.h" // locale name macros 32 33 int main(int, char**) 34 { 35 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2)); 36 { 37 std::cmatch m; 38 const char s[] = "m"; 39 assert(std::regex_match(s, m, std::regex("[a[=M=]z]", 40 std::regex_constants::basic))); 41 assert(m.size() == 1); 42 assert(!m.prefix().matched); 43 assert(m.prefix().first == s); 44 assert(m.prefix().second == m[0].first); 45 assert(!m.suffix().matched); 46 assert(m.suffix().first == m[0].second); 47 assert(m.suffix().second == m[0].second); 48 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 49 assert(m.position(0) == 0); 50 assert(m.str(0) == s); 51 } 52 { 53 std::cmatch m; 54 const char s[] = "Ch"; 55 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]", 56 std::regex_constants::basic | std::regex_constants::icase))); 57 assert(m.size() == 1); 58 assert(!m.prefix().matched); 59 assert(m.prefix().first == s); 60 assert(m.prefix().second == m[0].first); 61 assert(!m.suffix().matched); 62 assert(m.suffix().first == m[0].second); 63 assert(m.suffix().second == m[0].second); 64 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s)); 65 assert(m.position(0) == 0); 66 assert(m.str(0) == s); 67 } 68 std::locale::global(std::locale("C")); 69 { 70 std::cmatch m; 71 const char s[] = "m"; 72 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]", 73 std::regex_constants::basic))); 74 assert(m.size() == 0); 75 } 76 77 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 78 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2)); 79 { 80 std::wcmatch m; 81 const wchar_t s[] = L"m"; 82 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]", 83 std::regex_constants::basic))); 84 assert(m.size() == 1); 85 assert(!m.prefix().matched); 86 assert(m.prefix().first == s); 87 assert(m.prefix().second == m[0].first); 88 assert(!m.suffix().matched); 89 assert(m.suffix().first == m[0].second); 90 assert(m.suffix().second == m[0].second); 91 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 92 assert(m.position(0) == 0); 93 assert(m.str(0) == s); 94 } 95 { 96 std::wcmatch m; 97 const wchar_t s[] = L"Ch"; 98 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]", 99 std::regex_constants::basic | std::regex_constants::icase))); 100 assert(m.size() == 1); 101 assert(!m.prefix().matched); 102 assert(m.prefix().first == s); 103 assert(m.prefix().second == m[0].first); 104 assert(!m.suffix().matched); 105 assert(m.suffix().first == m[0].second); 106 assert(m.suffix().second == m[0].second); 107 assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s)); 108 assert(m.position(0) == 0); 109 assert(m.str(0) == s); 110 } 111 std::locale::global(std::locale("C")); 112 { 113 std::wcmatch m; 114 const wchar_t s[] = L"m"; 115 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]", 116 std::regex_constants::basic))); 117 assert(m.size() == 0); 118 } 119 #endif // TEST_HAS_NO_WIDE_CHARACTERS 120 121 return 0; 122 } 123