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