1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <regex> 11 12 // template <class charT> struct regex_traits; 13 14 // int value(charT ch, int radix) const; 15 16 #include <regex> 17 #include <cassert> 18 19 int main() 20 { 21 { 22 std::regex_traits<char> t; 23 24 for (char c = 0; c < '0'; ++c) 25 { 26 assert(t.value(c, 8) == -1); 27 assert(t.value(c, 10) == -1); 28 assert(t.value(c, 16) == -1); 29 } 30 for (char c = '0'; c < '8'; ++c) 31 { 32 assert(t.value(c, 8) == c - '0'); 33 assert(t.value(c, 10) == c - '0'); 34 assert(t.value(c, 16) == c - '0'); 35 } 36 for (char c = '8'; c < ':'; ++c) 37 { 38 assert(t.value(c, 8) == -1); 39 assert(t.value(c, 10) == c - '0'); 40 assert(t.value(c, 16) == c - '0'); 41 } 42 for (char c = ':'; c < 'A'; ++c) 43 { 44 assert(t.value(c, 8) == -1); 45 assert(t.value(c, 10) == -1); 46 assert(t.value(c, 16) == -1); 47 } 48 for (char c = 'A'; c < 'G'; ++c) 49 { 50 assert(t.value(c, 8) == -1); 51 assert(t.value(c, 10) == -1); 52 assert(t.value(c, 16) == c - 'A' +10); 53 } 54 for (char c = 'G'; c < 'a'; ++c) 55 { 56 assert(t.value(c, 8) == -1); 57 assert(t.value(c, 10) == -1); 58 assert(t.value(c, 16) == -1); 59 } 60 for (char c = 'a'; c < 'g'; ++c) 61 { 62 assert(t.value(c, 8) == -1); 63 assert(t.value(c, 10) == -1); 64 assert(t.value(c, 16) == c - 'a' +10); 65 } 66 for (int c = 'g'; c < 256; ++c) 67 { 68 assert(t.value(char(c), 8) == -1); 69 assert(t.value(char(c), 10) == -1); 70 assert(t.value(char(c), 16) == -1); 71 } 72 } 73 { 74 std::regex_traits<wchar_t> t; 75 76 for (wchar_t c = 0; c < '0'; ++c) 77 { 78 assert(t.value(c, 8) == -1); 79 assert(t.value(c, 10) == -1); 80 assert(t.value(c, 16) == -1); 81 } 82 for (wchar_t c = '0'; c < '8'; ++c) 83 { 84 assert(t.value(c, 8) == c - '0'); 85 assert(t.value(c, 10) == c - '0'); 86 assert(t.value(c, 16) == c - '0'); 87 } 88 for (wchar_t c = '8'; c < ':'; ++c) 89 { 90 assert(t.value(c, 8) == -1); 91 assert(t.value(c, 10) == c - '0'); 92 assert(t.value(c, 16) == c - '0'); 93 } 94 for (wchar_t c = ':'; c < 'A'; ++c) 95 { 96 assert(t.value(c, 8) == -1); 97 assert(t.value(c, 10) == -1); 98 assert(t.value(c, 16) == -1); 99 } 100 for (wchar_t c = 'A'; c < 'G'; ++c) 101 { 102 assert(t.value(c, 8) == -1); 103 assert(t.value(c, 10) == -1); 104 assert(t.value(c, 16) == c - 'A' +10); 105 } 106 for (wchar_t c = 'G'; c < 'a'; ++c) 107 { 108 assert(t.value(c, 8) == -1); 109 assert(t.value(c, 10) == -1); 110 assert(t.value(c, 16) == -1); 111 } 112 for (wchar_t c = 'a'; c < 'g'; ++c) 113 { 114 assert(t.value(c, 8) == -1); 115 assert(t.value(c, 10) == -1); 116 assert(t.value(c, 16) == c - 'a' +10); 117 } 118 for (int c = 'g'; c < 0xFFFF; ++c) 119 { 120 assert(t.value(c, 8) == -1); 121 assert(t.value(c, 10) == -1); 122 assert(t.value(c, 16) == -1); 123 } 124 } 125 } 126