Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <regex> |
| 11 | |
| 12 | // template <class charT> struct regex_traits; |
| 13 | |
| 14 | // template <class ForwardIterator> |
| 15 | // char_class_type |
| 16 | // lookup_classname(ForwardIterator first, ForwardIterator last, |
| 17 | // bool icase = false) const; |
| 18 | |
| 19 | #include <regex> |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 20 | #include <cassert> |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 21 | #include "test_iterators.h" |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 22 | |
| 23 | template <class char_type> |
| 24 | void |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 25 | test(const char_type* A, |
| 26 | typename std::regex_traits<char_type>::char_class_type expected, |
| 27 | bool icase = false) |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 28 | { |
| 29 | std::regex_traits<char_type> t; |
| 30 | typedef forward_iterator<const char_type*> F; |
| 31 | assert(t.lookup_classname(F(A), F(A + t.length(A)), icase) == expected); |
| 32 | } |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 33 | |
| 34 | int main() |
| 35 | { |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 36 | test("d", std::ctype_base::digit); |
| 37 | test("D", std::ctype_base::digit); |
| 38 | test("d", std::ctype_base::digit, true); |
| 39 | test("D", std::ctype_base::digit, true); |
| 40 | |
| 41 | test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum |
| 42 | | std::ctype_base::upper | std::ctype_base::lower); |
| 43 | test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum |
| 44 | | std::ctype_base::upper | std::ctype_base::lower); |
| 45 | test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum |
| 46 | | std::ctype_base::upper | std::ctype_base::lower, true); |
| 47 | test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum |
| 48 | | std::ctype_base::upper | std::ctype_base::lower, true); |
| 49 | |
| 50 | test("s", std::ctype_base::space); |
| 51 | test("S", std::ctype_base::space); |
| 52 | test("s", std::ctype_base::space, true); |
| 53 | test("S", std::ctype_base::space, true); |
| 54 | |
| 55 | test("alnum", std::ctype_base::alnum); |
| 56 | test("AlNum", std::ctype_base::alnum); |
| 57 | test("alnum", std::ctype_base::alnum, true); |
| 58 | test("AlNum", std::ctype_base::alnum, true); |
| 59 | |
| 60 | test("alpha", std::ctype_base::alpha); |
| 61 | test("Alpha", std::ctype_base::alpha); |
| 62 | test("alpha", std::ctype_base::alpha, true); |
| 63 | test("Alpha", std::ctype_base::alpha, true); |
| 64 | |
| 65 | test("blank", std::ctype_base::blank); |
| 66 | test("Blank", std::ctype_base::blank); |
| 67 | test("blank", std::ctype_base::blank, true); |
| 68 | test("Blank", std::ctype_base::blank, true); |
| 69 | |
| 70 | test("cntrl", std::ctype_base::cntrl); |
| 71 | test("Cntrl", std::ctype_base::cntrl); |
| 72 | test("cntrl", std::ctype_base::cntrl, true); |
| 73 | test("Cntrl", std::ctype_base::cntrl, true); |
| 74 | |
| 75 | test("digit", std::ctype_base::digit); |
| 76 | test("Digit", std::ctype_base::digit); |
| 77 | test("digit", std::ctype_base::digit, true); |
| 78 | test("Digit", std::ctype_base::digit, true); |
| 79 | |
| 80 | test("digit", std::ctype_base::digit); |
| 81 | test("DIGIT", std::ctype_base::digit); |
| 82 | test("digit", std::ctype_base::digit, true); |
| 83 | test("Digit", std::ctype_base::digit, true); |
| 84 | |
| 85 | test("graph", std::ctype_base::graph); |
| 86 | test("GRAPH", std::ctype_base::graph); |
| 87 | test("graph", std::ctype_base::graph, true); |
| 88 | test("Graph", std::ctype_base::graph, true); |
| 89 | |
| 90 | test("lower", std::ctype_base::lower); |
| 91 | test("LOWER", std::ctype_base::lower); |
| 92 | test("lower", std::ctype_base::lower | std::ctype_base::alpha, true); |
| 93 | test("Lower", std::ctype_base::lower | std::ctype_base::alpha, true); |
| 94 | |
| 95 | test("print", std::ctype_base::print); |
| 96 | test("PRINT", std::ctype_base::print); |
| 97 | test("print", std::ctype_base::print, true); |
| 98 | test("Print", std::ctype_base::print, true); |
| 99 | |
| 100 | test("punct", std::ctype_base::punct); |
| 101 | test("PUNCT", std::ctype_base::punct); |
| 102 | test("punct", std::ctype_base::punct, true); |
| 103 | test("Punct", std::ctype_base::punct, true); |
| 104 | |
| 105 | test("space", std::ctype_base::space); |
| 106 | test("SPACE", std::ctype_base::space); |
| 107 | test("space", std::ctype_base::space, true); |
| 108 | test("Space", std::ctype_base::space, true); |
| 109 | |
| 110 | test("upper", std::ctype_base::upper); |
| 111 | test("UPPER", std::ctype_base::upper); |
| 112 | test("upper", std::ctype_base::upper | std::ctype_base::alpha, true); |
| 113 | test("Upper", std::ctype_base::upper | std::ctype_base::alpha, true); |
| 114 | |
| 115 | test("xdigit", std::ctype_base::xdigit); |
| 116 | test("XDIGIT", std::ctype_base::xdigit); |
| 117 | test("xdigit", std::ctype_base::xdigit, true); |
| 118 | test("Xdigit", std::ctype_base::xdigit, true); |
| 119 | |
Marshall Clow | 8d4ce30 | 2014-03-04 22:44:34 +0000 | [diff] [blame] | 120 | test("dig", std::ctype_base::mask()); |
| 121 | test("", std::ctype_base::mask()); |
| 122 | test("digits", std::ctype_base::mask()); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 123 | |
| 124 | test(L"d", std::ctype_base::digit); |
| 125 | test(L"D", std::ctype_base::digit); |
| 126 | test(L"d", std::ctype_base::digit, true); |
| 127 | test(L"D", std::ctype_base::digit, true); |
| 128 | |
| 129 | test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum |
| 130 | | std::ctype_base::upper | std::ctype_base::lower); |
| 131 | test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum |
| 132 | | std::ctype_base::upper | std::ctype_base::lower); |
| 133 | test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum |
| 134 | | std::ctype_base::upper | std::ctype_base::lower, true); |
| 135 | test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum |
| 136 | | std::ctype_base::upper | std::ctype_base::lower, true); |
| 137 | |
| 138 | test(L"s", std::ctype_base::space); |
| 139 | test(L"S", std::ctype_base::space); |
| 140 | test(L"s", std::ctype_base::space, true); |
| 141 | test(L"S", std::ctype_base::space, true); |
| 142 | |
| 143 | test(L"alnum", std::ctype_base::alnum); |
| 144 | test(L"AlNum", std::ctype_base::alnum); |
| 145 | test(L"alnum", std::ctype_base::alnum, true); |
| 146 | test(L"AlNum", std::ctype_base::alnum, true); |
| 147 | |
| 148 | test(L"alpha", std::ctype_base::alpha); |
| 149 | test(L"Alpha", std::ctype_base::alpha); |
| 150 | test(L"alpha", std::ctype_base::alpha, true); |
| 151 | test(L"Alpha", std::ctype_base::alpha, true); |
| 152 | |
| 153 | test(L"blank", std::ctype_base::blank); |
| 154 | test(L"Blank", std::ctype_base::blank); |
| 155 | test(L"blank", std::ctype_base::blank, true); |
| 156 | test(L"Blank", std::ctype_base::blank, true); |
| 157 | |
| 158 | test(L"cntrl", std::ctype_base::cntrl); |
| 159 | test(L"Cntrl", std::ctype_base::cntrl); |
| 160 | test(L"cntrl", std::ctype_base::cntrl, true); |
| 161 | test(L"Cntrl", std::ctype_base::cntrl, true); |
| 162 | |
| 163 | test(L"digit", std::ctype_base::digit); |
| 164 | test(L"Digit", std::ctype_base::digit); |
| 165 | test(L"digit", std::ctype_base::digit, true); |
| 166 | test(L"Digit", std::ctype_base::digit, true); |
| 167 | |
| 168 | test(L"digit", std::ctype_base::digit); |
| 169 | test(L"DIGIT", std::ctype_base::digit); |
| 170 | test(L"digit", std::ctype_base::digit, true); |
| 171 | test(L"Digit", std::ctype_base::digit, true); |
| 172 | |
| 173 | test(L"graph", std::ctype_base::graph); |
| 174 | test(L"GRAPH", std::ctype_base::graph); |
| 175 | test(L"graph", std::ctype_base::graph, true); |
| 176 | test(L"Graph", std::ctype_base::graph, true); |
| 177 | |
| 178 | test(L"lower", std::ctype_base::lower); |
| 179 | test(L"LOWER", std::ctype_base::lower); |
| 180 | test(L"lower", std::ctype_base::lower | std::ctype_base::alpha, true); |
| 181 | test(L"Lower", std::ctype_base::lower | std::ctype_base::alpha, true); |
| 182 | |
| 183 | test(L"print", std::ctype_base::print); |
| 184 | test(L"PRINT", std::ctype_base::print); |
| 185 | test(L"print", std::ctype_base::print, true); |
| 186 | test(L"Print", std::ctype_base::print, true); |
| 187 | |
| 188 | test(L"punct", std::ctype_base::punct); |
| 189 | test(L"PUNCT", std::ctype_base::punct); |
| 190 | test(L"punct", std::ctype_base::punct, true); |
| 191 | test(L"Punct", std::ctype_base::punct, true); |
| 192 | |
| 193 | test(L"space", std::ctype_base::space); |
| 194 | test(L"SPACE", std::ctype_base::space); |
| 195 | test(L"space", std::ctype_base::space, true); |
| 196 | test(L"Space", std::ctype_base::space, true); |
| 197 | |
| 198 | test(L"upper", std::ctype_base::upper); |
| 199 | test(L"UPPER", std::ctype_base::upper); |
| 200 | test(L"upper", std::ctype_base::upper | std::ctype_base::alpha, true); |
| 201 | test(L"Upper", std::ctype_base::upper | std::ctype_base::alpha, true); |
| 202 | |
| 203 | test(L"xdigit", std::ctype_base::xdigit); |
| 204 | test(L"XDIGIT", std::ctype_base::xdigit); |
| 205 | test(L"xdigit", std::ctype_base::xdigit, true); |
| 206 | test(L"Xdigit", std::ctype_base::xdigit, true); |
| 207 | |
Marshall Clow | 8d4ce30 | 2014-03-04 22:44:34 +0000 | [diff] [blame] | 208 | test(L"dig", std::ctype_base::mask()); |
| 209 | test(L"", std::ctype_base::mask()); |
| 210 | test(L"digits", std::ctype_base::mask()); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 211 | } |