Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 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 | 7050530 | 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 | // string_type |
| 16 | // lookup_collatename(ForwardIterator first, ForwardIterator last) const; |
| 17 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 18 | #include <regex> |
| 19 | #include <iterator> |
| 20 | #include <cassert> |
| 21 | #include "iterators.h" |
| 22 | |
| 23 | template <class char_type> |
| 24 | void |
| 25 | test(const char_type* A, const char_type* expected) |
| 26 | { |
| 27 | std::regex_traits<char_type> t; |
| 28 | typedef forward_iterator<const char_type*> F; |
| 29 | assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected); |
| 30 | } |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | test("NUL", "\x00"); |
| 35 | test("alert", "\x07"); |
| 36 | test("backspace", "\x08"); |
| 37 | test("tab", "\x09"); |
| 38 | test("carriage-return", "\x0D"); |
| 39 | test("newline", "\x0A"); |
| 40 | test("vertical-tab", "\x0B"); |
| 41 | test("form-feed", "\x0C"); |
| 42 | test("space", " "); |
| 43 | test("exclamation-mark", "!"); |
| 44 | test("quotation-mark", "\""); |
| 45 | test("number-sign", "#"); |
| 46 | test("dollar-sign", "$"); |
| 47 | test("percent-sign", "%"); |
| 48 | test("ampersand", "&"); |
| 49 | test("apostrophe", "\'"); |
| 50 | test("left-parenthesis", "("); |
| 51 | test("right-parenthesis", ")"); |
| 52 | test("asterisk", "*"); |
| 53 | test("plus-sign", "+"); |
| 54 | test("comma", ","); |
| 55 | test("hyphen-minus", "-"); |
| 56 | test("hyphen", "-"); |
| 57 | test("full-stop", "."); |
| 58 | test("period", "."); |
| 59 | test("slash", "/"); |
| 60 | test("solidus", "/"); |
| 61 | test("zero", "0"); |
| 62 | test("one", "1"); |
| 63 | test("two", "2"); |
| 64 | test("three", "3"); |
| 65 | test("four", "4"); |
| 66 | test("five", "5"); |
| 67 | test("six", "6"); |
| 68 | test("seven", "7"); |
| 69 | test("eight", "8"); |
| 70 | test("nine", "9"); |
| 71 | test("colon", ":"); |
| 72 | test("semicolon", ";"); |
| 73 | test("less-than-sign", "<"); |
| 74 | test("equals-sign", "="); |
| 75 | test("greater-than-sign", ">"); |
| 76 | test("question-mark", "?"); |
| 77 | test("commercial-at", "@"); |
| 78 | for (char c = 'A'; c <= 'Z'; ++c) |
| 79 | { |
| 80 | const char a[2] = {c}; |
| 81 | test(a, a); |
| 82 | } |
| 83 | test("left-square-bracket", "["); |
| 84 | test("backslash", "\\"); |
| 85 | test("reverse-solidus", "\\"); |
| 86 | test("right-square-bracket", "]"); |
| 87 | test("circumflex-accent", "^"); |
| 88 | test("circumflex", "^"); |
| 89 | test("low-line", "_"); |
| 90 | test("underscore", "_"); |
| 91 | test("grave-accent", "`"); |
| 92 | for (char c = 'a'; c <= 'z'; ++c) |
| 93 | { |
| 94 | const char a[2] = {c}; |
| 95 | test(a, a); |
| 96 | } |
| 97 | test("left-brace", "{"); |
| 98 | test("left-curly-bracket", "{"); |
| 99 | test("vertical-line", "|"); |
| 100 | test("right-brace", "}"); |
| 101 | test("right-curly-bracket", "}"); |
| 102 | test("tilde", "~"); |
| 103 | |
| 104 | test("tild", ""); |
| 105 | test("ch", ""); |
| 106 | std::locale::global(std::locale("cs_CZ.ISO8859-2")); |
| 107 | test("ch", "ch"); |
| 108 | std::locale::global(std::locale("C")); |
| 109 | |
| 110 | test(L"NUL", L"\x00"); |
| 111 | test(L"alert", L"\x07"); |
| 112 | test(L"backspace", L"\x08"); |
| 113 | test(L"tab", L"\x09"); |
| 114 | test(L"carriage-return", L"\x0D"); |
| 115 | test(L"newline", L"\x0A"); |
| 116 | test(L"vertical-tab", L"\x0B"); |
| 117 | test(L"form-feed", L"\x0C"); |
| 118 | test(L"space", L" "); |
| 119 | test(L"exclamation-mark", L"!"); |
| 120 | test(L"quotation-mark", L"\""); |
| 121 | test(L"number-sign", L"#"); |
| 122 | test(L"dollar-sign", L"$"); |
| 123 | test(L"percent-sign", L"%"); |
| 124 | test(L"ampersand", L"&"); |
| 125 | test(L"apostrophe", L"\'"); |
| 126 | test(L"left-parenthesis", L"("); |
| 127 | test(L"right-parenthesis", L")"); |
| 128 | test(L"asterisk", L"*"); |
| 129 | test(L"plus-sign", L"+"); |
| 130 | test(L"comma", L","); |
| 131 | test(L"hyphen-minus", L"-"); |
| 132 | test(L"hyphen", L"-"); |
| 133 | test(L"full-stop", L"."); |
| 134 | test(L"period", L"."); |
| 135 | test(L"slash", L"/"); |
| 136 | test(L"solidus", L"/"); |
| 137 | test(L"zero", L"0"); |
| 138 | test(L"one", L"1"); |
| 139 | test(L"two", L"2"); |
| 140 | test(L"three", L"3"); |
| 141 | test(L"four", L"4"); |
| 142 | test(L"five", L"5"); |
| 143 | test(L"six", L"6"); |
| 144 | test(L"seven", L"7"); |
| 145 | test(L"eight", L"8"); |
| 146 | test(L"nine", L"9"); |
| 147 | test(L"colon", L":"); |
| 148 | test(L"semicolon", L";"); |
| 149 | test(L"less-than-sign", L"<"); |
| 150 | test(L"equals-sign", L"="); |
| 151 | test(L"greater-than-sign", L">"); |
| 152 | test(L"question-mark", L"?"); |
| 153 | test(L"commercial-at", L"@"); |
| 154 | for (wchar_t c = L'A'; c <= L'Z'; ++c) |
| 155 | { |
| 156 | const wchar_t a[2] = {c}; |
| 157 | test(a, a); |
| 158 | } |
| 159 | test(L"left-square-bracket", L"["); |
| 160 | test(L"backslash", L"\\"); |
| 161 | test(L"reverse-solidus", L"\\"); |
| 162 | test(L"right-square-bracket", L"]"); |
| 163 | test(L"circumflex-accent", L"^"); |
| 164 | test(L"circumflex", L"^"); |
| 165 | test(L"low-line", L"_"); |
| 166 | test(L"underscore", L"_"); |
| 167 | test(L"grave-accent", L"`"); |
| 168 | for (wchar_t c = L'a'; c <= L'z'; ++c) |
| 169 | { |
| 170 | const wchar_t a[2] = {c}; |
| 171 | test(a, a); |
| 172 | } |
| 173 | test(L"left-brace", L"{"); |
| 174 | test(L"left-curly-bracket", L"{"); |
| 175 | test(L"vertical-line", L"|"); |
| 176 | test(L"right-brace", L"}"); |
| 177 | test(L"right-curly-bracket", L"}"); |
| 178 | test(L"tilde", L"~"); |
| 179 | |
| 180 | test(L"tild", L""); |
| 181 | test(L"ch", L""); |
| 182 | std::locale::global(std::locale("cs_CZ.ISO8859-2")); |
| 183 | test(L"ch", L"ch"); |
| 184 | std::locale::global(std::locale("C")); |
| 185 | } |