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

source code of libcxx/test/std/re/re.alg/re.alg.match/awk.locale.pass.cpp