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 // <codecvt> 11 12 // template <class Elem, unsigned long Maxcode = 0x10ffff, 13 // codecvt_mode Mode = (codecvt_mode)0> 14 // class codecvt_utf8_utf16 15 // : public codecvt<Elem, char, mbstate_t> 16 // { 17 // // unspecified 18 // }; 19 20 // int length(stateT& state, const externT* from, const externT* from_end, 21 // size_t max) const; 22 23 #include <codecvt> 24 #include <cassert> 25 26 int main() 27 { 28 { 29 typedef std::codecvt_utf8_utf16<wchar_t> C; 30 C c; 31 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 32 std::mbstate_t m; 33 int r = c.length(m, n, n+4, 2); 34 assert(r == 4); 35 36 n[0] = char(0xE1); 37 n[1] = char(0x80); 38 n[2] = char(0x85); 39 r = c.length(m, n, n+3, 2); 40 assert(r == 3); 41 42 n[0] = char(0xD1); 43 n[1] = char(0x93); 44 r = c.length(m, n, n+2, 2); 45 assert(r == 2); 46 47 n[0] = char(0x56); 48 r = c.length(m, n, n+1, 2); 49 assert(r == 1); 50 } 51 { 52 typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C; 53 C c; 54 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 55 std::mbstate_t m; 56 int r = c.length(m, n, n+4, 2); 57 assert(r == 0); 58 59 n[0] = char(0xE1); 60 n[1] = char(0x80); 61 n[2] = char(0x85); 62 r = c.length(m, n, n+3, 2); 63 assert(r == 0); 64 65 n[0] = char(0xD1); 66 n[1] = char(0x93); 67 r = c.length(m, n, n+2, 2); 68 assert(r == 2); 69 70 n[0] = char(0x56); 71 r = c.length(m, n, n+1, 2); 72 assert(r == 1); 73 } 74 { 75 typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::consume_header> C; 76 C c; 77 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)}; 78 std::mbstate_t m; 79 int r = c.length(m, n, n+7, 2); 80 assert(r == 7); 81 82 n[0] = char(0xE1); 83 n[1] = char(0x80); 84 n[2] = char(0x85); 85 r = c.length(m, n, n+3, 2); 86 assert(r == 3); 87 88 n[0] = char(0xD1); 89 n[1] = char(0x93); 90 r = c.length(m, n, n+2, 2); 91 assert(r == 2); 92 93 n[0] = char(0x56); 94 r = c.length(m, n, n+1, 2); 95 assert(r == 1); 96 } 97 { 98 typedef std::codecvt_utf8_utf16<char32_t> C; 99 C c; 100 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 101 std::mbstate_t m; 102 int r = c.length(m, n, n+4, 2); 103 assert(r == 4); 104 105 n[0] = char(0xE1); 106 n[1] = char(0x80); 107 n[2] = char(0x85); 108 r = c.length(m, n, n+3, 2); 109 assert(r == 3); 110 111 n[0] = char(0xD1); 112 n[1] = char(0x93); 113 r = c.length(m, n, n+2, 2); 114 assert(r == 2); 115 116 n[0] = char(0x56); 117 r = c.length(m, n, n+1, 2); 118 assert(r == 1); 119 } 120 { 121 typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C; 122 C c; 123 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 124 std::mbstate_t m; 125 int r = c.length(m, n, n+4, 2); 126 assert(r == 0); 127 128 n[0] = char(0xE1); 129 n[1] = char(0x80); 130 n[2] = char(0x85); 131 r = c.length(m, n, n+3, 2); 132 assert(r == 0); 133 134 n[0] = char(0xD1); 135 n[1] = char(0x93); 136 r = c.length(m, n, n+2, 2); 137 assert(r == 2); 138 139 n[0] = char(0x56); 140 r = c.length(m, n, n+1, 2); 141 assert(r == 1); 142 } 143 { 144 typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::consume_header> C; 145 C c; 146 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)}; 147 std::mbstate_t m; 148 int r = c.length(m, n, n+7, 2); 149 assert(r == 7); 150 151 n[0] = char(0xE1); 152 n[1] = char(0x80); 153 n[2] = char(0x85); 154 r = c.length(m, n, n+3, 2); 155 assert(r == 3); 156 157 n[0] = char(0xD1); 158 n[1] = char(0x93); 159 r = c.length(m, n, n+2, 2); 160 assert(r == 2); 161 162 n[0] = char(0x56); 163 r = c.length(m, n, n+1, 2); 164 assert(r == 1); 165 } 166 { 167 typedef std::codecvt_utf8_utf16<char16_t> C; 168 C c; 169 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 170 std::mbstate_t m; 171 int r = c.length(m, n, n+4, 2); 172 assert(r == 4); 173 174 n[0] = char(0xE1); 175 n[1] = char(0x80); 176 n[2] = char(0x85); 177 r = c.length(m, n, n+3, 2); 178 assert(r == 3); 179 180 n[0] = char(0xD1); 181 n[1] = char(0x93); 182 r = c.length(m, n, n+2, 2); 183 assert(r == 2); 184 185 n[0] = char(0x56); 186 r = c.length(m, n, n+1, 2); 187 assert(r == 1); 188 } 189 { 190 typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C; 191 C c; 192 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)}; 193 std::mbstate_t m; 194 int r = c.length(m, n, n+4, 2); 195 assert(r == 0); 196 197 n[0] = char(0xE1); 198 n[1] = char(0x80); 199 n[2] = char(0x85); 200 r = c.length(m, n, n+3, 2); 201 assert(r == 0); 202 203 n[0] = char(0xD1); 204 n[1] = char(0x93); 205 r = c.length(m, n, n+2, 2); 206 assert(r == 2); 207 208 n[0] = char(0x56); 209 r = c.length(m, n, n+1, 2); 210 assert(r == 1); 211 } 212 { 213 typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::consume_header> C; 214 C c; 215 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)}; 216 std::mbstate_t m; 217 int r = c.length(m, n, n+7, 2); 218 assert(r == 7); 219 220 n[0] = char(0xE1); 221 n[1] = char(0x80); 222 n[2] = char(0x85); 223 r = c.length(m, n, n+3, 2); 224 assert(r == 3); 225 226 n[0] = char(0xD1); 227 n[1] = char(0x93); 228 r = c.length(m, n, n+2, 2); 229 assert(r == 2); 230 231 n[0] = char(0x56); 232 r = c.length(m, n, n+1, 2); 233 assert(r == 1); 234 } 235 } 236