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 // REQUIRES: locale.cs_CZ.ISO8859-2
23
24 #include <regex>
25 #include <cassert>
26 #include "test_macros.h"
27 #include "test_iterators.h"
28
29 #include "platform_support.h" // locale name macros
30
main(int,char **)31 int main(int, char**)
32 {
33 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
34 {
35 std::cmatch m;
36 const char s[] = "m";
37 // AIX supports character equivalence classes. What the contents of the class are depends
38 // on the locale and the standards do not specify any locale other than C/POSIX.
39 #if defined(_AIX)
40 assert(std::regex_match(s, m,
41 std::regex("[a[=m=]z]", std::regex_constants::awk)));
42 #else
43 assert(std::regex_match(s, m,
44 std::regex("[a[=M=]z]", std::regex_constants::awk)));
45 #endif
46 assert(m.size() == 1);
47 assert(!m.prefix().matched);
48 assert(m.prefix().first == s);
49 assert(m.prefix().second == m[0].first);
50 assert(!m.suffix().matched);
51 assert(m.suffix().first == m[0].second);
52 assert(m.suffix().second == m[0].second);
53 assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
54 assert(m.position(0) == 0);
55 assert(m.str(0) == s);
56 }
57 {
58 std::cmatch m;
59 const char s[] = "Ch";
60 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
61 std::regex_constants::awk | std::regex_constants::icase)));
62 assert(m.size() == 1);
63 assert(!m.prefix().matched);
64 assert(m.prefix().first == s);
65 assert(m.prefix().second == m[0].first);
66 assert(!m.suffix().matched);
67 assert(m.suffix().first == m[0].second);
68 assert(m.suffix().second == m[0].second);
69 assert((std::size_t)m.length(0) == std::char_traits<char>::length(s));
70 assert(m.position(0) == 0);
71 assert(m.str(0) == s);
72 }
73 std::locale::global(std::locale("C"));
74 {
75 std::cmatch m;
76 const char s[] = "m";
77 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]",
78 std::regex_constants::awk)));
79 assert(m.size() == 0);
80 }
81
82 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
83 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
84 {
85 std::wcmatch m;
86 const wchar_t s[] = L"m";
87 #if defined(_AIX)
88 assert(std::regex_match(s, m, std::wregex(L"[a[=m=]z]",
89 std::regex_constants::awk)));
90 #else
91 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
92 std::regex_constants::awk)));
93 #endif
94 assert(m.size() == 1);
95 assert(!m.prefix().matched);
96 assert(m.prefix().first == s);
97 assert(m.prefix().second == m[0].first);
98 assert(!m.suffix().matched);
99 assert(m.suffix().first == m[0].second);
100 assert(m.suffix().second == m[0].second);
101 assert((std::size_t)m.length(0) == std::char_traits<wchar_t>::length(s));
102 assert(m.position(0) == 0);
103 assert(m.str(0) == s);
104 }
105 //TODO: Need to be investigated for AIX OS
106 #if !defined(_AIX)
107 {
108 std::wcmatch m;
109 const wchar_t s[] = L"Ch";
110 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
111 std::regex_constants::awk | std::regex_constants::icase)));
112 assert(m.size() == 1);
113 assert(!m.prefix().matched);
114 assert(m.prefix().first == s);
115 assert(m.prefix().second == m[0].first);
116 assert(!m.suffix().matched);
117 assert(m.suffix().first == m[0].second);
118 assert(m.suffix().second == m[0].second);
119 assert((std::size_t)m.length(0) == std::char_traits<wchar_t>::length(s));
120 assert(m.position(0) == 0);
121 assert(m.str(0) == s);
122 }
123 #endif
124 std::locale::global(std::locale("C"));
125 {
126 std::wcmatch m;
127 const wchar_t s[] = L"m";
128 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
129 std::regex_constants::awk)));
130 assert(m.size() == 0);
131 }
132 #endif // TEST_HAS_NO_WIDE_CHARACTERS
133 return 0;
134 }
135