| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,2098 +0,0 @@ |
| 1 |
-// This comes from llvm's libcxx project. I've copied the code from there (with very minor modifications) for use with GCC and Clang when libcxx isn't being used. |
|
| 2 |
- |
|
| 3 |
-#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION) |
|
| 4 |
-#pragma once |
|
| 5 |
- |
|
| 6 |
-#include <locale> |
|
| 7 |
- |
|
| 8 |
-namespace std |
|
| 9 |
-{
|
|
| 10 |
- |
|
| 11 |
-enum codecvt_mode |
|
| 12 |
-{
|
|
| 13 |
- consume_header = 4, |
|
| 14 |
- generate_header = 2, |
|
| 15 |
- little_endian = 1 |
|
| 16 |
-}; |
|
| 17 |
- |
|
| 18 |
-// Valid UTF ranges |
|
| 19 |
-// UTF-32 UTF-16 UTF-8 # of code points |
|
| 20 |
-// first second first second third fourth |
|
| 21 |
-// 000000 - 00007F 0000 - 007F 00 - 7F 127 |
|
| 22 |
-// 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920 |
|
| 23 |
-// 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048 |
|
| 24 |
-// 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152 |
|
| 25 |
-// 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048 |
|
| 26 |
-// 00D800 - 00DFFF invalid |
|
| 27 |
-// 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192 |
|
| 28 |
-// 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608 |
|
| 29 |
-// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432 |
|
| 30 |
-// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536 |
|
| 31 |
- |
|
| 32 |
-namespace UnicodeConverters |
|
| 33 |
-{
|
|
| 34 |
- inline codecvt_base::result utf16_to_utf8(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 35 |
- {
|
|
| 36 |
- frm_nxt = frm; |
|
| 37 |
- to_nxt = to; |
|
| 38 |
- if (mode & generate_header) |
|
| 39 |
- {
|
|
| 40 |
- if (to_end - to_nxt < 3) |
|
| 41 |
- return codecvt_base::partial; |
|
| 42 |
- *to_nxt++ = 0xEF; |
|
| 43 |
- *to_nxt++ = 0xBB; |
|
| 44 |
- *to_nxt++ = 0xBF; |
|
| 45 |
- } |
|
| 46 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 47 |
- {
|
|
| 48 |
- uint16_t wc1 = *frm_nxt; |
|
| 49 |
- if (wc1 > Maxcode) |
|
| 50 |
- return codecvt_base::error; |
|
| 51 |
- if (wc1 < 0x0080) |
|
| 52 |
- {
|
|
| 53 |
- if (to_end - to_nxt < 1) |
|
| 54 |
- return codecvt_base::partial; |
|
| 55 |
- *to_nxt++ = static_cast<uint8_t>(wc1); |
|
| 56 |
- } |
|
| 57 |
- else if (wc1 < 0x0800) |
|
| 58 |
- {
|
|
| 59 |
- if (to_end - to_nxt < 2) |
|
| 60 |
- return codecvt_base::partial; |
|
| 61 |
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6)); |
|
| 62 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F)); |
|
| 63 |
- } |
|
| 64 |
- else if (wc1 < 0xD800) |
|
| 65 |
- {
|
|
| 66 |
- if (to_end - to_nxt < 3) |
|
| 67 |
- return codecvt_base::partial; |
|
| 68 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 69 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 70 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 71 |
- } |
|
| 72 |
- else if (wc1 < 0xDC00) |
|
| 73 |
- {
|
|
| 74 |
- if (frm_end - frm_nxt < 2) |
|
| 75 |
- return codecvt_base::partial; |
|
| 76 |
- uint16_t wc2 = frm_nxt[1]; |
|
| 77 |
- if ((wc2 & 0xFC00) != 0xDC00) |
|
| 78 |
- return codecvt_base::error; |
|
| 79 |
- if (to_end - to_nxt < 4) |
|
| 80 |
- return codecvt_base::partial; |
|
| 81 |
- if (((((static_cast<unsigned long>(wc1) & 0x03C0) >> 6) + 1) << 16) + ((static_cast<unsigned long>(wc1) & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode) |
|
| 82 |
- return codecvt_base::error; |
|
| 83 |
- ++frm_nxt; |
|
| 84 |
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1; |
|
| 85 |
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2)); |
|
| 86 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2)); |
|
| 87 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6)); |
|
| 88 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F)); |
|
| 89 |
- } |
|
| 90 |
- else if (wc1 < 0xE000) |
|
| 91 |
- return codecvt_base::error; |
|
| 92 |
- else |
|
| 93 |
- {
|
|
| 94 |
- if (to_end - to_nxt < 3) |
|
| 95 |
- return codecvt_base::partial; |
|
| 96 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 97 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 98 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 99 |
- } |
|
| 100 |
- } |
|
| 101 |
- return codecvt_base::ok; |
|
| 102 |
- } |
|
| 103 |
- |
|
| 104 |
- inline codecvt_base::result utf16_to_utf8(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 105 |
- {
|
|
| 106 |
- frm_nxt = frm; |
|
| 107 |
- to_nxt = to; |
|
| 108 |
- if (mode & generate_header) |
|
| 109 |
- {
|
|
| 110 |
- if (to_end - to_nxt < 3) |
|
| 111 |
- return codecvt_base::partial; |
|
| 112 |
- *to_nxt++ = 0xEF; |
|
| 113 |
- *to_nxt++ = 0xBB; |
|
| 114 |
- *to_nxt++ = 0xBF; |
|
| 115 |
- } |
|
| 116 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 117 |
- {
|
|
| 118 |
- uint16_t wc1 = static_cast<uint16_t>(*frm_nxt); |
|
| 119 |
- if (wc1 > Maxcode) |
|
| 120 |
- return codecvt_base::error; |
|
| 121 |
- if (wc1 < 0x0080) |
|
| 122 |
- {
|
|
| 123 |
- if (to_end - to_nxt < 1) |
|
| 124 |
- return codecvt_base::partial; |
|
| 125 |
- *to_nxt++ = static_cast<uint8_t>(wc1); |
|
| 126 |
- } |
|
| 127 |
- else if (wc1 < 0x0800) |
|
| 128 |
- {
|
|
| 129 |
- if (to_end - to_nxt < 2) |
|
| 130 |
- return codecvt_base::partial; |
|
| 131 |
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6)); |
|
| 132 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F)); |
|
| 133 |
- } |
|
| 134 |
- else if (wc1 < 0xD800) |
|
| 135 |
- {
|
|
| 136 |
- if (to_end - to_nxt < 3) |
|
| 137 |
- return codecvt_base::partial; |
|
| 138 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 139 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 140 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 141 |
- } |
|
| 142 |
- else if (wc1 < 0xDC00) |
|
| 143 |
- {
|
|
| 144 |
- if (frm_end - frm_nxt < 2) |
|
| 145 |
- return codecvt_base::partial; |
|
| 146 |
- uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]); |
|
| 147 |
- if ((wc2 & 0xFC00) != 0xDC00) |
|
| 148 |
- return codecvt_base::error; |
|
| 149 |
- if (to_end - to_nxt < 4) |
|
| 150 |
- return codecvt_base::partial; |
|
| 151 |
- if (((((static_cast<unsigned long>(wc1) & 0x03C0) >> 6) + 1) << 16) + ((static_cast<unsigned long>(wc1) & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode) |
|
| 152 |
- return codecvt_base::error; |
|
| 153 |
- ++frm_nxt; |
|
| 154 |
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1; |
|
| 155 |
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2)); |
|
| 156 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2)); |
|
| 157 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6)); |
|
| 158 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F)); |
|
| 159 |
- } |
|
| 160 |
- else if (wc1 < 0xE000) |
|
| 161 |
- return codecvt_base::error; |
|
| 162 |
- else |
|
| 163 |
- {
|
|
| 164 |
- if (to_end - to_nxt < 3) |
|
| 165 |
- return codecvt_base::partial; |
|
| 166 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 167 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 168 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 169 |
- } |
|
| 170 |
- } |
|
| 171 |
- return codecvt_base::ok; |
|
| 172 |
- } |
|
| 173 |
- |
|
| 174 |
- inline codecvt_base::result utf8_to_utf16(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 175 |
- {
|
|
| 176 |
- frm_nxt = frm; |
|
| 177 |
- to_nxt = to; |
|
| 178 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 179 |
- frm_nxt += 3; |
|
| 180 |
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 181 |
- {
|
|
| 182 |
- uint8_t c1 = *frm_nxt; |
|
| 183 |
- if (c1 > Maxcode) |
|
| 184 |
- return codecvt_base::error; |
|
| 185 |
- if (c1 < 0x80) |
|
| 186 |
- {
|
|
| 187 |
- *to_nxt = static_cast<uint16_t>(c1); |
|
| 188 |
- ++frm_nxt; |
|
| 189 |
- } |
|
| 190 |
- else if (c1 < 0xC2) |
|
| 191 |
- return codecvt_base::error; |
|
| 192 |
- else if (c1 < 0xE0) |
|
| 193 |
- {
|
|
| 194 |
- if (frm_end - frm_nxt < 2) |
|
| 195 |
- return codecvt_base::partial; |
|
| 196 |
- uint8_t c2 = frm_nxt[1]; |
|
| 197 |
- if ((c2 & 0xC0) != 0x80) |
|
| 198 |
- return codecvt_base::error; |
|
| 199 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 200 |
- if (t > Maxcode) |
|
| 201 |
- return codecvt_base::error; |
|
| 202 |
- *to_nxt = t; |
|
| 203 |
- frm_nxt += 2; |
|
| 204 |
- } |
|
| 205 |
- else if (c1 < 0xF0) |
|
| 206 |
- {
|
|
| 207 |
- if (frm_end - frm_nxt < 3) |
|
| 208 |
- return codecvt_base::partial; |
|
| 209 |
- uint8_t c2 = frm_nxt[1]; |
|
| 210 |
- uint8_t c3 = frm_nxt[2]; |
|
| 211 |
- switch (c1) |
|
| 212 |
- {
|
|
| 213 |
- case 0xE0: |
|
| 214 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 215 |
- return codecvt_base::error; |
|
| 216 |
- break; |
|
| 217 |
- case 0xED: |
|
| 218 |
- if ((c2 & 0xE0) != 0x80) |
|
| 219 |
- return codecvt_base::error; |
|
| 220 |
- break; |
|
| 221 |
- default: |
|
| 222 |
- if ((c2 & 0xC0) != 0x80) |
|
| 223 |
- return codecvt_base::error; |
|
| 224 |
- } |
|
| 225 |
- if ((c3 & 0xC0) != 0x80) |
|
| 226 |
- return codecvt_base::error; |
|
| 227 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 228 |
- if (t > Maxcode) |
|
| 229 |
- return codecvt_base::error; |
|
| 230 |
- *to_nxt = t; |
|
| 231 |
- frm_nxt += 3; |
|
| 232 |
- } |
|
| 233 |
- else if (c1 < 0xF5) |
|
| 234 |
- {
|
|
| 235 |
- if (frm_end - frm_nxt < 4) |
|
| 236 |
- return codecvt_base::partial; |
|
| 237 |
- uint8_t c2 = frm_nxt[1]; |
|
| 238 |
- uint8_t c3 = frm_nxt[2]; |
|
| 239 |
- uint8_t c4 = frm_nxt[3]; |
|
| 240 |
- switch (c1) |
|
| 241 |
- {
|
|
| 242 |
- case 0xF0: |
|
| 243 |
- if (c2 < 0x90 || c2 > 0xBF) |
|
| 244 |
- return codecvt_base::error; |
|
| 245 |
- break; |
|
| 246 |
- case 0xF4: |
|
| 247 |
- if ((c2 & 0xF0) != 0x80) |
|
| 248 |
- return codecvt_base::error; |
|
| 249 |
- break; |
|
| 250 |
- default: |
|
| 251 |
- if ((c2 & 0xC0) != 0x80) |
|
| 252 |
- return codecvt_base::error; |
|
| 253 |
- } |
|
| 254 |
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 255 |
- return codecvt_base::error; |
|
| 256 |
- if (to_end - to_nxt < 2) |
|
| 257 |
- return codecvt_base::partial; |
|
| 258 |
- if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 259 |
- return codecvt_base::error; |
|
| 260 |
- *to_nxt = static_cast<uint16_t>(0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4)); |
|
| 261 |
- *++to_nxt = static_cast<uint16_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F)); |
|
| 262 |
- frm_nxt += 4; |
|
| 263 |
- } |
|
| 264 |
- else |
|
| 265 |
- return codecvt_base::error; |
|
| 266 |
- } |
|
| 267 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 268 |
- } |
|
| 269 |
- |
|
| 270 |
- inline codecvt_base::result utf8_to_utf16(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 271 |
- {
|
|
| 272 |
- frm_nxt = frm; |
|
| 273 |
- to_nxt = to; |
|
| 274 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 275 |
- frm_nxt += 3; |
|
| 276 |
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 277 |
- {
|
|
| 278 |
- uint8_t c1 = *frm_nxt; |
|
| 279 |
- if (c1 > Maxcode) |
|
| 280 |
- return codecvt_base::error; |
|
| 281 |
- if (c1 < 0x80) |
|
| 282 |
- {
|
|
| 283 |
- *to_nxt = static_cast<uint32_t>(c1); |
|
| 284 |
- ++frm_nxt; |
|
| 285 |
- } |
|
| 286 |
- else if (c1 < 0xC2) |
|
| 287 |
- return codecvt_base::error; |
|
| 288 |
- else if (c1 < 0xE0) |
|
| 289 |
- {
|
|
| 290 |
- if (frm_end - frm_nxt < 2) |
|
| 291 |
- return codecvt_base::partial; |
|
| 292 |
- uint8_t c2 = frm_nxt[1]; |
|
| 293 |
- if ((c2 & 0xC0) != 0x80) |
|
| 294 |
- return codecvt_base::error; |
|
| 295 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 296 |
- if (t > Maxcode) |
|
| 297 |
- return codecvt_base::error; |
|
| 298 |
- *to_nxt = static_cast<uint32_t>(t); |
|
| 299 |
- frm_nxt += 2; |
|
| 300 |
- } |
|
| 301 |
- else if (c1 < 0xF0) |
|
| 302 |
- {
|
|
| 303 |
- if (frm_end - frm_nxt < 3) |
|
| 304 |
- return codecvt_base::partial; |
|
| 305 |
- uint8_t c2 = frm_nxt[1]; |
|
| 306 |
- uint8_t c3 = frm_nxt[2]; |
|
| 307 |
- switch (c1) |
|
| 308 |
- {
|
|
| 309 |
- case 0xE0: |
|
| 310 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 311 |
- return codecvt_base::error; |
|
| 312 |
- break; |
|
| 313 |
- case 0xED: |
|
| 314 |
- if ((c2 & 0xE0) != 0x80) |
|
| 315 |
- return codecvt_base::error; |
|
| 316 |
- break; |
|
| 317 |
- default: |
|
| 318 |
- if ((c2 & 0xC0) != 0x80) |
|
| 319 |
- return codecvt_base::error; |
|
| 320 |
- } |
|
| 321 |
- if ((c3 & 0xC0) != 0x80) |
|
| 322 |
- return codecvt_base::error; |
|
| 323 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 324 |
- if (t > Maxcode) |
|
| 325 |
- return codecvt_base::error; |
|
| 326 |
- *to_nxt = static_cast<uint32_t>(t); |
|
| 327 |
- frm_nxt += 3; |
|
| 328 |
- } |
|
| 329 |
- else if (c1 < 0xF5) |
|
| 330 |
- {
|
|
| 331 |
- if (frm_end - frm_nxt < 4) |
|
| 332 |
- return codecvt_base::partial; |
|
| 333 |
- uint8_t c2 = frm_nxt[1]; |
|
| 334 |
- uint8_t c3 = frm_nxt[2]; |
|
| 335 |
- uint8_t c4 = frm_nxt[3]; |
|
| 336 |
- switch (c1) |
|
| 337 |
- {
|
|
| 338 |
- case 0xF0: |
|
| 339 |
- if (c2 < 0x90 || c2 > 0xBF) |
|
| 340 |
- return codecvt_base::error; |
|
| 341 |
- break; |
|
| 342 |
- case 0xF4: |
|
| 343 |
- if ((c2 & 0xF0) != 0x80) |
|
| 344 |
- return codecvt_base::error; |
|
| 345 |
- break; |
|
| 346 |
- default: |
|
| 347 |
- if ((c2 & 0xC0) != 0x80) |
|
| 348 |
- return codecvt_base::error; |
|
| 349 |
- } |
|
| 350 |
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 351 |
- return codecvt_base::error; |
|
| 352 |
- if (to_end - to_nxt < 2) |
|
| 353 |
- return codecvt_base::partial; |
|
| 354 |
- if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 355 |
- return codecvt_base::error; |
|
| 356 |
- *to_nxt = static_cast<uint32_t>(0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4)); |
|
| 357 |
- *++to_nxt = static_cast<uint32_t>( 0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F)); |
|
| 358 |
- frm_nxt += 4; |
|
| 359 |
- } |
|
| 360 |
- else |
|
| 361 |
- return codecvt_base::error; |
|
| 362 |
- } |
|
| 363 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 364 |
- } |
|
| 365 |
- |
|
| 366 |
- inline int utf8_to_utf16_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 367 |
- {
|
|
| 368 |
- auto frm_nxt = frm; |
|
| 369 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 370 |
- frm_nxt += 3; |
|
| 371 |
- for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t) |
|
| 372 |
- {
|
|
| 373 |
- uint8_t c1 = *frm_nxt; |
|
| 374 |
- if (c1 > Maxcode) |
|
| 375 |
- break; |
|
| 376 |
- if (c1 < 0x80) |
|
| 377 |
- ++frm_nxt; |
|
| 378 |
- else if (c1 < 0xC2) |
|
| 379 |
- break; |
|
| 380 |
- else if (c1 < 0xE0) |
|
| 381 |
- {
|
|
| 382 |
- if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 383 |
- break; |
|
| 384 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)); |
|
| 385 |
- if (t > Maxcode) |
|
| 386 |
- break; |
|
| 387 |
- frm_nxt += 2; |
|
| 388 |
- } |
|
| 389 |
- else if (c1 < 0xF0) |
|
| 390 |
- {
|
|
| 391 |
- if (frm_end - frm_nxt < 3) |
|
| 392 |
- break; |
|
| 393 |
- uint8_t c2 = frm_nxt[1]; |
|
| 394 |
- uint8_t c3 = frm_nxt[2]; |
|
| 395 |
- switch (c1) |
|
| 396 |
- {
|
|
| 397 |
- case 0xE0: |
|
| 398 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 399 |
- return static_cast<int>(frm_nxt - frm); |
|
| 400 |
- break; |
|
| 401 |
- case 0xED: |
|
| 402 |
- if ((c2 & 0xE0) != 0x80) |
|
| 403 |
- return static_cast<int>(frm_nxt - frm); |
|
| 404 |
- break; |
|
| 405 |
- default: |
|
| 406 |
- if ((c2 & 0xC0) != 0x80) |
|
| 407 |
- return static_cast<int>(frm_nxt - frm); |
|
| 408 |
- } |
|
| 409 |
- if ((c3 & 0xC0) != 0x80) |
|
| 410 |
- break; |
|
| 411 |
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 412 |
- break; |
|
| 413 |
- frm_nxt += 3; |
|
| 414 |
- } |
|
| 415 |
- else if (c1 < 0xF5) |
|
| 416 |
- {
|
|
| 417 |
- if (frm_end - frm_nxt < 4 || mx - nchar16_t < 2) |
|
| 418 |
- break; |
|
| 419 |
- uint8_t c2 = frm_nxt[1]; |
|
| 420 |
- uint8_t c3 = frm_nxt[2]; |
|
| 421 |
- uint8_t c4 = frm_nxt[3]; |
|
| 422 |
- switch (c1) |
|
| 423 |
- {
|
|
| 424 |
- case 0xF0: |
|
| 425 |
- if (c2 < 0x90 || c2 > 0xBF) |
|
| 426 |
- return static_cast<int>(frm_nxt - frm); |
|
| 427 |
- break; |
|
| 428 |
- case 0xF4: |
|
| 429 |
- if ((c2 & 0xF0) != 0x80) |
|
| 430 |
- return static_cast<int>(frm_nxt - frm); |
|
| 431 |
- break; |
|
| 432 |
- default: |
|
| 433 |
- if ((c2 & 0xC0) != 0x80) |
|
| 434 |
- return static_cast<int>(frm_nxt - frm); |
|
| 435 |
- } |
|
| 436 |
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 437 |
- break; |
|
| 438 |
- if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 439 |
- break; |
|
| 440 |
- ++nchar16_t; |
|
| 441 |
- frm_nxt += 4; |
|
| 442 |
- } |
|
| 443 |
- else |
|
| 444 |
- break; |
|
| 445 |
- } |
|
| 446 |
- return static_cast<int>(frm_nxt - frm); |
|
| 447 |
- } |
|
| 448 |
- |
|
| 449 |
- inline codecvt_base::result ucs4_to_utf8(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 450 |
- {
|
|
| 451 |
- frm_nxt = frm; |
|
| 452 |
- to_nxt = to; |
|
| 453 |
- if (mode & generate_header) |
|
| 454 |
- {
|
|
| 455 |
- if (to_end - to_nxt < 3) |
|
| 456 |
- return codecvt_base::partial; |
|
| 457 |
- *to_nxt++ = 0xEF; |
|
| 458 |
- *to_nxt++ = 0xBB; |
|
| 459 |
- *to_nxt++ = 0xBF; |
|
| 460 |
- } |
|
| 461 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 462 |
- {
|
|
| 463 |
- uint32_t wc = *frm_nxt; |
|
| 464 |
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 465 |
- return codecvt_base::error; |
|
| 466 |
- if (wc < 0x000080) |
|
| 467 |
- {
|
|
| 468 |
- if (to_end - to_nxt < 1) |
|
| 469 |
- return codecvt_base::partial; |
|
| 470 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 471 |
- } |
|
| 472 |
- else if (wc < 0x000800) |
|
| 473 |
- {
|
|
| 474 |
- if (to_end - to_nxt < 2) |
|
| 475 |
- return codecvt_base::partial; |
|
| 476 |
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6)); |
|
| 477 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F)); |
|
| 478 |
- } |
|
| 479 |
- else if (wc < 0x010000) |
|
| 480 |
- {
|
|
| 481 |
- if (to_end - to_nxt < 3) |
|
| 482 |
- return codecvt_base::partial; |
|
| 483 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12)); |
|
| 484 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6)); |
|
| 485 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F)); |
|
| 486 |
- } |
|
| 487 |
- else // if (wc < 0x110000) |
|
| 488 |
- {
|
|
| 489 |
- if (to_end - to_nxt < 4) |
|
| 490 |
- return codecvt_base::partial; |
|
| 491 |
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18)); |
|
| 492 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12)); |
|
| 493 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6)); |
|
| 494 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F)); |
|
| 495 |
- } |
|
| 496 |
- } |
|
| 497 |
- return codecvt_base::ok; |
|
| 498 |
- } |
|
| 499 |
- |
|
| 500 |
- inline codecvt_base::result utf8_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 501 |
- {
|
|
| 502 |
- frm_nxt = frm; |
|
| 503 |
- to_nxt = to; |
|
| 504 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 505 |
- frm_nxt += 3; |
|
| 506 |
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 507 |
- {
|
|
| 508 |
- uint8_t c1 = *frm_nxt; |
|
| 509 |
- if (c1 < 0x80) |
|
| 510 |
- {
|
|
| 511 |
- if (c1 > Maxcode) |
|
| 512 |
- return codecvt_base::error; |
|
| 513 |
- *to_nxt = static_cast<uint32_t>(c1); |
|
| 514 |
- ++frm_nxt; |
|
| 515 |
- } |
|
| 516 |
- else if (c1 < 0xC2) |
|
| 517 |
- return codecvt_base::error; |
|
| 518 |
- else if (c1 < 0xE0) |
|
| 519 |
- {
|
|
| 520 |
- if (frm_end - frm_nxt < 2) |
|
| 521 |
- return codecvt_base::partial; |
|
| 522 |
- uint8_t c2 = frm_nxt[1]; |
|
| 523 |
- if ((c2 & 0xC0) != 0x80) |
|
| 524 |
- return codecvt_base::error; |
|
| 525 |
- uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 526 |
- if (t > Maxcode) |
|
| 527 |
- return codecvt_base::error; |
|
| 528 |
- *to_nxt = t; |
|
| 529 |
- frm_nxt += 2; |
|
| 530 |
- } |
|
| 531 |
- else if (c1 < 0xF0) |
|
| 532 |
- {
|
|
| 533 |
- if (frm_end - frm_nxt < 3) |
|
| 534 |
- return codecvt_base::partial; |
|
| 535 |
- uint8_t c2 = frm_nxt[1]; |
|
| 536 |
- uint8_t c3 = frm_nxt[2]; |
|
| 537 |
- switch (c1) |
|
| 538 |
- {
|
|
| 539 |
- case 0xE0: |
|
| 540 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 541 |
- return codecvt_base::error; |
|
| 542 |
- break; |
|
| 543 |
- case 0xED: |
|
| 544 |
- if ((c2 & 0xE0) != 0x80) |
|
| 545 |
- return codecvt_base::error; |
|
| 546 |
- break; |
|
| 547 |
- default: |
|
| 548 |
- if ((c2 & 0xC0) != 0x80) |
|
| 549 |
- return codecvt_base::error; |
|
| 550 |
- } |
|
| 551 |
- if ((c3 & 0xC0) != 0x80) |
|
| 552 |
- return codecvt_base::error; |
|
| 553 |
- uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 554 |
- if (t > Maxcode) |
|
| 555 |
- return codecvt_base::error; |
|
| 556 |
- *to_nxt = t; |
|
| 557 |
- frm_nxt += 3; |
|
| 558 |
- } |
|
| 559 |
- else if (c1 < 0xF5) |
|
| 560 |
- {
|
|
| 561 |
- if (frm_end - frm_nxt < 4) |
|
| 562 |
- return codecvt_base::partial; |
|
| 563 |
- uint8_t c2 = frm_nxt[1]; |
|
| 564 |
- uint8_t c3 = frm_nxt[2]; |
|
| 565 |
- uint8_t c4 = frm_nxt[3]; |
|
| 566 |
- switch (c1) |
|
| 567 |
- {
|
|
| 568 |
- case 0xF0: |
|
| 569 |
- if (c2 < 0x90 || c2 > 0xBF) |
|
| 570 |
- return codecvt_base::error; |
|
| 571 |
- break; |
|
| 572 |
- case 0xF4: |
|
| 573 |
- if ((c2 & 0xF0) != 0x80) |
|
| 574 |
- return codecvt_base::error; |
|
| 575 |
- break; |
|
| 576 |
- default: |
|
| 577 |
- if ((c2 & 0xC0) != 0x80) |
|
| 578 |
- return codecvt_base::error; |
|
| 579 |
- } |
|
| 580 |
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 581 |
- return codecvt_base::error; |
|
| 582 |
- uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); |
|
| 583 |
- if (t > Maxcode) |
|
| 584 |
- return codecvt_base::error; |
|
| 585 |
- *to_nxt = t; |
|
| 586 |
- frm_nxt += 4; |
|
| 587 |
- } |
|
| 588 |
- else |
|
| 589 |
- return codecvt_base::error; |
|
| 590 |
- } |
|
| 591 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 592 |
- } |
|
| 593 |
- |
|
| 594 |
- inline int utf8_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 595 |
- {
|
|
| 596 |
- auto frm_nxt = frm; |
|
| 597 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 598 |
- frm_nxt += 3; |
|
| 599 |
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) |
|
| 600 |
- {
|
|
| 601 |
- uint8_t c1 = *frm_nxt; |
|
| 602 |
- if (c1 < 0x80) |
|
| 603 |
- {
|
|
| 604 |
- if (c1 > Maxcode) |
|
| 605 |
- break; |
|
| 606 |
- ++frm_nxt; |
|
| 607 |
- } |
|
| 608 |
- else if (c1 < 0xC2) |
|
| 609 |
- break; |
|
| 610 |
- else if (c1 < 0xE0) |
|
| 611 |
- {
|
|
| 612 |
- if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 613 |
- break; |
|
| 614 |
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode) |
|
| 615 |
- break; |
|
| 616 |
- frm_nxt += 2; |
|
| 617 |
- } |
|
| 618 |
- else if (c1 < 0xF0) |
|
| 619 |
- {
|
|
| 620 |
- if (frm_end - frm_nxt < 3) |
|
| 621 |
- break; |
|
| 622 |
- uint8_t c2 = frm_nxt[1]; |
|
| 623 |
- uint8_t c3 = frm_nxt[2]; |
|
| 624 |
- switch (c1) |
|
| 625 |
- {
|
|
| 626 |
- case 0xE0: |
|
| 627 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 628 |
- return static_cast<int>(frm_nxt - frm); |
|
| 629 |
- break; |
|
| 630 |
- case 0xED: |
|
| 631 |
- if ((c2 & 0xE0) != 0x80) |
|
| 632 |
- return static_cast<int>(frm_nxt - frm); |
|
| 633 |
- break; |
|
| 634 |
- default: |
|
| 635 |
- if ((c2 & 0xC0) != 0x80) |
|
| 636 |
- return static_cast<int>(frm_nxt - frm); |
|
| 637 |
- } |
|
| 638 |
- if ((c3 & 0xC0) != 0x80) |
|
| 639 |
- break; |
|
| 640 |
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 641 |
- break; |
|
| 642 |
- frm_nxt += 3; |
|
| 643 |
- } |
|
| 644 |
- else if (c1 < 0xF5) |
|
| 645 |
- {
|
|
| 646 |
- if (frm_end - frm_nxt < 4) |
|
| 647 |
- break; |
|
| 648 |
- uint8_t c2 = frm_nxt[1]; |
|
| 649 |
- uint8_t c3 = frm_nxt[2]; |
|
| 650 |
- uint8_t c4 = frm_nxt[3]; |
|
| 651 |
- switch (c1) |
|
| 652 |
- {
|
|
| 653 |
- case 0xF0: |
|
| 654 |
- if (c2 < 0x90 || c2 > 0xBF) |
|
| 655 |
- return static_cast<int>(frm_nxt - frm); |
|
| 656 |
- break; |
|
| 657 |
- case 0xF4: |
|
| 658 |
- if ((c2 & 0xF0) != 0x80) |
|
| 659 |
- return static_cast<int>(frm_nxt - frm); |
|
| 660 |
- break; |
|
| 661 |
- default: |
|
| 662 |
- if ((c2 & 0xC0) != 0x80) |
|
| 663 |
- return static_cast<int>(frm_nxt - frm); |
|
| 664 |
- } |
|
| 665 |
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 666 |
- break; |
|
| 667 |
- if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) | ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode) |
|
| 668 |
- break; |
|
| 669 |
- frm_nxt += 4; |
|
| 670 |
- } |
|
| 671 |
- else |
|
| 672 |
- break; |
|
| 673 |
- } |
|
| 674 |
- return static_cast<int>(frm_nxt - frm); |
|
| 675 |
- } |
|
| 676 |
- |
|
| 677 |
- inline codecvt_base::result ucs2_to_utf8(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 678 |
- {
|
|
| 679 |
- frm_nxt = frm; |
|
| 680 |
- to_nxt = to; |
|
| 681 |
- if (mode & generate_header) |
|
| 682 |
- {
|
|
| 683 |
- if (to_end - to_nxt < 3) |
|
| 684 |
- return codecvt_base::partial; |
|
| 685 |
- *to_nxt++ = 0xEF; |
|
| 686 |
- *to_nxt++ = 0xBB; |
|
| 687 |
- *to_nxt++ = 0xBF; |
|
| 688 |
- } |
|
| 689 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 690 |
- {
|
|
| 691 |
- uint16_t wc = *frm_nxt; |
|
| 692 |
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 693 |
- return codecvt_base::error; |
|
| 694 |
- if (wc < 0x0080) |
|
| 695 |
- {
|
|
| 696 |
- if (to_end - to_nxt < 1) |
|
| 697 |
- return codecvt_base::partial; |
|
| 698 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 699 |
- } |
|
| 700 |
- else if (wc < 0x0800) |
|
| 701 |
- {
|
|
| 702 |
- if (to_end - to_nxt < 2) |
|
| 703 |
- return codecvt_base::partial; |
|
| 704 |
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6)); |
|
| 705 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F)); |
|
| 706 |
- } |
|
| 707 |
- else // if (wc <= 0xFFFF) |
|
| 708 |
- {
|
|
| 709 |
- if (to_end - to_nxt < 3) |
|
| 710 |
- return codecvt_base::partial; |
|
| 711 |
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12)); |
|
| 712 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6)); |
|
| 713 |
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F)); |
|
| 714 |
- } |
|
| 715 |
- } |
|
| 716 |
- return codecvt_base::ok; |
|
| 717 |
- } |
|
| 718 |
- |
|
| 719 |
- inline codecvt_base::result utf8_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 720 |
- {
|
|
| 721 |
- frm_nxt = frm; |
|
| 722 |
- to_nxt = to; |
|
| 723 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 724 |
- frm_nxt += 3; |
|
| 725 |
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 726 |
- {
|
|
| 727 |
- uint8_t c1 = *frm_nxt; |
|
| 728 |
- if (c1 < 0x80) |
|
| 729 |
- {
|
|
| 730 |
- if (c1 > Maxcode) |
|
| 731 |
- return codecvt_base::error; |
|
| 732 |
- *to_nxt = static_cast<uint16_t>(c1); |
|
| 733 |
- ++frm_nxt; |
|
| 734 |
- } |
|
| 735 |
- else if (c1 < 0xC2) |
|
| 736 |
- return codecvt_base::error; |
|
| 737 |
- else if (c1 < 0xE0) |
|
| 738 |
- {
|
|
| 739 |
- if (frm_end - frm_nxt < 2) |
|
| 740 |
- return codecvt_base::partial; |
|
| 741 |
- uint8_t c2 = frm_nxt[1]; |
|
| 742 |
- if ((c2 & 0xC0) != 0x80) |
|
| 743 |
- return codecvt_base::error; |
|
| 744 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 745 |
- if (t > Maxcode) |
|
| 746 |
- return codecvt_base::error; |
|
| 747 |
- *to_nxt = t; |
|
| 748 |
- frm_nxt += 2; |
|
| 749 |
- } |
|
| 750 |
- else if (c1 < 0xF0) |
|
| 751 |
- {
|
|
| 752 |
- if (frm_end - frm_nxt < 3) |
|
| 753 |
- return codecvt_base::partial; |
|
| 754 |
- uint8_t c2 = frm_nxt[1]; |
|
| 755 |
- uint8_t c3 = frm_nxt[2]; |
|
| 756 |
- switch (c1) |
|
| 757 |
- {
|
|
| 758 |
- case 0xE0: |
|
| 759 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 760 |
- return codecvt_base::error; |
|
| 761 |
- break; |
|
| 762 |
- case 0xED: |
|
| 763 |
- if ((c2 & 0xE0) != 0x80) |
|
| 764 |
- return codecvt_base::error; |
|
| 765 |
- break; |
|
| 766 |
- default: |
|
| 767 |
- if ((c2 & 0xC0) != 0x80) |
|
| 768 |
- return codecvt_base::error; |
|
| 769 |
- } |
|
| 770 |
- if ((c3 & 0xC0) != 0x80) |
|
| 771 |
- return codecvt_base::error; |
|
| 772 |
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 773 |
- if (t > Maxcode) |
|
| 774 |
- return codecvt_base::error; |
|
| 775 |
- *to_nxt = t; |
|
| 776 |
- frm_nxt += 3; |
|
| 777 |
- } |
|
| 778 |
- else |
|
| 779 |
- return codecvt_base::error; |
|
| 780 |
- } |
|
| 781 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 782 |
- } |
|
| 783 |
- |
|
| 784 |
- inline int utf8_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 785 |
- {
|
|
| 786 |
- auto frm_nxt = frm; |
|
| 787 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 788 |
- frm_nxt += 3; |
|
| 789 |
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) |
|
| 790 |
- {
|
|
| 791 |
- uint8_t c1 = *frm_nxt; |
|
| 792 |
- if (c1 < 0x80) |
|
| 793 |
- {
|
|
| 794 |
- if (c1 > Maxcode) |
|
| 795 |
- break; |
|
| 796 |
- ++frm_nxt; |
|
| 797 |
- } |
|
| 798 |
- else if (c1 < 0xC2) |
|
| 799 |
- break; |
|
| 800 |
- else if (c1 < 0xE0) |
|
| 801 |
- {
|
|
| 802 |
- if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 803 |
- break; |
|
| 804 |
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode) |
|
| 805 |
- break; |
|
| 806 |
- frm_nxt += 2; |
|
| 807 |
- } |
|
| 808 |
- else if (c1 < 0xF0) |
|
| 809 |
- {
|
|
| 810 |
- if (frm_end - frm_nxt < 3) |
|
| 811 |
- break; |
|
| 812 |
- uint8_t c2 = frm_nxt[1]; |
|
| 813 |
- uint8_t c3 = frm_nxt[2]; |
|
| 814 |
- switch (c1) |
|
| 815 |
- {
|
|
| 816 |
- case 0xE0: |
|
| 817 |
- if ((c2 & 0xE0) != 0xA0) |
|
| 818 |
- return static_cast<int>(frm_nxt - frm); |
|
| 819 |
- break; |
|
| 820 |
- case 0xED: |
|
| 821 |
- if ((c2 & 0xE0) != 0x80) |
|
| 822 |
- return static_cast<int>(frm_nxt - frm); |
|
| 823 |
- break; |
|
| 824 |
- default: |
|
| 825 |
- if ((c2 & 0xC0) != 0x80) |
|
| 826 |
- return static_cast<int>(frm_nxt - frm); |
|
| 827 |
- } |
|
| 828 |
- if ((c3 & 0xC0) != 0x80) |
|
| 829 |
- break; |
|
| 830 |
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 831 |
- break; |
|
| 832 |
- frm_nxt += 3; |
|
| 833 |
- } |
|
| 834 |
- else |
|
| 835 |
- break; |
|
| 836 |
- } |
|
| 837 |
- return static_cast<int>(frm_nxt - frm); |
|
| 838 |
- } |
|
| 839 |
- |
|
| 840 |
- inline codecvt_base::result ucs4_to_utf16be(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 841 |
- {
|
|
| 842 |
- frm_nxt = frm; |
|
| 843 |
- to_nxt = to; |
|
| 844 |
- if (mode & generate_header) |
|
| 845 |
- {
|
|
| 846 |
- if (to_end - to_nxt < 2) |
|
| 847 |
- return codecvt_base::partial; |
|
| 848 |
- *to_nxt++ = 0xFE; |
|
| 849 |
- *to_nxt++ = 0xFF; |
|
| 850 |
- } |
|
| 851 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 852 |
- {
|
|
| 853 |
- uint32_t wc = *frm_nxt; |
|
| 854 |
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 855 |
- return codecvt_base::error; |
|
| 856 |
- if (wc < 0x010000) |
|
| 857 |
- {
|
|
| 858 |
- if (to_end - to_nxt < 2) |
|
| 859 |
- return codecvt_base::partial; |
|
| 860 |
- *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 861 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 862 |
- } |
|
| 863 |
- else |
|
| 864 |
- {
|
|
| 865 |
- if (to_end - to_nxt < 4) |
|
| 866 |
- return codecvt_base::partial; |
|
| 867 |
- uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10)); |
|
| 868 |
- *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 869 |
- *to_nxt++ = static_cast<uint8_t>(t); |
|
| 870 |
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF)); |
|
| 871 |
- *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 872 |
- *to_nxt++ = static_cast<uint8_t>(t); |
|
| 873 |
- } |
|
| 874 |
- } |
|
| 875 |
- return codecvt_base::ok; |
|
| 876 |
- } |
|
| 877 |
- |
|
| 878 |
- inline codecvt_base::result utf16be_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 879 |
- {
|
|
| 880 |
- frm_nxt = frm; |
|
| 881 |
- to_nxt = to; |
|
| 882 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 883 |
- frm_nxt += 2; |
|
| 884 |
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 885 |
- {
|
|
| 886 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 887 |
- if ((c1 & 0xFC00) == 0xDC00) |
|
| 888 |
- return codecvt_base::error; |
|
| 889 |
- if ((c1 & 0xFC00) != 0xD800) |
|
| 890 |
- {
|
|
| 891 |
- if (c1 > Maxcode) |
|
| 892 |
- return codecvt_base::error; |
|
| 893 |
- *to_nxt = static_cast<uint32_t>(c1); |
|
| 894 |
- frm_nxt += 2; |
|
| 895 |
- } |
|
| 896 |
- else |
|
| 897 |
- {
|
|
| 898 |
- if (frm_end - frm_nxt < 4) |
|
| 899 |
- return codecvt_base::partial; |
|
| 900 |
- uint16_t c2 = static_cast<uint16_t>((frm_nxt[2] << 8) | frm_nxt[3]); |
|
| 901 |
- if ((c2 & 0xFC00) != 0xDC00) |
|
| 902 |
- return codecvt_base::error; |
|
| 903 |
- uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 904 |
- if (t > Maxcode) |
|
| 905 |
- return codecvt_base::error; |
|
| 906 |
- *to_nxt = t; |
|
| 907 |
- frm_nxt += 4; |
|
| 908 |
- } |
|
| 909 |
- } |
|
| 910 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 911 |
- } |
|
| 912 |
- |
|
| 913 |
- inline int utf16be_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 914 |
- {
|
|
| 915 |
- auto frm_nxt = frm; |
|
| 916 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 917 |
- frm_nxt += 2; |
|
| 918 |
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) |
|
| 919 |
- {
|
|
| 920 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 921 |
- if ((c1 & 0xFC00) == 0xDC00) |
|
| 922 |
- break; |
|
| 923 |
- if ((c1 & 0xFC00) != 0xD800) |
|
| 924 |
- {
|
|
| 925 |
- if (c1 > Maxcode) |
|
| 926 |
- break; |
|
| 927 |
- frm_nxt += 2; |
|
| 928 |
- } |
|
| 929 |
- else |
|
| 930 |
- {
|
|
| 931 |
- if (frm_end - frm_nxt < 4) |
|
| 932 |
- break; |
|
| 933 |
- uint16_t c2 = static_cast<uint16_t>((frm_nxt[2] << 8) | frm_nxt[3]); |
|
| 934 |
- if ((c2 & 0xFC00) != 0xDC00) |
|
| 935 |
- break; |
|
| 936 |
- uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 937 |
- if (t > Maxcode) |
|
| 938 |
- break; |
|
| 939 |
- frm_nxt += 4; |
|
| 940 |
- } |
|
| 941 |
- } |
|
| 942 |
- return static_cast<int>(frm_nxt - frm); |
|
| 943 |
- } |
|
| 944 |
- |
|
| 945 |
- inline codecvt_base::result ucs4_to_utf16le(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 946 |
- {
|
|
| 947 |
- frm_nxt = frm; |
|
| 948 |
- to_nxt = to; |
|
| 949 |
- if (mode & generate_header) |
|
| 950 |
- {
|
|
| 951 |
- if (to_end - to_nxt < 2) |
|
| 952 |
- return codecvt_base::partial; |
|
| 953 |
- *to_nxt++ = 0xFF; |
|
| 954 |
- *to_nxt++ = 0xFE; |
|
| 955 |
- } |
|
| 956 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 957 |
- {
|
|
| 958 |
- uint32_t wc = *frm_nxt; |
|
| 959 |
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 960 |
- return codecvt_base::error; |
|
| 961 |
- if (wc < 0x010000) |
|
| 962 |
- {
|
|
| 963 |
- if (to_end - to_nxt < 2) |
|
| 964 |
- return codecvt_base::partial; |
|
| 965 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 966 |
- *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 967 |
- } |
|
| 968 |
- else |
|
| 969 |
- {
|
|
| 970 |
- if (to_end - to_nxt < 4) |
|
| 971 |
- return codecvt_base::partial; |
|
| 972 |
- uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10)); |
|
| 973 |
- *to_nxt++ = static_cast<uint8_t>(t); |
|
| 974 |
- *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 975 |
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF)); |
|
| 976 |
- *to_nxt++ = static_cast<uint8_t>(t); |
|
| 977 |
- *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 978 |
- } |
|
| 979 |
- } |
|
| 980 |
- return codecvt_base::ok; |
|
| 981 |
- } |
|
| 982 |
- |
|
| 983 |
- inline codecvt_base::result utf16le_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 984 |
- {
|
|
| 985 |
- frm_nxt = frm; |
|
| 986 |
- to_nxt = to; |
|
| 987 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 988 |
- frm_nxt += 2; |
|
| 989 |
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 990 |
- {
|
|
| 991 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 992 |
- if ((c1 & 0xFC00) == 0xDC00) |
|
| 993 |
- return codecvt_base::error; |
|
| 994 |
- if ((c1 & 0xFC00) != 0xD800) |
|
| 995 |
- {
|
|
| 996 |
- if (c1 > Maxcode) |
|
| 997 |
- return codecvt_base::error; |
|
| 998 |
- *to_nxt = static_cast<uint32_t>(c1); |
|
| 999 |
- frm_nxt += 2; |
|
| 1000 |
- } |
|
| 1001 |
- else |
|
| 1002 |
- {
|
|
| 1003 |
- if (frm_end - frm_nxt < 4) |
|
| 1004 |
- return codecvt_base::partial; |
|
| 1005 |
- uint16_t c2 = static_cast<uint16_t>((frm_nxt[3] << 8) | frm_nxt[2]); |
|
| 1006 |
- if ((c2 & 0xFC00) != 0xDC00) |
|
| 1007 |
- return codecvt_base::error; |
|
| 1008 |
- uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 1009 |
- if (t > Maxcode) |
|
| 1010 |
- return codecvt_base::error; |
|
| 1011 |
- *to_nxt = t; |
|
| 1012 |
- frm_nxt += 4; |
|
| 1013 |
- } |
|
| 1014 |
- } |
|
| 1015 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1016 |
- } |
|
| 1017 |
- |
|
| 1018 |
- inline int utf16le_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1019 |
- {
|
|
| 1020 |
- auto frm_nxt = frm; |
|
| 1021 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1022 |
- frm_nxt += 2; |
|
| 1023 |
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) |
|
| 1024 |
- {
|
|
| 1025 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1026 |
- if ((c1 & 0xFC00) == 0xDC00) |
|
| 1027 |
- break; |
|
| 1028 |
- if ((c1 & 0xFC00) != 0xD800) |
|
| 1029 |
- {
|
|
| 1030 |
- if (c1 > Maxcode) |
|
| 1031 |
- break; |
|
| 1032 |
- frm_nxt += 2; |
|
| 1033 |
- } |
|
| 1034 |
- else |
|
| 1035 |
- {
|
|
| 1036 |
- if (frm_end - frm_nxt < 4) |
|
| 1037 |
- break; |
|
| 1038 |
- uint16_t c2 = static_cast<uint16_t>((frm_nxt[3] << 8) | frm_nxt[2]); |
|
| 1039 |
- if ((c2 & 0xFC00) != 0xDC00) |
|
| 1040 |
- break; |
|
| 1041 |
- uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 1042 |
- if (t > Maxcode) |
|
| 1043 |
- break; |
|
| 1044 |
- frm_nxt += 4; |
|
| 1045 |
- } |
|
| 1046 |
- } |
|
| 1047 |
- return static_cast<int>(frm_nxt - frm); |
|
| 1048 |
- } |
|
| 1049 |
- |
|
| 1050 |
- inline codecvt_base::result ucs2_to_utf16be(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1051 |
- {
|
|
| 1052 |
- frm_nxt = frm; |
|
| 1053 |
- to_nxt = to; |
|
| 1054 |
- if (mode & generate_header) |
|
| 1055 |
- {
|
|
| 1056 |
- if (to_end - to_nxt < 2) |
|
| 1057 |
- return codecvt_base::partial; |
|
| 1058 |
- *to_nxt++ = 0xFE; |
|
| 1059 |
- *to_nxt++ = 0xFF; |
|
| 1060 |
- } |
|
| 1061 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 1062 |
- {
|
|
| 1063 |
- uint16_t wc = *frm_nxt; |
|
| 1064 |
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 1065 |
- return codecvt_base::error; |
|
| 1066 |
- if (to_end - to_nxt < 2) |
|
| 1067 |
- return codecvt_base::partial; |
|
| 1068 |
- *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 1069 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 1070 |
- } |
|
| 1071 |
- return codecvt_base::ok; |
|
| 1072 |
- } |
|
| 1073 |
- |
|
| 1074 |
- inline codecvt_base::result utf16be_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1075 |
- {
|
|
| 1076 |
- frm_nxt = frm; |
|
| 1077 |
- to_nxt = to; |
|
| 1078 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 1079 |
- frm_nxt += 2; |
|
| 1080 |
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 1081 |
- {
|
|
| 1082 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 1083 |
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1084 |
- return codecvt_base::error; |
|
| 1085 |
- *to_nxt = c1; |
|
| 1086 |
- frm_nxt += 2; |
|
| 1087 |
- } |
|
| 1088 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1089 |
- } |
|
| 1090 |
- |
|
| 1091 |
- inline int utf16be_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1092 |
- {
|
|
| 1093 |
- auto frm_nxt = frm; |
|
| 1094 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 1095 |
- frm_nxt += 2; |
|
| 1096 |
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) |
|
| 1097 |
- {
|
|
| 1098 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 1099 |
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1100 |
- break; |
|
| 1101 |
- frm_nxt += 2; |
|
| 1102 |
- } |
|
| 1103 |
- return static_cast<int>(frm_nxt - frm); |
|
| 1104 |
- } |
|
| 1105 |
- |
|
| 1106 |
- inline codecvt_base::result ucs2_to_utf16le(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1107 |
- {
|
|
| 1108 |
- frm_nxt = frm; |
|
| 1109 |
- to_nxt = to; |
|
| 1110 |
- if (mode & generate_header) |
|
| 1111 |
- {
|
|
| 1112 |
- if (to_end - to_nxt < 2) |
|
| 1113 |
- return codecvt_base::partial; |
|
| 1114 |
- *to_nxt++ = 0xFF; |
|
| 1115 |
- *to_nxt++ = 0xFE; |
|
| 1116 |
- } |
|
| 1117 |
- for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 1118 |
- {
|
|
| 1119 |
- uint16_t wc = *frm_nxt; |
|
| 1120 |
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 1121 |
- return codecvt_base::error; |
|
| 1122 |
- if (to_end - to_nxt < 2) |
|
| 1123 |
- return codecvt_base::partial; |
|
| 1124 |
- *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 1125 |
- *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 1126 |
- } |
|
| 1127 |
- return codecvt_base::ok; |
|
| 1128 |
- } |
|
| 1129 |
- |
|
| 1130 |
- inline codecvt_base::result utf16le_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1131 |
- {
|
|
| 1132 |
- frm_nxt = frm; |
|
| 1133 |
- to_nxt = to; |
|
| 1134 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1135 |
- frm_nxt += 2; |
|
| 1136 |
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 1137 |
- {
|
|
| 1138 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1139 |
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1140 |
- return codecvt_base::error; |
|
| 1141 |
- *to_nxt = c1; |
|
| 1142 |
- frm_nxt += 2; |
|
| 1143 |
- } |
|
| 1144 |
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1145 |
- } |
|
| 1146 |
- |
|
| 1147 |
- inline int utf16le_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1148 |
- {
|
|
| 1149 |
- auto frm_nxt = frm; |
|
| 1150 |
- if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1151 |
- frm_nxt += 2; |
|
| 1152 |
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) |
|
| 1153 |
- {
|
|
| 1154 |
- uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1155 |
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1156 |
- break; |
|
| 1157 |
- frm_nxt += 2; |
|
| 1158 |
- } |
|
| 1159 |
- return static_cast<int>(frm_nxt - frm); |
|
| 1160 |
- } |
|
| 1161 |
-} |
|
| 1162 |
- |
|
| 1163 |
-template<> class codecvt<char16_t, char, mbstate_t> : public locale::facet, public codecvt_base |
|
| 1164 |
-{
|
|
| 1165 |
-public: |
|
| 1166 |
- typedef char16_t intern_type; |
|
| 1167 |
- typedef char extern_type; |
|
| 1168 |
- typedef mbstate_t state_type; |
|
| 1169 |
- |
|
| 1170 |
- explicit codecvt(size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1171 |
- |
|
| 1172 |
- result out(state_type &__st, const intern_type *__frm, const intern_type *__frm_end, const intern_type *&__frm_nxt, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1173 |
- {
|
|
| 1174 |
- return this->do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1175 |
- } |
|
| 1176 |
- |
|
| 1177 |
- result unshift(state_type &__st, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1178 |
- {
|
|
| 1179 |
- return this->do_unshift(__st, __to, __to_end, __to_nxt); |
|
| 1180 |
- } |
|
| 1181 |
- |
|
| 1182 |
- result in(state_type &__st, const extern_type *__frm, const extern_type *__frm_end, const extern_type *&__frm_nxt, intern_type *__to, intern_type *__to_end, intern_type *&__to_nxt) const |
|
| 1183 |
- {
|
|
| 1184 |
- return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1185 |
- } |
|
| 1186 |
- |
|
| 1187 |
- int encoding() const noexcept |
|
| 1188 |
- {
|
|
| 1189 |
- return this->do_encoding(); |
|
| 1190 |
- } |
|
| 1191 |
- |
|
| 1192 |
- bool always_noconv() const noexcept |
|
| 1193 |
- {
|
|
| 1194 |
- return this->do_always_noconv(); |
|
| 1195 |
- } |
|
| 1196 |
- |
|
| 1197 |
- int length(state_type &__st, const extern_type *__frm, const extern_type *__end, size_t __mx) const |
|
| 1198 |
- {
|
|
| 1199 |
- return this->do_length(__st, __frm, __end, __mx); |
|
| 1200 |
- } |
|
| 1201 |
- |
|
| 1202 |
- int max_length() const noexcept |
|
| 1203 |
- {
|
|
| 1204 |
- return this->do_max_length(); |
|
| 1205 |
- } |
|
| 1206 |
- |
|
| 1207 |
- static locale::id id; |
|
| 1208 |
- |
|
| 1209 |
-protected: |
|
| 1210 |
- explicit codecvt(const char *, size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1211 |
- |
|
| 1212 |
- ~codecvt() { }
|
|
| 1213 |
- |
|
| 1214 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1215 |
- {
|
|
| 1216 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1217 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1218 |
- auto _frm_nxt = _frm; |
|
| 1219 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1220 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1221 |
- auto _to_nxt = _to; |
|
| 1222 |
- auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1223 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1224 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1225 |
- return r; |
|
| 1226 |
- } |
|
| 1227 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1228 |
- {
|
|
| 1229 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1230 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1231 |
- auto _frm_nxt = _frm; |
|
| 1232 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1233 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1234 |
- auto _to_nxt = _to; |
|
| 1235 |
- auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1236 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1237 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1238 |
- return r; |
|
| 1239 |
- } |
|
| 1240 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1241 |
- {
|
|
| 1242 |
- to_nxt = to; |
|
| 1243 |
- return noconv; |
|
| 1244 |
- } |
|
| 1245 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1246 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1247 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1248 |
- {
|
|
| 1249 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1250 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1251 |
- return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx); |
|
| 1252 |
- } |
|
| 1253 |
- virtual int do_max_length() const noexcept { return 4; }
|
|
| 1254 |
-}; |
|
| 1255 |
- |
|
| 1256 |
-template<> class codecvt<char32_t, char, mbstate_t> : public locale::facet, public codecvt_base |
|
| 1257 |
-{
|
|
| 1258 |
-public: |
|
| 1259 |
- typedef char32_t intern_type; |
|
| 1260 |
- typedef char extern_type; |
|
| 1261 |
- typedef mbstate_t state_type; |
|
| 1262 |
- |
|
| 1263 |
- explicit codecvt(size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1264 |
- |
|
| 1265 |
- result out(state_type &__st, const intern_type *__frm, const intern_type *__frm_end, const intern_type *&__frm_nxt, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1266 |
- {
|
|
| 1267 |
- return this->do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1268 |
- } |
|
| 1269 |
- |
|
| 1270 |
- result unshift(state_type &__st, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1271 |
- {
|
|
| 1272 |
- return this->do_unshift(__st, __to, __to_end, __to_nxt); |
|
| 1273 |
- } |
|
| 1274 |
- |
|
| 1275 |
- result in(state_type &__st, const extern_type *__frm, const extern_type *__frm_end, const extern_type *&__frm_nxt, intern_type *__to, intern_type *__to_end, intern_type *&__to_nxt) const |
|
| 1276 |
- {
|
|
| 1277 |
- return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1278 |
- } |
|
| 1279 |
- |
|
| 1280 |
- int encoding() const noexcept |
|
| 1281 |
- {
|
|
| 1282 |
- return this->do_encoding(); |
|
| 1283 |
- } |
|
| 1284 |
- |
|
| 1285 |
- bool always_noconv() const noexcept |
|
| 1286 |
- {
|
|
| 1287 |
- return this->do_always_noconv(); |
|
| 1288 |
- } |
|
| 1289 |
- |
|
| 1290 |
- int length(state_type &__st, const extern_type *__frm, const extern_type *__end, size_t __mx) const |
|
| 1291 |
- {
|
|
| 1292 |
- return this->do_length(__st, __frm, __end, __mx); |
|
| 1293 |
- } |
|
| 1294 |
- |
|
| 1295 |
- int max_length() const noexcept |
|
| 1296 |
- {
|
|
| 1297 |
- return this->do_max_length(); |
|
| 1298 |
- } |
|
| 1299 |
- |
|
| 1300 |
- static locale::id id; |
|
| 1301 |
- |
|
| 1302 |
-protected: |
|
| 1303 |
- explicit codecvt(const char *, size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1304 |
- |
|
| 1305 |
- ~codecvt() { }
|
|
| 1306 |
- |
|
| 1307 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1308 |
- {
|
|
| 1309 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1310 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1311 |
- auto _frm_nxt = _frm; |
|
| 1312 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1313 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1314 |
- auto _to_nxt = _to; |
|
| 1315 |
- auto r = UnicodeConverters::ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1316 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1317 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1318 |
- return r; |
|
| 1319 |
- } |
|
| 1320 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1321 |
- {
|
|
| 1322 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1323 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1324 |
- auto _frm_nxt = _frm; |
|
| 1325 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1326 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1327 |
- auto _to_nxt = _to; |
|
| 1328 |
- auto r = UnicodeConverters::utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1329 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1330 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1331 |
- return r; |
|
| 1332 |
- } |
|
| 1333 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1334 |
- {
|
|
| 1335 |
- to_nxt = to; |
|
| 1336 |
- return noconv; |
|
| 1337 |
- } |
|
| 1338 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1339 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1340 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1341 |
- {
|
|
| 1342 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1343 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1344 |
- return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx); |
|
| 1345 |
- } |
|
| 1346 |
- virtual int do_max_length() const noexcept { return 4; }
|
|
| 1347 |
-}; |
|
| 1348 |
- |
|
| 1349 |
-template<class _Elem> class __codecvt_utf8; |
|
| 1350 |
- |
|
| 1351 |
-template<> class __codecvt_utf8<wchar_t> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1352 |
-{
|
|
| 1353 |
- unsigned long _Maxcode_; |
|
| 1354 |
- codecvt_mode _Mode_; |
|
| 1355 |
-public: |
|
| 1356 |
- typedef wchar_t intern_type; |
|
| 1357 |
- typedef char extern_type; |
|
| 1358 |
- typedef mbstate_t state_type; |
|
| 1359 |
- |
|
| 1360 |
- explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1361 |
-protected: |
|
| 1362 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1363 |
- {
|
|
| 1364 |
-#ifdef _WIN32 |
|
| 1365 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1366 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1367 |
-#else |
|
| 1368 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1369 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1370 |
-#endif |
|
| 1371 |
- auto _frm_nxt = _frm; |
|
| 1372 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1373 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1374 |
- auto _to_nxt = _to; |
|
| 1375 |
- auto r = UnicodeConverters:: |
|
| 1376 |
-#ifdef _WIN32 |
|
| 1377 |
- ucs2_to_utf8 |
|
| 1378 |
-#else |
|
| 1379 |
- ucs4_to_utf8 |
|
| 1380 |
-#endif |
|
| 1381 |
- (_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1382 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1383 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1384 |
- return r; |
|
| 1385 |
- } |
|
| 1386 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1387 |
- {
|
|
| 1388 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1389 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1390 |
- auto _frm_nxt = _frm; |
|
| 1391 |
-#ifdef _WIN32 |
|
| 1392 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1393 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1394 |
-#else |
|
| 1395 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1396 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1397 |
-#endif |
|
| 1398 |
- auto _to_nxt = _to; |
|
| 1399 |
- auto r = UnicodeConverters:: |
|
| 1400 |
-#ifdef _WIN32 |
|
| 1401 |
- utf8_to_ucs2 |
|
| 1402 |
-#else |
|
| 1403 |
- utf8_to_ucs4 |
|
| 1404 |
-#endif |
|
| 1405 |
- (_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1406 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1407 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1408 |
- return r; |
|
| 1409 |
- } |
|
| 1410 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1411 |
- {
|
|
| 1412 |
- to_nxt = to; |
|
| 1413 |
- return noconv; |
|
| 1414 |
- } |
|
| 1415 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1416 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1417 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1418 |
- {
|
|
| 1419 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1420 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1421 |
- return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1422 |
- } |
|
| 1423 |
- virtual int do_max_length() const noexcept |
|
| 1424 |
- {
|
|
| 1425 |
- if (this->_Mode_ & consume_header) |
|
| 1426 |
- return 7; |
|
| 1427 |
- return 4; |
|
| 1428 |
- } |
|
| 1429 |
-}; |
|
| 1430 |
- |
|
| 1431 |
-template<> class __codecvt_utf8<char16_t> : public codecvt<char16_t, char, mbstate_t> |
|
| 1432 |
-{
|
|
| 1433 |
- unsigned long _Maxcode_; |
|
| 1434 |
- codecvt_mode _Mode_; |
|
| 1435 |
-public: |
|
| 1436 |
- typedef char16_t intern_type; |
|
| 1437 |
- typedef char extern_type; |
|
| 1438 |
- typedef mbstate_t state_type; |
|
| 1439 |
- |
|
| 1440 |
- explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1441 |
-protected: |
|
| 1442 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1443 |
- {
|
|
| 1444 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1445 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1446 |
- auto _frm_nxt = _frm; |
|
| 1447 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1448 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1449 |
- auto _to_nxt = _to; |
|
| 1450 |
- auto r = UnicodeConverters::ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1451 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1452 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1453 |
- return r; |
|
| 1454 |
- } |
|
| 1455 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1456 |
- {
|
|
| 1457 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1458 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1459 |
- auto _frm_nxt = _frm; |
|
| 1460 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1461 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1462 |
- auto _to_nxt = _to; |
|
| 1463 |
- auto r = UnicodeConverters::utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1464 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1465 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1466 |
- return r; |
|
| 1467 |
- } |
|
| 1468 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1469 |
- {
|
|
| 1470 |
- to_nxt = to; |
|
| 1471 |
- return noconv; |
|
| 1472 |
- } |
|
| 1473 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1474 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1475 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1476 |
- {
|
|
| 1477 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1478 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1479 |
- return UnicodeConverters::utf8_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1480 |
- } |
|
| 1481 |
- virtual int do_max_length() const noexcept |
|
| 1482 |
- {
|
|
| 1483 |
- if (this->_Mode_ & consume_header) |
|
| 1484 |
- return 6; |
|
| 1485 |
- return 3; |
|
| 1486 |
- } |
|
| 1487 |
-}; |
|
| 1488 |
- |
|
| 1489 |
-template<> class __codecvt_utf8<char32_t> : public codecvt<char32_t, char, mbstate_t> |
|
| 1490 |
-{
|
|
| 1491 |
- unsigned long _Maxcode_; |
|
| 1492 |
- codecvt_mode _Mode_; |
|
| 1493 |
-public: |
|
| 1494 |
- typedef char32_t intern_type; |
|
| 1495 |
- typedef char extern_type; |
|
| 1496 |
- typedef mbstate_t state_type; |
|
| 1497 |
- |
|
| 1498 |
- explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1499 |
-protected: |
|
| 1500 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1501 |
- {
|
|
| 1502 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1503 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1504 |
- auto _frm_nxt = _frm; |
|
| 1505 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1506 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1507 |
- auto _to_nxt = _to; |
|
| 1508 |
- auto r = UnicodeConverters::ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1509 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1510 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1511 |
- return r; |
|
| 1512 |
- } |
|
| 1513 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1514 |
- {
|
|
| 1515 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1516 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1517 |
- auto _frm_nxt = _frm; |
|
| 1518 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1519 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1520 |
- auto _to_nxt = _to; |
|
| 1521 |
- auto r = UnicodeConverters::utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1522 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1523 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1524 |
- return r; |
|
| 1525 |
- } |
|
| 1526 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1527 |
- {
|
|
| 1528 |
- to_nxt = to; |
|
| 1529 |
- return noconv; |
|
| 1530 |
- } |
|
| 1531 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1532 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1533 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1534 |
- {
|
|
| 1535 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1536 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1537 |
- return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1538 |
- } |
|
| 1539 |
- virtual int do_max_length() const noexcept |
|
| 1540 |
- {
|
|
| 1541 |
- if (this->_Mode_ & consume_header) |
|
| 1542 |
- return 7; |
|
| 1543 |
- return 4; |
|
| 1544 |
- } |
|
| 1545 |
-}; |
|
| 1546 |
- |
|
| 1547 |
-template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf8 : public __codecvt_utf8<_Elem> |
|
| 1548 |
-{
|
|
| 1549 |
-public: |
|
| 1550 |
- explicit codecvt_utf8(size_t __refs = 0) : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) { }
|
|
| 1551 |
- |
|
| 1552 |
- ~codecvt_utf8() { }
|
|
| 1553 |
-}; |
|
| 1554 |
- |
|
| 1555 |
-template<class _Elem, bool _LittleEndian> class __codecvt_utf16; |
|
| 1556 |
- |
|
| 1557 |
-template<> class __codecvt_utf16<wchar_t, false> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1558 |
-{
|
|
| 1559 |
- unsigned long _Maxcode_; |
|
| 1560 |
- codecvt_mode _Mode_; |
|
| 1561 |
-public: |
|
| 1562 |
- typedef wchar_t intern_type; |
|
| 1563 |
- typedef char extern_type; |
|
| 1564 |
- typedef mbstate_t state_type; |
|
| 1565 |
- |
|
| 1566 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1567 |
-protected: |
|
| 1568 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1569 |
- {
|
|
| 1570 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1571 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1572 |
- auto _frm_nxt = _frm; |
|
| 1573 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1574 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1575 |
- auto _to_nxt = _to; |
|
| 1576 |
- auto r = UnicodeConverters::ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1577 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1578 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1579 |
- return r; |
|
| 1580 |
- } |
|
| 1581 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1582 |
- {
|
|
| 1583 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1584 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1585 |
- auto _frm_nxt = _frm; |
|
| 1586 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1587 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1588 |
- auto _to_nxt = _to; |
|
| 1589 |
- auto r = UnicodeConverters::utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1590 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1591 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1592 |
- return r; |
|
| 1593 |
- } |
|
| 1594 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1595 |
- {
|
|
| 1596 |
- to_nxt = to; |
|
| 1597 |
- return noconv; |
|
| 1598 |
- } |
|
| 1599 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1600 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1601 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1602 |
- {
|
|
| 1603 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1604 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1605 |
- return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1606 |
- } |
|
| 1607 |
- virtual int do_max_length() const noexcept |
|
| 1608 |
- {
|
|
| 1609 |
- if (this->_Mode_ & consume_header) |
|
| 1610 |
- return 6; |
|
| 1611 |
- return 4; |
|
| 1612 |
- } |
|
| 1613 |
-}; |
|
| 1614 |
- |
|
| 1615 |
-template<> class __codecvt_utf16<wchar_t, true> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1616 |
-{
|
|
| 1617 |
- unsigned long _Maxcode_; |
|
| 1618 |
- codecvt_mode _Mode_; |
|
| 1619 |
-public: |
|
| 1620 |
- typedef wchar_t intern_type; |
|
| 1621 |
- typedef char extern_type; |
|
| 1622 |
- typedef mbstate_t state_type; |
|
| 1623 |
- |
|
| 1624 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1625 |
-protected: |
|
| 1626 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1627 |
- {
|
|
| 1628 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1629 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1630 |
- auto _frm_nxt = _frm; |
|
| 1631 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1632 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1633 |
- auto _to_nxt = _to; |
|
| 1634 |
- auto r = UnicodeConverters::ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1635 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1636 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1637 |
- return r; |
|
| 1638 |
- } |
|
| 1639 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1640 |
- {
|
|
| 1641 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1642 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1643 |
- auto _frm_nxt = _frm; |
|
| 1644 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1645 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1646 |
- auto _to_nxt = _to; |
|
| 1647 |
- auto r = UnicodeConverters::utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1648 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1649 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1650 |
- return r; |
|
| 1651 |
- } |
|
| 1652 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1653 |
- {
|
|
| 1654 |
- to_nxt = to; |
|
| 1655 |
- return noconv; |
|
| 1656 |
- } |
|
| 1657 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1658 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1659 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1660 |
- {
|
|
| 1661 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1662 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1663 |
- return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1664 |
- } |
|
| 1665 |
- virtual int do_max_length() const noexcept |
|
| 1666 |
- {
|
|
| 1667 |
- if (this->_Mode_ & consume_header) |
|
| 1668 |
- return 6; |
|
| 1669 |
- return 4; |
|
| 1670 |
- } |
|
| 1671 |
-}; |
|
| 1672 |
- |
|
| 1673 |
-template<> class __codecvt_utf16<char16_t, false> : public codecvt<char16_t, char, mbstate_t> |
|
| 1674 |
-{
|
|
| 1675 |
- unsigned long _Maxcode_; |
|
| 1676 |
- codecvt_mode _Mode_; |
|
| 1677 |
-public: |
|
| 1678 |
- typedef char16_t intern_type; |
|
| 1679 |
- typedef char extern_type; |
|
| 1680 |
- typedef mbstate_t state_type; |
|
| 1681 |
- |
|
| 1682 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1683 |
-protected: |
|
| 1684 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1685 |
- {
|
|
| 1686 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1687 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1688 |
- auto _frm_nxt = _frm; |
|
| 1689 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1690 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1691 |
- auto _to_nxt = _to; |
|
| 1692 |
- auto r = UnicodeConverters::ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1693 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1694 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1695 |
- return r; |
|
| 1696 |
- } |
|
| 1697 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1698 |
- {
|
|
| 1699 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1700 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1701 |
- auto _frm_nxt = _frm; |
|
| 1702 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1703 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1704 |
- auto _to_nxt = _to; |
|
| 1705 |
- auto r = UnicodeConverters::utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1706 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1707 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1708 |
- return r; |
|
| 1709 |
- } |
|
| 1710 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1711 |
- {
|
|
| 1712 |
- to_nxt = to; |
|
| 1713 |
- return noconv; |
|
| 1714 |
- } |
|
| 1715 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1716 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1717 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1718 |
- {
|
|
| 1719 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1720 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1721 |
- return UnicodeConverters::utf16be_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1722 |
- } |
|
| 1723 |
- virtual int do_max_length() const noexcept |
|
| 1724 |
- {
|
|
| 1725 |
- if (this->_Mode_ & consume_header) |
|
| 1726 |
- return 4; |
|
| 1727 |
- return 2; |
|
| 1728 |
- } |
|
| 1729 |
-}; |
|
| 1730 |
- |
|
| 1731 |
-template<> class __codecvt_utf16<char16_t, true> : public codecvt<char16_t, char, mbstate_t> |
|
| 1732 |
-{
|
|
| 1733 |
- unsigned long _Maxcode_; |
|
| 1734 |
- codecvt_mode _Mode_; |
|
| 1735 |
-public: |
|
| 1736 |
- typedef char16_t intern_type; |
|
| 1737 |
- typedef char extern_type; |
|
| 1738 |
- typedef mbstate_t state_type; |
|
| 1739 |
- |
|
| 1740 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1741 |
-protected: |
|
| 1742 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1743 |
- {
|
|
| 1744 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1745 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1746 |
- auto _frm_nxt = _frm; |
|
| 1747 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1748 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1749 |
- auto _to_nxt = _to; |
|
| 1750 |
- auto r = UnicodeConverters::ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1751 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1752 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1753 |
- return r; |
|
| 1754 |
- } |
|
| 1755 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1756 |
- {
|
|
| 1757 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1758 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1759 |
- auto _frm_nxt = _frm; |
|
| 1760 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1761 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1762 |
- auto _to_nxt = _to; |
|
| 1763 |
- auto r = UnicodeConverters::utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1764 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1765 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1766 |
- return r; |
|
| 1767 |
- } |
|
| 1768 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1769 |
- {
|
|
| 1770 |
- to_nxt = to; |
|
| 1771 |
- return noconv; |
|
| 1772 |
- } |
|
| 1773 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1774 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1775 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1776 |
- {
|
|
| 1777 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1778 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1779 |
- return UnicodeConverters::utf16le_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1780 |
- } |
|
| 1781 |
- virtual int do_max_length() const noexcept |
|
| 1782 |
- {
|
|
| 1783 |
- if (this->_Mode_ & consume_header) |
|
| 1784 |
- return 4; |
|
| 1785 |
- return 2; |
|
| 1786 |
- } |
|
| 1787 |
-}; |
|
| 1788 |
- |
|
| 1789 |
-template<> class __codecvt_utf16<char32_t, false> : public codecvt<char32_t, char, mbstate_t> |
|
| 1790 |
-{
|
|
| 1791 |
- unsigned long _Maxcode_; |
|
| 1792 |
- codecvt_mode _Mode_; |
|
| 1793 |
-public: |
|
| 1794 |
- typedef char32_t intern_type; |
|
| 1795 |
- typedef char extern_type; |
|
| 1796 |
- typedef mbstate_t state_type; |
|
| 1797 |
- |
|
| 1798 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1799 |
-protected: |
|
| 1800 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1801 |
- {
|
|
| 1802 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1803 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1804 |
- auto _frm_nxt = _frm; |
|
| 1805 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1806 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1807 |
- auto _to_nxt = _to; |
|
| 1808 |
- auto r = UnicodeConverters::ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1809 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1810 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1811 |
- return r; |
|
| 1812 |
- } |
|
| 1813 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1814 |
- {
|
|
| 1815 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1816 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1817 |
- auto _frm_nxt = _frm; |
|
| 1818 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1819 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1820 |
- auto _to_nxt = _to; |
|
| 1821 |
- auto r = UnicodeConverters::utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1822 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1823 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1824 |
- return r; |
|
| 1825 |
- } |
|
| 1826 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1827 |
- {
|
|
| 1828 |
- to_nxt = to; |
|
| 1829 |
- return noconv; |
|
| 1830 |
- } |
|
| 1831 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1832 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1833 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1834 |
- {
|
|
| 1835 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1836 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1837 |
- return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1838 |
- } |
|
| 1839 |
- virtual int do_max_length() const noexcept |
|
| 1840 |
- {
|
|
| 1841 |
- if (this->_Mode_ & consume_header) |
|
| 1842 |
- return 6; |
|
| 1843 |
- return 4; |
|
| 1844 |
- } |
|
| 1845 |
-}; |
|
| 1846 |
- |
|
| 1847 |
-template<> class __codecvt_utf16<char32_t, true> : public codecvt<char32_t, char, mbstate_t> |
|
| 1848 |
-{
|
|
| 1849 |
- unsigned long _Maxcode_; |
|
| 1850 |
- codecvt_mode _Mode_; |
|
| 1851 |
-public: |
|
| 1852 |
- typedef char32_t intern_type; |
|
| 1853 |
- typedef char extern_type; |
|
| 1854 |
- typedef mbstate_t state_type; |
|
| 1855 |
- |
|
| 1856 |
- explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1857 |
-protected: |
|
| 1858 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1859 |
- {
|
|
| 1860 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1861 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1862 |
- auto _frm_nxt = _frm; |
|
| 1863 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1864 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1865 |
- auto _to_nxt = _to; |
|
| 1866 |
- auto r = UnicodeConverters::ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1867 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1868 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1869 |
- return r; |
|
| 1870 |
- } |
|
| 1871 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1872 |
- {
|
|
| 1873 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1874 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1875 |
- auto _frm_nxt = _frm; |
|
| 1876 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1877 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1878 |
- auto _to_nxt = _to; |
|
| 1879 |
- auto r = UnicodeConverters::utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1880 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1881 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1882 |
- return r; |
|
| 1883 |
- } |
|
| 1884 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1885 |
- {
|
|
| 1886 |
- to_nxt = to; |
|
| 1887 |
- return noconv; |
|
| 1888 |
- } |
|
| 1889 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1890 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1891 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1892 |
- {
|
|
| 1893 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1894 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1895 |
- return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1896 |
- } |
|
| 1897 |
- virtual int do_max_length() const noexcept |
|
| 1898 |
- {
|
|
| 1899 |
- if (this->_Mode_ & consume_header) |
|
| 1900 |
- return 6; |
|
| 1901 |
- return 4; |
|
| 1902 |
- } |
|
| 1903 |
-}; |
|
| 1904 |
- |
|
| 1905 |
-template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf16 : public __codecvt_utf16<_Elem, _Mode & little_endian> |
|
| 1906 |
-{
|
|
| 1907 |
-public: |
|
| 1908 |
- explicit codecvt_utf16(size_t __refs = 0) : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) { }
|
|
| 1909 |
- |
|
| 1910 |
- ~codecvt_utf16() { }
|
|
| 1911 |
-}; |
|
| 1912 |
- |
|
| 1913 |
-template<class _Elem> class __codecvt_utf8_utf16; |
|
| 1914 |
- |
|
| 1915 |
-template<> class __codecvt_utf8_utf16<wchar_t> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1916 |
-{
|
|
| 1917 |
- unsigned long _Maxcode_; |
|
| 1918 |
- codecvt_mode _Mode_; |
|
| 1919 |
-public: |
|
| 1920 |
- typedef wchar_t intern_type; |
|
| 1921 |
- typedef char extern_type; |
|
| 1922 |
- typedef mbstate_t state_type; |
|
| 1923 |
- |
|
| 1924 |
- explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1925 |
-protected: |
|
| 1926 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1927 |
- {
|
|
| 1928 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1929 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1930 |
- auto _frm_nxt = _frm; |
|
| 1931 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1932 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1933 |
- auto _to_nxt = _to; |
|
| 1934 |
- auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1935 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1936 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1937 |
- return r; |
|
| 1938 |
- } |
|
| 1939 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1940 |
- {
|
|
| 1941 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1942 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1943 |
- auto _frm_nxt = _frm; |
|
| 1944 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1945 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1946 |
- auto _to_nxt = _to; |
|
| 1947 |
- auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1948 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1949 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1950 |
- return r; |
|
| 1951 |
- } |
|
| 1952 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1953 |
- {
|
|
| 1954 |
- to_nxt = to; |
|
| 1955 |
- return noconv; |
|
| 1956 |
- } |
|
| 1957 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 1958 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1959 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1960 |
- {
|
|
| 1961 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1962 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1963 |
- return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1964 |
- } |
|
| 1965 |
- virtual int do_max_length() const noexcept |
|
| 1966 |
- {
|
|
| 1967 |
- if (this->_Mode_ & consume_header) |
|
| 1968 |
- return 7; |
|
| 1969 |
- return 4; |
|
| 1970 |
- } |
|
| 1971 |
-}; |
|
| 1972 |
- |
|
| 1973 |
-template<> class __codecvt_utf8_utf16<char32_t> : public codecvt<char32_t, char, mbstate_t> |
|
| 1974 |
-{
|
|
| 1975 |
- unsigned long _Maxcode_; |
|
| 1976 |
- codecvt_mode _Mode_; |
|
| 1977 |
-public: |
|
| 1978 |
- typedef char32_t intern_type; |
|
| 1979 |
- typedef char extern_type; |
|
| 1980 |
- typedef mbstate_t state_type; |
|
| 1981 |
- |
|
| 1982 |
- explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1983 |
-protected: |
|
| 1984 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1985 |
- {
|
|
| 1986 |
- auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1987 |
- auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1988 |
- auto _frm_nxt = _frm; |
|
| 1989 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1990 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1991 |
- auto _to_nxt = _to; |
|
| 1992 |
- auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1993 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1994 |
- to_nxt = to + (_to_nxt - _to); |
|
| 1995 |
- return r; |
|
| 1996 |
- } |
|
| 1997 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1998 |
- {
|
|
| 1999 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2000 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2001 |
- auto _frm_nxt = _frm; |
|
| 2002 |
- auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 2003 |
- auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 2004 |
- auto _to_nxt = _to; |
|
| 2005 |
- auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2006 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2007 |
- to_nxt = to + (_to_nxt - _to); |
|
| 2008 |
- return r; |
|
| 2009 |
- } |
|
| 2010 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 2011 |
- {
|
|
| 2012 |
- to_nxt = to; |
|
| 2013 |
- return noconv; |
|
| 2014 |
- } |
|
| 2015 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 2016 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 2017 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 2018 |
- {
|
|
| 2019 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2020 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2021 |
- return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 2022 |
- } |
|
| 2023 |
- virtual int do_max_length() const noexcept |
|
| 2024 |
- {
|
|
| 2025 |
- if (this->_Mode_ & consume_header) |
|
| 2026 |
- return 7; |
|
| 2027 |
- return 4; |
|
| 2028 |
- } |
|
| 2029 |
-}; |
|
| 2030 |
- |
|
| 2031 |
-template<> class __codecvt_utf8_utf16<char16_t> : public codecvt<char16_t, char, mbstate_t> |
|
| 2032 |
-{
|
|
| 2033 |
- unsigned long _Maxcode_; |
|
| 2034 |
- codecvt_mode _Mode_; |
|
| 2035 |
-public: |
|
| 2036 |
- typedef char16_t intern_type; |
|
| 2037 |
- typedef char extern_type; |
|
| 2038 |
- typedef mbstate_t state_type; |
|
| 2039 |
- |
|
| 2040 |
- explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 2041 |
-protected: |
|
| 2042 |
- virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 2043 |
- {
|
|
| 2044 |
- auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 2045 |
- auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 2046 |
- auto _frm_nxt = _frm; |
|
| 2047 |
- auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 2048 |
- auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 2049 |
- auto _to_nxt = _to; |
|
| 2050 |
- auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2051 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2052 |
- to_nxt = to + (_to_nxt - _to); |
|
| 2053 |
- return r; |
|
| 2054 |
- } |
|
| 2055 |
- virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 2056 |
- {
|
|
| 2057 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2058 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2059 |
- auto _frm_nxt = _frm; |
|
| 2060 |
- auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 2061 |
- auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 2062 |
- auto _to_nxt = _to; |
|
| 2063 |
- auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2064 |
- frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2065 |
- to_nxt = to + (_to_nxt - _to); |
|
| 2066 |
- return r; |
|
| 2067 |
- } |
|
| 2068 |
- virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 2069 |
- {
|
|
| 2070 |
- to_nxt = to; |
|
| 2071 |
- return noconv; |
|
| 2072 |
- } |
|
| 2073 |
- virtual int do_encoding() const noexcept { return 0; }
|
|
| 2074 |
- virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 2075 |
- virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 2076 |
- {
|
|
| 2077 |
- auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2078 |
- auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2079 |
- return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 2080 |
- } |
|
| 2081 |
- virtual int do_max_length() const noexcept |
|
| 2082 |
- {
|
|
| 2083 |
- if (this->_Mode_ & consume_header) |
|
| 2084 |
- return 7; |
|
| 2085 |
- return 4; |
|
| 2086 |
- } |
|
| 2087 |
-}; |
|
| 2088 |
- |
|
| 2089 |
-template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf8_utf16 : public __codecvt_utf8_utf16<_Elem> |
|
| 2090 |
-{
|
|
| 2091 |
-public: |
|
| 2092 |
- explicit codecvt_utf8_utf16(size_t __refs = 0) : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) { }
|
|
| 2093 |
- |
|
| 2094 |
- ~codecvt_utf8_utf16() {}
|
|
| 2095 |
-}; |
|
| 2096 |
- |
|
| 2097 |
-} |
|
| 2098 |
-#endif |
* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).
| ... | ... |
@@ -1184,12 +1184,12 @@ public: |
| 1184 | 1184 |
return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1185 | 1185 |
} |
| 1186 | 1186 |
|
| 1187 |
- int encoding() const throw() |
|
| 1187 |
+ int encoding() const noexcept |
|
| 1188 | 1188 |
{
|
| 1189 | 1189 |
return this->do_encoding(); |
| 1190 | 1190 |
} |
| 1191 | 1191 |
|
| 1192 |
- bool always_noconv() const throw() |
|
| 1192 |
+ bool always_noconv() const noexcept |
|
| 1193 | 1193 |
{
|
| 1194 | 1194 |
return this->do_always_noconv(); |
| 1195 | 1195 |
} |
| ... | ... |
@@ -1199,7 +1199,7 @@ public: |
| 1199 | 1199 |
return this->do_length(__st, __frm, __end, __mx); |
| 1200 | 1200 |
} |
| 1201 | 1201 |
|
| 1202 |
- int max_length() const throw() |
|
| 1202 |
+ int max_length() const noexcept |
|
| 1203 | 1203 |
{
|
| 1204 | 1204 |
return this->do_max_length(); |
| 1205 | 1205 |
} |
| ... | ... |
@@ -1242,15 +1242,15 @@ protected: |
| 1242 | 1242 |
to_nxt = to; |
| 1243 | 1243 |
return noconv; |
| 1244 | 1244 |
} |
| 1245 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1246 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1245 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1246 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1247 | 1247 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1248 | 1248 |
{
|
| 1249 | 1249 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1250 | 1250 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1251 | 1251 |
return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx); |
| 1252 | 1252 |
} |
| 1253 |
- virtual int do_max_length() const throw() { return 4; }
|
|
| 1253 |
+ virtual int do_max_length() const noexcept { return 4; }
|
|
| 1254 | 1254 |
}; |
| 1255 | 1255 |
|
| 1256 | 1256 |
template<> class codecvt<char32_t, char, mbstate_t> : public locale::facet, public codecvt_base |
| ... | ... |
@@ -1277,12 +1277,12 @@ public: |
| 1277 | 1277 |
return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1278 | 1278 |
} |
| 1279 | 1279 |
|
| 1280 |
- int encoding() const throw() |
|
| 1280 |
+ int encoding() const noexcept |
|
| 1281 | 1281 |
{
|
| 1282 | 1282 |
return this->do_encoding(); |
| 1283 | 1283 |
} |
| 1284 | 1284 |
|
| 1285 |
- bool always_noconv() const throw() |
|
| 1285 |
+ bool always_noconv() const noexcept |
|
| 1286 | 1286 |
{
|
| 1287 | 1287 |
return this->do_always_noconv(); |
| 1288 | 1288 |
} |
| ... | ... |
@@ -1292,7 +1292,7 @@ public: |
| 1292 | 1292 |
return this->do_length(__st, __frm, __end, __mx); |
| 1293 | 1293 |
} |
| 1294 | 1294 |
|
| 1295 |
- int max_length() const throw() |
|
| 1295 |
+ int max_length() const noexcept |
|
| 1296 | 1296 |
{
|
| 1297 | 1297 |
return this->do_max_length(); |
| 1298 | 1298 |
} |
| ... | ... |
@@ -1335,15 +1335,15 @@ protected: |
| 1335 | 1335 |
to_nxt = to; |
| 1336 | 1336 |
return noconv; |
| 1337 | 1337 |
} |
| 1338 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1339 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1338 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1339 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1340 | 1340 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1341 | 1341 |
{
|
| 1342 | 1342 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1343 | 1343 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1344 | 1344 |
return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx); |
| 1345 | 1345 |
} |
| 1346 |
- virtual int do_max_length() const throw() { return 4; }
|
|
| 1346 |
+ virtual int do_max_length() const noexcept { return 4; }
|
|
| 1347 | 1347 |
}; |
| 1348 | 1348 |
|
| 1349 | 1349 |
template<class _Elem> class __codecvt_utf8; |
| ... | ... |
@@ -1412,15 +1412,15 @@ protected: |
| 1412 | 1412 |
to_nxt = to; |
| 1413 | 1413 |
return noconv; |
| 1414 | 1414 |
} |
| 1415 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1416 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1415 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1416 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1417 | 1417 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1418 | 1418 |
{
|
| 1419 | 1419 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1420 | 1420 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1421 | 1421 |
return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1422 | 1422 |
} |
| 1423 |
- virtual int do_max_length() const throw() |
|
| 1423 |
+ virtual int do_max_length() const noexcept |
|
| 1424 | 1424 |
{
|
| 1425 | 1425 |
if (this->_Mode_ & consume_header) |
| 1426 | 1426 |
return 7; |
| ... | ... |
@@ -1470,15 +1470,15 @@ protected: |
| 1470 | 1470 |
to_nxt = to; |
| 1471 | 1471 |
return noconv; |
| 1472 | 1472 |
} |
| 1473 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1474 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1473 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1474 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1475 | 1475 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1476 | 1476 |
{
|
| 1477 | 1477 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1478 | 1478 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1479 | 1479 |
return UnicodeConverters::utf8_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1480 | 1480 |
} |
| 1481 |
- virtual int do_max_length() const throw() |
|
| 1481 |
+ virtual int do_max_length() const noexcept |
|
| 1482 | 1482 |
{
|
| 1483 | 1483 |
if (this->_Mode_ & consume_header) |
| 1484 | 1484 |
return 6; |
| ... | ... |
@@ -1528,15 +1528,15 @@ protected: |
| 1528 | 1528 |
to_nxt = to; |
| 1529 | 1529 |
return noconv; |
| 1530 | 1530 |
} |
| 1531 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1532 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1531 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1532 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1533 | 1533 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1534 | 1534 |
{
|
| 1535 | 1535 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1536 | 1536 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1537 | 1537 |
return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1538 | 1538 |
} |
| 1539 |
- virtual int do_max_length() const throw() |
|
| 1539 |
+ virtual int do_max_length() const noexcept |
|
| 1540 | 1540 |
{
|
| 1541 | 1541 |
if (this->_Mode_ & consume_header) |
| 1542 | 1542 |
return 7; |
| ... | ... |
@@ -1596,15 +1596,15 @@ protected: |
| 1596 | 1596 |
to_nxt = to; |
| 1597 | 1597 |
return noconv; |
| 1598 | 1598 |
} |
| 1599 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1600 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1599 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1600 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1601 | 1601 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1602 | 1602 |
{
|
| 1603 | 1603 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1604 | 1604 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1605 | 1605 |
return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1606 | 1606 |
} |
| 1607 |
- virtual int do_max_length() const throw() |
|
| 1607 |
+ virtual int do_max_length() const noexcept |
|
| 1608 | 1608 |
{
|
| 1609 | 1609 |
if (this->_Mode_ & consume_header) |
| 1610 | 1610 |
return 6; |
| ... | ... |
@@ -1654,15 +1654,15 @@ protected: |
| 1654 | 1654 |
to_nxt = to; |
| 1655 | 1655 |
return noconv; |
| 1656 | 1656 |
} |
| 1657 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1658 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1657 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1658 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1659 | 1659 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1660 | 1660 |
{
|
| 1661 | 1661 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1662 | 1662 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1663 | 1663 |
return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1664 | 1664 |
} |
| 1665 |
- virtual int do_max_length() const throw() |
|
| 1665 |
+ virtual int do_max_length() const noexcept |
|
| 1666 | 1666 |
{
|
| 1667 | 1667 |
if (this->_Mode_ & consume_header) |
| 1668 | 1668 |
return 6; |
| ... | ... |
@@ -1712,15 +1712,15 @@ protected: |
| 1712 | 1712 |
to_nxt = to; |
| 1713 | 1713 |
return noconv; |
| 1714 | 1714 |
} |
| 1715 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1716 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1715 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1716 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1717 | 1717 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1718 | 1718 |
{
|
| 1719 | 1719 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1720 | 1720 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1721 | 1721 |
return UnicodeConverters::utf16be_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1722 | 1722 |
} |
| 1723 |
- virtual int do_max_length() const throw() |
|
| 1723 |
+ virtual int do_max_length() const noexcept |
|
| 1724 | 1724 |
{
|
| 1725 | 1725 |
if (this->_Mode_ & consume_header) |
| 1726 | 1726 |
return 4; |
| ... | ... |
@@ -1770,15 +1770,15 @@ protected: |
| 1770 | 1770 |
to_nxt = to; |
| 1771 | 1771 |
return noconv; |
| 1772 | 1772 |
} |
| 1773 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1774 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1773 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1774 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1775 | 1775 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1776 | 1776 |
{
|
| 1777 | 1777 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1778 | 1778 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1779 | 1779 |
return UnicodeConverters::utf16le_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1780 | 1780 |
} |
| 1781 |
- virtual int do_max_length() const throw() |
|
| 1781 |
+ virtual int do_max_length() const noexcept |
|
| 1782 | 1782 |
{
|
| 1783 | 1783 |
if (this->_Mode_ & consume_header) |
| 1784 | 1784 |
return 4; |
| ... | ... |
@@ -1828,15 +1828,15 @@ protected: |
| 1828 | 1828 |
to_nxt = to; |
| 1829 | 1829 |
return noconv; |
| 1830 | 1830 |
} |
| 1831 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1832 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1831 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1832 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1833 | 1833 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1834 | 1834 |
{
|
| 1835 | 1835 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1836 | 1836 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1837 | 1837 |
return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1838 | 1838 |
} |
| 1839 |
- virtual int do_max_length() const throw() |
|
| 1839 |
+ virtual int do_max_length() const noexcept |
|
| 1840 | 1840 |
{
|
| 1841 | 1841 |
if (this->_Mode_ & consume_header) |
| 1842 | 1842 |
return 6; |
| ... | ... |
@@ -1886,15 +1886,15 @@ protected: |
| 1886 | 1886 |
to_nxt = to; |
| 1887 | 1887 |
return noconv; |
| 1888 | 1888 |
} |
| 1889 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1890 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1889 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1890 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1891 | 1891 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1892 | 1892 |
{
|
| 1893 | 1893 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1894 | 1894 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1895 | 1895 |
return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1896 | 1896 |
} |
| 1897 |
- virtual int do_max_length() const throw() |
|
| 1897 |
+ virtual int do_max_length() const noexcept |
|
| 1898 | 1898 |
{
|
| 1899 | 1899 |
if (this->_Mode_ & consume_header) |
| 1900 | 1900 |
return 6; |
| ... | ... |
@@ -1954,15 +1954,15 @@ protected: |
| 1954 | 1954 |
to_nxt = to; |
| 1955 | 1955 |
return noconv; |
| 1956 | 1956 |
} |
| 1957 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 1958 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1957 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 1958 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 1959 | 1959 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 1960 | 1960 |
{
|
| 1961 | 1961 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 1962 | 1962 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 1963 | 1963 |
return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 1964 | 1964 |
} |
| 1965 |
- virtual int do_max_length() const throw() |
|
| 1965 |
+ virtual int do_max_length() const noexcept |
|
| 1966 | 1966 |
{
|
| 1967 | 1967 |
if (this->_Mode_ & consume_header) |
| 1968 | 1968 |
return 7; |
| ... | ... |
@@ -2012,15 +2012,15 @@ protected: |
| 2012 | 2012 |
to_nxt = to; |
| 2013 | 2013 |
return noconv; |
| 2014 | 2014 |
} |
| 2015 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 2016 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 2015 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 2016 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 2017 | 2017 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 2018 | 2018 |
{
|
| 2019 | 2019 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 2020 | 2020 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 2021 | 2021 |
return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 2022 | 2022 |
} |
| 2023 |
- virtual int do_max_length() const throw() |
|
| 2023 |
+ virtual int do_max_length() const noexcept |
|
| 2024 | 2024 |
{
|
| 2025 | 2025 |
if (this->_Mode_ & consume_header) |
| 2026 | 2026 |
return 7; |
| ... | ... |
@@ -2070,15 +2070,15 @@ protected: |
| 2070 | 2070 |
to_nxt = to; |
| 2071 | 2071 |
return noconv; |
| 2072 | 2072 |
} |
| 2073 |
- virtual int do_encoding() const throw() { return 0; }
|
|
| 2074 |
- virtual bool do_always_noconv() const throw() { return false; }
|
|
| 2073 |
+ virtual int do_encoding() const noexcept { return 0; }
|
|
| 2074 |
+ virtual bool do_always_noconv() const noexcept { return false; }
|
|
| 2075 | 2075 |
virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
| 2076 | 2076 |
{
|
| 2077 | 2077 |
auto _frm = reinterpret_cast<const uint8_t *>(frm); |
| 2078 | 2078 |
auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
| 2079 | 2079 |
return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
| 2080 | 2080 |
} |
| 2081 |
- virtual int do_max_length() const throw() |
|
| 2081 |
+ virtual int do_max_length() const noexcept |
|
| 2082 | 2082 |
{
|
| 2083 | 2083 |
if (this->_Mode_ & consume_header) |
| 2084 | 2084 |
return 7; |
| ... | ... |
@@ -2094,5 +2094,5 @@ public: |
| 2094 | 2094 |
~codecvt_utf8_utf16() {}
|
| 2095 | 2095 |
}; |
| 2096 | 2096 |
|
| 2097 |
-}; |
|
| 2097 |
+} |
|
| 2098 | 2098 |
#endif |
* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,2098 @@ |
| 1 |
+// This comes from llvm's libcxx project. I've copied the code from there (with very minor modifications) for use with GCC and Clang when libcxx isn't being used. |
|
| 2 |
+ |
|
| 3 |
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION) |
|
| 4 |
+#pragma once |
|
| 5 |
+ |
|
| 6 |
+#include <locale> |
|
| 7 |
+ |
|
| 8 |
+namespace std |
|
| 9 |
+{
|
|
| 10 |
+ |
|
| 11 |
+enum codecvt_mode |
|
| 12 |
+{
|
|
| 13 |
+ consume_header = 4, |
|
| 14 |
+ generate_header = 2, |
|
| 15 |
+ little_endian = 1 |
|
| 16 |
+}; |
|
| 17 |
+ |
|
| 18 |
+// Valid UTF ranges |
|
| 19 |
+// UTF-32 UTF-16 UTF-8 # of code points |
|
| 20 |
+// first second first second third fourth |
|
| 21 |
+// 000000 - 00007F 0000 - 007F 00 - 7F 127 |
|
| 22 |
+// 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920 |
|
| 23 |
+// 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048 |
|
| 24 |
+// 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152 |
|
| 25 |
+// 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048 |
|
| 26 |
+// 00D800 - 00DFFF invalid |
|
| 27 |
+// 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192 |
|
| 28 |
+// 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608 |
|
| 29 |
+// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432 |
|
| 30 |
+// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536 |
|
| 31 |
+ |
|
| 32 |
+namespace UnicodeConverters |
|
| 33 |
+{
|
|
| 34 |
+ inline codecvt_base::result utf16_to_utf8(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 35 |
+ {
|
|
| 36 |
+ frm_nxt = frm; |
|
| 37 |
+ to_nxt = to; |
|
| 38 |
+ if (mode & generate_header) |
|
| 39 |
+ {
|
|
| 40 |
+ if (to_end - to_nxt < 3) |
|
| 41 |
+ return codecvt_base::partial; |
|
| 42 |
+ *to_nxt++ = 0xEF; |
|
| 43 |
+ *to_nxt++ = 0xBB; |
|
| 44 |
+ *to_nxt++ = 0xBF; |
|
| 45 |
+ } |
|
| 46 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 47 |
+ {
|
|
| 48 |
+ uint16_t wc1 = *frm_nxt; |
|
| 49 |
+ if (wc1 > Maxcode) |
|
| 50 |
+ return codecvt_base::error; |
|
| 51 |
+ if (wc1 < 0x0080) |
|
| 52 |
+ {
|
|
| 53 |
+ if (to_end - to_nxt < 1) |
|
| 54 |
+ return codecvt_base::partial; |
|
| 55 |
+ *to_nxt++ = static_cast<uint8_t>(wc1); |
|
| 56 |
+ } |
|
| 57 |
+ else if (wc1 < 0x0800) |
|
| 58 |
+ {
|
|
| 59 |
+ if (to_end - to_nxt < 2) |
|
| 60 |
+ return codecvt_base::partial; |
|
| 61 |
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6)); |
|
| 62 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F)); |
|
| 63 |
+ } |
|
| 64 |
+ else if (wc1 < 0xD800) |
|
| 65 |
+ {
|
|
| 66 |
+ if (to_end - to_nxt < 3) |
|
| 67 |
+ return codecvt_base::partial; |
|
| 68 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 69 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 70 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 71 |
+ } |
|
| 72 |
+ else if (wc1 < 0xDC00) |
|
| 73 |
+ {
|
|
| 74 |
+ if (frm_end - frm_nxt < 2) |
|
| 75 |
+ return codecvt_base::partial; |
|
| 76 |
+ uint16_t wc2 = frm_nxt[1]; |
|
| 77 |
+ if ((wc2 & 0xFC00) != 0xDC00) |
|
| 78 |
+ return codecvt_base::error; |
|
| 79 |
+ if (to_end - to_nxt < 4) |
|
| 80 |
+ return codecvt_base::partial; |
|
| 81 |
+ if (((((static_cast<unsigned long>(wc1) & 0x03C0) >> 6) + 1) << 16) + ((static_cast<unsigned long>(wc1) & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode) |
|
| 82 |
+ return codecvt_base::error; |
|
| 83 |
+ ++frm_nxt; |
|
| 84 |
+ uint8_t z = ((wc1 & 0x03C0) >> 6) + 1; |
|
| 85 |
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2)); |
|
| 86 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2)); |
|
| 87 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6)); |
|
| 88 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F)); |
|
| 89 |
+ } |
|
| 90 |
+ else if (wc1 < 0xE000) |
|
| 91 |
+ return codecvt_base::error; |
|
| 92 |
+ else |
|
| 93 |
+ {
|
|
| 94 |
+ if (to_end - to_nxt < 3) |
|
| 95 |
+ return codecvt_base::partial; |
|
| 96 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 97 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 98 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 99 |
+ } |
|
| 100 |
+ } |
|
| 101 |
+ return codecvt_base::ok; |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ inline codecvt_base::result utf16_to_utf8(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 105 |
+ {
|
|
| 106 |
+ frm_nxt = frm; |
|
| 107 |
+ to_nxt = to; |
|
| 108 |
+ if (mode & generate_header) |
|
| 109 |
+ {
|
|
| 110 |
+ if (to_end - to_nxt < 3) |
|
| 111 |
+ return codecvt_base::partial; |
|
| 112 |
+ *to_nxt++ = 0xEF; |
|
| 113 |
+ *to_nxt++ = 0xBB; |
|
| 114 |
+ *to_nxt++ = 0xBF; |
|
| 115 |
+ } |
|
| 116 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 117 |
+ {
|
|
| 118 |
+ uint16_t wc1 = static_cast<uint16_t>(*frm_nxt); |
|
| 119 |
+ if (wc1 > Maxcode) |
|
| 120 |
+ return codecvt_base::error; |
|
| 121 |
+ if (wc1 < 0x0080) |
|
| 122 |
+ {
|
|
| 123 |
+ if (to_end - to_nxt < 1) |
|
| 124 |
+ return codecvt_base::partial; |
|
| 125 |
+ *to_nxt++ = static_cast<uint8_t>(wc1); |
|
| 126 |
+ } |
|
| 127 |
+ else if (wc1 < 0x0800) |
|
| 128 |
+ {
|
|
| 129 |
+ if (to_end - to_nxt < 2) |
|
| 130 |
+ return codecvt_base::partial; |
|
| 131 |
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6)); |
|
| 132 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F)); |
|
| 133 |
+ } |
|
| 134 |
+ else if (wc1 < 0xD800) |
|
| 135 |
+ {
|
|
| 136 |
+ if (to_end - to_nxt < 3) |
|
| 137 |
+ return codecvt_base::partial; |
|
| 138 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 139 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 140 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 141 |
+ } |
|
| 142 |
+ else if (wc1 < 0xDC00) |
|
| 143 |
+ {
|
|
| 144 |
+ if (frm_end - frm_nxt < 2) |
|
| 145 |
+ return codecvt_base::partial; |
|
| 146 |
+ uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]); |
|
| 147 |
+ if ((wc2 & 0xFC00) != 0xDC00) |
|
| 148 |
+ return codecvt_base::error; |
|
| 149 |
+ if (to_end - to_nxt < 4) |
|
| 150 |
+ return codecvt_base::partial; |
|
| 151 |
+ if (((((static_cast<unsigned long>(wc1) & 0x03C0) >> 6) + 1) << 16) + ((static_cast<unsigned long>(wc1) & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode) |
|
| 152 |
+ return codecvt_base::error; |
|
| 153 |
+ ++frm_nxt; |
|
| 154 |
+ uint8_t z = ((wc1 & 0x03C0) >> 6) + 1; |
|
| 155 |
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2)); |
|
| 156 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2)); |
|
| 157 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6)); |
|
| 158 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F)); |
|
| 159 |
+ } |
|
| 160 |
+ else if (wc1 < 0xE000) |
|
| 161 |
+ return codecvt_base::error; |
|
| 162 |
+ else |
|
| 163 |
+ {
|
|
| 164 |
+ if (to_end - to_nxt < 3) |
|
| 165 |
+ return codecvt_base::partial; |
|
| 166 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12)); |
|
| 167 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6)); |
|
| 168 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F)); |
|
| 169 |
+ } |
|
| 170 |
+ } |
|
| 171 |
+ return codecvt_base::ok; |
|
| 172 |
+ } |
|
| 173 |
+ |
|
| 174 |
+ inline codecvt_base::result utf8_to_utf16(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 175 |
+ {
|
|
| 176 |
+ frm_nxt = frm; |
|
| 177 |
+ to_nxt = to; |
|
| 178 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 179 |
+ frm_nxt += 3; |
|
| 180 |
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 181 |
+ {
|
|
| 182 |
+ uint8_t c1 = *frm_nxt; |
|
| 183 |
+ if (c1 > Maxcode) |
|
| 184 |
+ return codecvt_base::error; |
|
| 185 |
+ if (c1 < 0x80) |
|
| 186 |
+ {
|
|
| 187 |
+ *to_nxt = static_cast<uint16_t>(c1); |
|
| 188 |
+ ++frm_nxt; |
|
| 189 |
+ } |
|
| 190 |
+ else if (c1 < 0xC2) |
|
| 191 |
+ return codecvt_base::error; |
|
| 192 |
+ else if (c1 < 0xE0) |
|
| 193 |
+ {
|
|
| 194 |
+ if (frm_end - frm_nxt < 2) |
|
| 195 |
+ return codecvt_base::partial; |
|
| 196 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 197 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 198 |
+ return codecvt_base::error; |
|
| 199 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 200 |
+ if (t > Maxcode) |
|
| 201 |
+ return codecvt_base::error; |
|
| 202 |
+ *to_nxt = t; |
|
| 203 |
+ frm_nxt += 2; |
|
| 204 |
+ } |
|
| 205 |
+ else if (c1 < 0xF0) |
|
| 206 |
+ {
|
|
| 207 |
+ if (frm_end - frm_nxt < 3) |
|
| 208 |
+ return codecvt_base::partial; |
|
| 209 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 210 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 211 |
+ switch (c1) |
|
| 212 |
+ {
|
|
| 213 |
+ case 0xE0: |
|
| 214 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 215 |
+ return codecvt_base::error; |
|
| 216 |
+ break; |
|
| 217 |
+ case 0xED: |
|
| 218 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 219 |
+ return codecvt_base::error; |
|
| 220 |
+ break; |
|
| 221 |
+ default: |
|
| 222 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 223 |
+ return codecvt_base::error; |
|
| 224 |
+ } |
|
| 225 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 226 |
+ return codecvt_base::error; |
|
| 227 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 228 |
+ if (t > Maxcode) |
|
| 229 |
+ return codecvt_base::error; |
|
| 230 |
+ *to_nxt = t; |
|
| 231 |
+ frm_nxt += 3; |
|
| 232 |
+ } |
|
| 233 |
+ else if (c1 < 0xF5) |
|
| 234 |
+ {
|
|
| 235 |
+ if (frm_end - frm_nxt < 4) |
|
| 236 |
+ return codecvt_base::partial; |
|
| 237 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 238 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 239 |
+ uint8_t c4 = frm_nxt[3]; |
|
| 240 |
+ switch (c1) |
|
| 241 |
+ {
|
|
| 242 |
+ case 0xF0: |
|
| 243 |
+ if (c2 < 0x90 || c2 > 0xBF) |
|
| 244 |
+ return codecvt_base::error; |
|
| 245 |
+ break; |
|
| 246 |
+ case 0xF4: |
|
| 247 |
+ if ((c2 & 0xF0) != 0x80) |
|
| 248 |
+ return codecvt_base::error; |
|
| 249 |
+ break; |
|
| 250 |
+ default: |
|
| 251 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 252 |
+ return codecvt_base::error; |
|
| 253 |
+ } |
|
| 254 |
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 255 |
+ return codecvt_base::error; |
|
| 256 |
+ if (to_end - to_nxt < 2) |
|
| 257 |
+ return codecvt_base::partial; |
|
| 258 |
+ if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 259 |
+ return codecvt_base::error; |
|
| 260 |
+ *to_nxt = static_cast<uint16_t>(0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4)); |
|
| 261 |
+ *++to_nxt = static_cast<uint16_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F)); |
|
| 262 |
+ frm_nxt += 4; |
|
| 263 |
+ } |
|
| 264 |
+ else |
|
| 265 |
+ return codecvt_base::error; |
|
| 266 |
+ } |
|
| 267 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 268 |
+ } |
|
| 269 |
+ |
|
| 270 |
+ inline codecvt_base::result utf8_to_utf16(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 271 |
+ {
|
|
| 272 |
+ frm_nxt = frm; |
|
| 273 |
+ to_nxt = to; |
|
| 274 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 275 |
+ frm_nxt += 3; |
|
| 276 |
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 277 |
+ {
|
|
| 278 |
+ uint8_t c1 = *frm_nxt; |
|
| 279 |
+ if (c1 > Maxcode) |
|
| 280 |
+ return codecvt_base::error; |
|
| 281 |
+ if (c1 < 0x80) |
|
| 282 |
+ {
|
|
| 283 |
+ *to_nxt = static_cast<uint32_t>(c1); |
|
| 284 |
+ ++frm_nxt; |
|
| 285 |
+ } |
|
| 286 |
+ else if (c1 < 0xC2) |
|
| 287 |
+ return codecvt_base::error; |
|
| 288 |
+ else if (c1 < 0xE0) |
|
| 289 |
+ {
|
|
| 290 |
+ if (frm_end - frm_nxt < 2) |
|
| 291 |
+ return codecvt_base::partial; |
|
| 292 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 293 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 294 |
+ return codecvt_base::error; |
|
| 295 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 296 |
+ if (t > Maxcode) |
|
| 297 |
+ return codecvt_base::error; |
|
| 298 |
+ *to_nxt = static_cast<uint32_t>(t); |
|
| 299 |
+ frm_nxt += 2; |
|
| 300 |
+ } |
|
| 301 |
+ else if (c1 < 0xF0) |
|
| 302 |
+ {
|
|
| 303 |
+ if (frm_end - frm_nxt < 3) |
|
| 304 |
+ return codecvt_base::partial; |
|
| 305 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 306 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 307 |
+ switch (c1) |
|
| 308 |
+ {
|
|
| 309 |
+ case 0xE0: |
|
| 310 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 311 |
+ return codecvt_base::error; |
|
| 312 |
+ break; |
|
| 313 |
+ case 0xED: |
|
| 314 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 315 |
+ return codecvt_base::error; |
|
| 316 |
+ break; |
|
| 317 |
+ default: |
|
| 318 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 319 |
+ return codecvt_base::error; |
|
| 320 |
+ } |
|
| 321 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 322 |
+ return codecvt_base::error; |
|
| 323 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 324 |
+ if (t > Maxcode) |
|
| 325 |
+ return codecvt_base::error; |
|
| 326 |
+ *to_nxt = static_cast<uint32_t>(t); |
|
| 327 |
+ frm_nxt += 3; |
|
| 328 |
+ } |
|
| 329 |
+ else if (c1 < 0xF5) |
|
| 330 |
+ {
|
|
| 331 |
+ if (frm_end - frm_nxt < 4) |
|
| 332 |
+ return codecvt_base::partial; |
|
| 333 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 334 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 335 |
+ uint8_t c4 = frm_nxt[3]; |
|
| 336 |
+ switch (c1) |
|
| 337 |
+ {
|
|
| 338 |
+ case 0xF0: |
|
| 339 |
+ if (c2 < 0x90 || c2 > 0xBF) |
|
| 340 |
+ return codecvt_base::error; |
|
| 341 |
+ break; |
|
| 342 |
+ case 0xF4: |
|
| 343 |
+ if ((c2 & 0xF0) != 0x80) |
|
| 344 |
+ return codecvt_base::error; |
|
| 345 |
+ break; |
|
| 346 |
+ default: |
|
| 347 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 348 |
+ return codecvt_base::error; |
|
| 349 |
+ } |
|
| 350 |
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 351 |
+ return codecvt_base::error; |
|
| 352 |
+ if (to_end - to_nxt < 2) |
|
| 353 |
+ return codecvt_base::partial; |
|
| 354 |
+ if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 355 |
+ return codecvt_base::error; |
|
| 356 |
+ *to_nxt = static_cast<uint32_t>(0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4)); |
|
| 357 |
+ *++to_nxt = static_cast<uint32_t>( 0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F)); |
|
| 358 |
+ frm_nxt += 4; |
|
| 359 |
+ } |
|
| 360 |
+ else |
|
| 361 |
+ return codecvt_base::error; |
|
| 362 |
+ } |
|
| 363 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 364 |
+ } |
|
| 365 |
+ |
|
| 366 |
+ inline int utf8_to_utf16_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 367 |
+ {
|
|
| 368 |
+ auto frm_nxt = frm; |
|
| 369 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 370 |
+ frm_nxt += 3; |
|
| 371 |
+ for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t) |
|
| 372 |
+ {
|
|
| 373 |
+ uint8_t c1 = *frm_nxt; |
|
| 374 |
+ if (c1 > Maxcode) |
|
| 375 |
+ break; |
|
| 376 |
+ if (c1 < 0x80) |
|
| 377 |
+ ++frm_nxt; |
|
| 378 |
+ else if (c1 < 0xC2) |
|
| 379 |
+ break; |
|
| 380 |
+ else if (c1 < 0xE0) |
|
| 381 |
+ {
|
|
| 382 |
+ if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 383 |
+ break; |
|
| 384 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)); |
|
| 385 |
+ if (t > Maxcode) |
|
| 386 |
+ break; |
|
| 387 |
+ frm_nxt += 2; |
|
| 388 |
+ } |
|
| 389 |
+ else if (c1 < 0xF0) |
|
| 390 |
+ {
|
|
| 391 |
+ if (frm_end - frm_nxt < 3) |
|
| 392 |
+ break; |
|
| 393 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 394 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 395 |
+ switch (c1) |
|
| 396 |
+ {
|
|
| 397 |
+ case 0xE0: |
|
| 398 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 399 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 400 |
+ break; |
|
| 401 |
+ case 0xED: |
|
| 402 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 403 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 404 |
+ break; |
|
| 405 |
+ default: |
|
| 406 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 407 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 408 |
+ } |
|
| 409 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 410 |
+ break; |
|
| 411 |
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 412 |
+ break; |
|
| 413 |
+ frm_nxt += 3; |
|
| 414 |
+ } |
|
| 415 |
+ else if (c1 < 0xF5) |
|
| 416 |
+ {
|
|
| 417 |
+ if (frm_end - frm_nxt < 4 || mx - nchar16_t < 2) |
|
| 418 |
+ break; |
|
| 419 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 420 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 421 |
+ uint8_t c4 = frm_nxt[3]; |
|
| 422 |
+ switch (c1) |
|
| 423 |
+ {
|
|
| 424 |
+ case 0xF0: |
|
| 425 |
+ if (c2 < 0x90 || c2 > 0xBF) |
|
| 426 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 427 |
+ break; |
|
| 428 |
+ case 0xF4: |
|
| 429 |
+ if ((c2 & 0xF0) != 0x80) |
|
| 430 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 431 |
+ break; |
|
| 432 |
+ default: |
|
| 433 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 434 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 435 |
+ } |
|
| 436 |
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 437 |
+ break; |
|
| 438 |
+ if ((((static_cast<unsigned long>(c1) & 7) << 18) + ((static_cast<unsigned long>(c2) & 0x3F) << 12) + ((static_cast<unsigned long>(c3) & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode) |
|
| 439 |
+ break; |
|
| 440 |
+ ++nchar16_t; |
|
| 441 |
+ frm_nxt += 4; |
|
| 442 |
+ } |
|
| 443 |
+ else |
|
| 444 |
+ break; |
|
| 445 |
+ } |
|
| 446 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 447 |
+ } |
|
| 448 |
+ |
|
| 449 |
+ inline codecvt_base::result ucs4_to_utf8(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 450 |
+ {
|
|
| 451 |
+ frm_nxt = frm; |
|
| 452 |
+ to_nxt = to; |
|
| 453 |
+ if (mode & generate_header) |
|
| 454 |
+ {
|
|
| 455 |
+ if (to_end - to_nxt < 3) |
|
| 456 |
+ return codecvt_base::partial; |
|
| 457 |
+ *to_nxt++ = 0xEF; |
|
| 458 |
+ *to_nxt++ = 0xBB; |
|
| 459 |
+ *to_nxt++ = 0xBF; |
|
| 460 |
+ } |
|
| 461 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 462 |
+ {
|
|
| 463 |
+ uint32_t wc = *frm_nxt; |
|
| 464 |
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 465 |
+ return codecvt_base::error; |
|
| 466 |
+ if (wc < 0x000080) |
|
| 467 |
+ {
|
|
| 468 |
+ if (to_end - to_nxt < 1) |
|
| 469 |
+ return codecvt_base::partial; |
|
| 470 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 471 |
+ } |
|
| 472 |
+ else if (wc < 0x000800) |
|
| 473 |
+ {
|
|
| 474 |
+ if (to_end - to_nxt < 2) |
|
| 475 |
+ return codecvt_base::partial; |
|
| 476 |
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6)); |
|
| 477 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F)); |
|
| 478 |
+ } |
|
| 479 |
+ else if (wc < 0x010000) |
|
| 480 |
+ {
|
|
| 481 |
+ if (to_end - to_nxt < 3) |
|
| 482 |
+ return codecvt_base::partial; |
|
| 483 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12)); |
|
| 484 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6)); |
|
| 485 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F)); |
|
| 486 |
+ } |
|
| 487 |
+ else // if (wc < 0x110000) |
|
| 488 |
+ {
|
|
| 489 |
+ if (to_end - to_nxt < 4) |
|
| 490 |
+ return codecvt_base::partial; |
|
| 491 |
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18)); |
|
| 492 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12)); |
|
| 493 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6)); |
|
| 494 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F)); |
|
| 495 |
+ } |
|
| 496 |
+ } |
|
| 497 |
+ return codecvt_base::ok; |
|
| 498 |
+ } |
|
| 499 |
+ |
|
| 500 |
+ inline codecvt_base::result utf8_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 501 |
+ {
|
|
| 502 |
+ frm_nxt = frm; |
|
| 503 |
+ to_nxt = to; |
|
| 504 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 505 |
+ frm_nxt += 3; |
|
| 506 |
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 507 |
+ {
|
|
| 508 |
+ uint8_t c1 = *frm_nxt; |
|
| 509 |
+ if (c1 < 0x80) |
|
| 510 |
+ {
|
|
| 511 |
+ if (c1 > Maxcode) |
|
| 512 |
+ return codecvt_base::error; |
|
| 513 |
+ *to_nxt = static_cast<uint32_t>(c1); |
|
| 514 |
+ ++frm_nxt; |
|
| 515 |
+ } |
|
| 516 |
+ else if (c1 < 0xC2) |
|
| 517 |
+ return codecvt_base::error; |
|
| 518 |
+ else if (c1 < 0xE0) |
|
| 519 |
+ {
|
|
| 520 |
+ if (frm_end - frm_nxt < 2) |
|
| 521 |
+ return codecvt_base::partial; |
|
| 522 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 523 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 524 |
+ return codecvt_base::error; |
|
| 525 |
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 526 |
+ if (t > Maxcode) |
|
| 527 |
+ return codecvt_base::error; |
|
| 528 |
+ *to_nxt = t; |
|
| 529 |
+ frm_nxt += 2; |
|
| 530 |
+ } |
|
| 531 |
+ else if (c1 < 0xF0) |
|
| 532 |
+ {
|
|
| 533 |
+ if (frm_end - frm_nxt < 3) |
|
| 534 |
+ return codecvt_base::partial; |
|
| 535 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 536 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 537 |
+ switch (c1) |
|
| 538 |
+ {
|
|
| 539 |
+ case 0xE0: |
|
| 540 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 541 |
+ return codecvt_base::error; |
|
| 542 |
+ break; |
|
| 543 |
+ case 0xED: |
|
| 544 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 545 |
+ return codecvt_base::error; |
|
| 546 |
+ break; |
|
| 547 |
+ default: |
|
| 548 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 549 |
+ return codecvt_base::error; |
|
| 550 |
+ } |
|
| 551 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 552 |
+ return codecvt_base::error; |
|
| 553 |
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 554 |
+ if (t > Maxcode) |
|
| 555 |
+ return codecvt_base::error; |
|
| 556 |
+ *to_nxt = t; |
|
| 557 |
+ frm_nxt += 3; |
|
| 558 |
+ } |
|
| 559 |
+ else if (c1 < 0xF5) |
|
| 560 |
+ {
|
|
| 561 |
+ if (frm_end - frm_nxt < 4) |
|
| 562 |
+ return codecvt_base::partial; |
|
| 563 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 564 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 565 |
+ uint8_t c4 = frm_nxt[3]; |
|
| 566 |
+ switch (c1) |
|
| 567 |
+ {
|
|
| 568 |
+ case 0xF0: |
|
| 569 |
+ if (c2 < 0x90 || c2 > 0xBF) |
|
| 570 |
+ return codecvt_base::error; |
|
| 571 |
+ break; |
|
| 572 |
+ case 0xF4: |
|
| 573 |
+ if ((c2 & 0xF0) != 0x80) |
|
| 574 |
+ return codecvt_base::error; |
|
| 575 |
+ break; |
|
| 576 |
+ default: |
|
| 577 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 578 |
+ return codecvt_base::error; |
|
| 579 |
+ } |
|
| 580 |
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 581 |
+ return codecvt_base::error; |
|
| 582 |
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); |
|
| 583 |
+ if (t > Maxcode) |
|
| 584 |
+ return codecvt_base::error; |
|
| 585 |
+ *to_nxt = t; |
|
| 586 |
+ frm_nxt += 4; |
|
| 587 |
+ } |
|
| 588 |
+ else |
|
| 589 |
+ return codecvt_base::error; |
|
| 590 |
+ } |
|
| 591 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 592 |
+ } |
|
| 593 |
+ |
|
| 594 |
+ inline int utf8_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 595 |
+ {
|
|
| 596 |
+ auto frm_nxt = frm; |
|
| 597 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 598 |
+ frm_nxt += 3; |
|
| 599 |
+ for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) |
|
| 600 |
+ {
|
|
| 601 |
+ uint8_t c1 = *frm_nxt; |
|
| 602 |
+ if (c1 < 0x80) |
|
| 603 |
+ {
|
|
| 604 |
+ if (c1 > Maxcode) |
|
| 605 |
+ break; |
|
| 606 |
+ ++frm_nxt; |
|
| 607 |
+ } |
|
| 608 |
+ else if (c1 < 0xC2) |
|
| 609 |
+ break; |
|
| 610 |
+ else if (c1 < 0xE0) |
|
| 611 |
+ {
|
|
| 612 |
+ if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 613 |
+ break; |
|
| 614 |
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode) |
|
| 615 |
+ break; |
|
| 616 |
+ frm_nxt += 2; |
|
| 617 |
+ } |
|
| 618 |
+ else if (c1 < 0xF0) |
|
| 619 |
+ {
|
|
| 620 |
+ if (frm_end - frm_nxt < 3) |
|
| 621 |
+ break; |
|
| 622 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 623 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 624 |
+ switch (c1) |
|
| 625 |
+ {
|
|
| 626 |
+ case 0xE0: |
|
| 627 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 628 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 629 |
+ break; |
|
| 630 |
+ case 0xED: |
|
| 631 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 632 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 633 |
+ break; |
|
| 634 |
+ default: |
|
| 635 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 636 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 637 |
+ } |
|
| 638 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 639 |
+ break; |
|
| 640 |
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 641 |
+ break; |
|
| 642 |
+ frm_nxt += 3; |
|
| 643 |
+ } |
|
| 644 |
+ else if (c1 < 0xF5) |
|
| 645 |
+ {
|
|
| 646 |
+ if (frm_end - frm_nxt < 4) |
|
| 647 |
+ break; |
|
| 648 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 649 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 650 |
+ uint8_t c4 = frm_nxt[3]; |
|
| 651 |
+ switch (c1) |
|
| 652 |
+ {
|
|
| 653 |
+ case 0xF0: |
|
| 654 |
+ if (c2 < 0x90 || c2 > 0xBF) |
|
| 655 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 656 |
+ break; |
|
| 657 |
+ case 0xF4: |
|
| 658 |
+ if ((c2 & 0xF0) != 0x80) |
|
| 659 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 660 |
+ break; |
|
| 661 |
+ default: |
|
| 662 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 663 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 664 |
+ } |
|
| 665 |
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80) |
|
| 666 |
+ break; |
|
| 667 |
+ if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) | ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode) |
|
| 668 |
+ break; |
|
| 669 |
+ frm_nxt += 4; |
|
| 670 |
+ } |
|
| 671 |
+ else |
|
| 672 |
+ break; |
|
| 673 |
+ } |
|
| 674 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 675 |
+ } |
|
| 676 |
+ |
|
| 677 |
+ inline codecvt_base::result ucs2_to_utf8(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 678 |
+ {
|
|
| 679 |
+ frm_nxt = frm; |
|
| 680 |
+ to_nxt = to; |
|
| 681 |
+ if (mode & generate_header) |
|
| 682 |
+ {
|
|
| 683 |
+ if (to_end - to_nxt < 3) |
|
| 684 |
+ return codecvt_base::partial; |
|
| 685 |
+ *to_nxt++ = 0xEF; |
|
| 686 |
+ *to_nxt++ = 0xBB; |
|
| 687 |
+ *to_nxt++ = 0xBF; |
|
| 688 |
+ } |
|
| 689 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 690 |
+ {
|
|
| 691 |
+ uint16_t wc = *frm_nxt; |
|
| 692 |
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 693 |
+ return codecvt_base::error; |
|
| 694 |
+ if (wc < 0x0080) |
|
| 695 |
+ {
|
|
| 696 |
+ if (to_end - to_nxt < 1) |
|
| 697 |
+ return codecvt_base::partial; |
|
| 698 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 699 |
+ } |
|
| 700 |
+ else if (wc < 0x0800) |
|
| 701 |
+ {
|
|
| 702 |
+ if (to_end - to_nxt < 2) |
|
| 703 |
+ return codecvt_base::partial; |
|
| 704 |
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6)); |
|
| 705 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F)); |
|
| 706 |
+ } |
|
| 707 |
+ else // if (wc <= 0xFFFF) |
|
| 708 |
+ {
|
|
| 709 |
+ if (to_end - to_nxt < 3) |
|
| 710 |
+ return codecvt_base::partial; |
|
| 711 |
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12)); |
|
| 712 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6)); |
|
| 713 |
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F)); |
|
| 714 |
+ } |
|
| 715 |
+ } |
|
| 716 |
+ return codecvt_base::ok; |
|
| 717 |
+ } |
|
| 718 |
+ |
|
| 719 |
+ inline codecvt_base::result utf8_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 720 |
+ {
|
|
| 721 |
+ frm_nxt = frm; |
|
| 722 |
+ to_nxt = to; |
|
| 723 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 724 |
+ frm_nxt += 3; |
|
| 725 |
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) |
|
| 726 |
+ {
|
|
| 727 |
+ uint8_t c1 = *frm_nxt; |
|
| 728 |
+ if (c1 < 0x80) |
|
| 729 |
+ {
|
|
| 730 |
+ if (c1 > Maxcode) |
|
| 731 |
+ return codecvt_base::error; |
|
| 732 |
+ *to_nxt = static_cast<uint16_t>(c1); |
|
| 733 |
+ ++frm_nxt; |
|
| 734 |
+ } |
|
| 735 |
+ else if (c1 < 0xC2) |
|
| 736 |
+ return codecvt_base::error; |
|
| 737 |
+ else if (c1 < 0xE0) |
|
| 738 |
+ {
|
|
| 739 |
+ if (frm_end - frm_nxt < 2) |
|
| 740 |
+ return codecvt_base::partial; |
|
| 741 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 742 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 743 |
+ return codecvt_base::error; |
|
| 744 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F)); |
|
| 745 |
+ if (t > Maxcode) |
|
| 746 |
+ return codecvt_base::error; |
|
| 747 |
+ *to_nxt = t; |
|
| 748 |
+ frm_nxt += 2; |
|
| 749 |
+ } |
|
| 750 |
+ else if (c1 < 0xF0) |
|
| 751 |
+ {
|
|
| 752 |
+ if (frm_end - frm_nxt < 3) |
|
| 753 |
+ return codecvt_base::partial; |
|
| 754 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 755 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 756 |
+ switch (c1) |
|
| 757 |
+ {
|
|
| 758 |
+ case 0xE0: |
|
| 759 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 760 |
+ return codecvt_base::error; |
|
| 761 |
+ break; |
|
| 762 |
+ case 0xED: |
|
| 763 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 764 |
+ return codecvt_base::error; |
|
| 765 |
+ break; |
|
| 766 |
+ default: |
|
| 767 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 768 |
+ return codecvt_base::error; |
|
| 769 |
+ } |
|
| 770 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 771 |
+ return codecvt_base::error; |
|
| 772 |
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
| 773 |
+ if (t > Maxcode) |
|
| 774 |
+ return codecvt_base::error; |
|
| 775 |
+ *to_nxt = t; |
|
| 776 |
+ frm_nxt += 3; |
|
| 777 |
+ } |
|
| 778 |
+ else |
|
| 779 |
+ return codecvt_base::error; |
|
| 780 |
+ } |
|
| 781 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 782 |
+ } |
|
| 783 |
+ |
|
| 784 |
+ inline int utf8_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 785 |
+ {
|
|
| 786 |
+ auto frm_nxt = frm; |
|
| 787 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF) |
|
| 788 |
+ frm_nxt += 3; |
|
| 789 |
+ for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) |
|
| 790 |
+ {
|
|
| 791 |
+ uint8_t c1 = *frm_nxt; |
|
| 792 |
+ if (c1 < 0x80) |
|
| 793 |
+ {
|
|
| 794 |
+ if (c1 > Maxcode) |
|
| 795 |
+ break; |
|
| 796 |
+ ++frm_nxt; |
|
| 797 |
+ } |
|
| 798 |
+ else if (c1 < 0xC2) |
|
| 799 |
+ break; |
|
| 800 |
+ else if (c1 < 0xE0) |
|
| 801 |
+ {
|
|
| 802 |
+ if (frm_end - frm_nxt < 2 || (frm_nxt[1] & 0xC0) != 0x80) |
|
| 803 |
+ break; |
|
| 804 |
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode) |
|
| 805 |
+ break; |
|
| 806 |
+ frm_nxt += 2; |
|
| 807 |
+ } |
|
| 808 |
+ else if (c1 < 0xF0) |
|
| 809 |
+ {
|
|
| 810 |
+ if (frm_end - frm_nxt < 3) |
|
| 811 |
+ break; |
|
| 812 |
+ uint8_t c2 = frm_nxt[1]; |
|
| 813 |
+ uint8_t c3 = frm_nxt[2]; |
|
| 814 |
+ switch (c1) |
|
| 815 |
+ {
|
|
| 816 |
+ case 0xE0: |
|
| 817 |
+ if ((c2 & 0xE0) != 0xA0) |
|
| 818 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 819 |
+ break; |
|
| 820 |
+ case 0xED: |
|
| 821 |
+ if ((c2 & 0xE0) != 0x80) |
|
| 822 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 823 |
+ break; |
|
| 824 |
+ default: |
|
| 825 |
+ if ((c2 & 0xC0) != 0x80) |
|
| 826 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 827 |
+ } |
|
| 828 |
+ if ((c3 & 0xC0) != 0x80) |
|
| 829 |
+ break; |
|
| 830 |
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode) |
|
| 831 |
+ break; |
|
| 832 |
+ frm_nxt += 3; |
|
| 833 |
+ } |
|
| 834 |
+ else |
|
| 835 |
+ break; |
|
| 836 |
+ } |
|
| 837 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 838 |
+ } |
|
| 839 |
+ |
|
| 840 |
+ inline codecvt_base::result ucs4_to_utf16be(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 841 |
+ {
|
|
| 842 |
+ frm_nxt = frm; |
|
| 843 |
+ to_nxt = to; |
|
| 844 |
+ if (mode & generate_header) |
|
| 845 |
+ {
|
|
| 846 |
+ if (to_end - to_nxt < 2) |
|
| 847 |
+ return codecvt_base::partial; |
|
| 848 |
+ *to_nxt++ = 0xFE; |
|
| 849 |
+ *to_nxt++ = 0xFF; |
|
| 850 |
+ } |
|
| 851 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 852 |
+ {
|
|
| 853 |
+ uint32_t wc = *frm_nxt; |
|
| 854 |
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 855 |
+ return codecvt_base::error; |
|
| 856 |
+ if (wc < 0x010000) |
|
| 857 |
+ {
|
|
| 858 |
+ if (to_end - to_nxt < 2) |
|
| 859 |
+ return codecvt_base::partial; |
|
| 860 |
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 861 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 862 |
+ } |
|
| 863 |
+ else |
|
| 864 |
+ {
|
|
| 865 |
+ if (to_end - to_nxt < 4) |
|
| 866 |
+ return codecvt_base::partial; |
|
| 867 |
+ uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10)); |
|
| 868 |
+ *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 869 |
+ *to_nxt++ = static_cast<uint8_t>(t); |
|
| 870 |
+ t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF)); |
|
| 871 |
+ *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 872 |
+ *to_nxt++ = static_cast<uint8_t>(t); |
|
| 873 |
+ } |
|
| 874 |
+ } |
|
| 875 |
+ return codecvt_base::ok; |
|
| 876 |
+ } |
|
| 877 |
+ |
|
| 878 |
+ inline codecvt_base::result utf16be_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 879 |
+ {
|
|
| 880 |
+ frm_nxt = frm; |
|
| 881 |
+ to_nxt = to; |
|
| 882 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 883 |
+ frm_nxt += 2; |
|
| 884 |
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 885 |
+ {
|
|
| 886 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 887 |
+ if ((c1 & 0xFC00) == 0xDC00) |
|
| 888 |
+ return codecvt_base::error; |
|
| 889 |
+ if ((c1 & 0xFC00) != 0xD800) |
|
| 890 |
+ {
|
|
| 891 |
+ if (c1 > Maxcode) |
|
| 892 |
+ return codecvt_base::error; |
|
| 893 |
+ *to_nxt = static_cast<uint32_t>(c1); |
|
| 894 |
+ frm_nxt += 2; |
|
| 895 |
+ } |
|
| 896 |
+ else |
|
| 897 |
+ {
|
|
| 898 |
+ if (frm_end - frm_nxt < 4) |
|
| 899 |
+ return codecvt_base::partial; |
|
| 900 |
+ uint16_t c2 = static_cast<uint16_t>((frm_nxt[2] << 8) | frm_nxt[3]); |
|
| 901 |
+ if ((c2 & 0xFC00) != 0xDC00) |
|
| 902 |
+ return codecvt_base::error; |
|
| 903 |
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 904 |
+ if (t > Maxcode) |
|
| 905 |
+ return codecvt_base::error; |
|
| 906 |
+ *to_nxt = t; |
|
| 907 |
+ frm_nxt += 4; |
|
| 908 |
+ } |
|
| 909 |
+ } |
|
| 910 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 911 |
+ } |
|
| 912 |
+ |
|
| 913 |
+ inline int utf16be_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 914 |
+ {
|
|
| 915 |
+ auto frm_nxt = frm; |
|
| 916 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 917 |
+ frm_nxt += 2; |
|
| 918 |
+ for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) |
|
| 919 |
+ {
|
|
| 920 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 921 |
+ if ((c1 & 0xFC00) == 0xDC00) |
|
| 922 |
+ break; |
|
| 923 |
+ if ((c1 & 0xFC00) != 0xD800) |
|
| 924 |
+ {
|
|
| 925 |
+ if (c1 > Maxcode) |
|
| 926 |
+ break; |
|
| 927 |
+ frm_nxt += 2; |
|
| 928 |
+ } |
|
| 929 |
+ else |
|
| 930 |
+ {
|
|
| 931 |
+ if (frm_end - frm_nxt < 4) |
|
| 932 |
+ break; |
|
| 933 |
+ uint16_t c2 = static_cast<uint16_t>((frm_nxt[2] << 8) | frm_nxt[3]); |
|
| 934 |
+ if ((c2 & 0xFC00) != 0xDC00) |
|
| 935 |
+ break; |
|
| 936 |
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 937 |
+ if (t > Maxcode) |
|
| 938 |
+ break; |
|
| 939 |
+ frm_nxt += 4; |
|
| 940 |
+ } |
|
| 941 |
+ } |
|
| 942 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 943 |
+ } |
|
| 944 |
+ |
|
| 945 |
+ inline codecvt_base::result ucs4_to_utf16le(const uint32_t *frm, const uint32_t *frm_end, const uint32_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 946 |
+ {
|
|
| 947 |
+ frm_nxt = frm; |
|
| 948 |
+ to_nxt = to; |
|
| 949 |
+ if (mode & generate_header) |
|
| 950 |
+ {
|
|
| 951 |
+ if (to_end - to_nxt < 2) |
|
| 952 |
+ return codecvt_base::partial; |
|
| 953 |
+ *to_nxt++ = 0xFF; |
|
| 954 |
+ *to_nxt++ = 0xFE; |
|
| 955 |
+ } |
|
| 956 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 957 |
+ {
|
|
| 958 |
+ uint32_t wc = *frm_nxt; |
|
| 959 |
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode) |
|
| 960 |
+ return codecvt_base::error; |
|
| 961 |
+ if (wc < 0x010000) |
|
| 962 |
+ {
|
|
| 963 |
+ if (to_end - to_nxt < 2) |
|
| 964 |
+ return codecvt_base::partial; |
|
| 965 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 966 |
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 967 |
+ } |
|
| 968 |
+ else |
|
| 969 |
+ {
|
|
| 970 |
+ if (to_end - to_nxt < 4) |
|
| 971 |
+ return codecvt_base::partial; |
|
| 972 |
+ uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10)); |
|
| 973 |
+ *to_nxt++ = static_cast<uint8_t>(t); |
|
| 974 |
+ *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 975 |
+ t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF)); |
|
| 976 |
+ *to_nxt++ = static_cast<uint8_t>(t); |
|
| 977 |
+ *to_nxt++ = static_cast<uint8_t>(t >> 8); |
|
| 978 |
+ } |
|
| 979 |
+ } |
|
| 980 |
+ return codecvt_base::ok; |
|
| 981 |
+ } |
|
| 982 |
+ |
|
| 983 |
+ inline codecvt_base::result utf16le_to_ucs4(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint32_t *to, uint32_t *to_end, uint32_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 984 |
+ {
|
|
| 985 |
+ frm_nxt = frm; |
|
| 986 |
+ to_nxt = to; |
|
| 987 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 988 |
+ frm_nxt += 2; |
|
| 989 |
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 990 |
+ {
|
|
| 991 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 992 |
+ if ((c1 & 0xFC00) == 0xDC00) |
|
| 993 |
+ return codecvt_base::error; |
|
| 994 |
+ if ((c1 & 0xFC00) != 0xD800) |
|
| 995 |
+ {
|
|
| 996 |
+ if (c1 > Maxcode) |
|
| 997 |
+ return codecvt_base::error; |
|
| 998 |
+ *to_nxt = static_cast<uint32_t>(c1); |
|
| 999 |
+ frm_nxt += 2; |
|
| 1000 |
+ } |
|
| 1001 |
+ else |
|
| 1002 |
+ {
|
|
| 1003 |
+ if (frm_end - frm_nxt < 4) |
|
| 1004 |
+ return codecvt_base::partial; |
|
| 1005 |
+ uint16_t c2 = static_cast<uint16_t>((frm_nxt[3] << 8) | frm_nxt[2]); |
|
| 1006 |
+ if ((c2 & 0xFC00) != 0xDC00) |
|
| 1007 |
+ return codecvt_base::error; |
|
| 1008 |
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 1009 |
+ if (t > Maxcode) |
|
| 1010 |
+ return codecvt_base::error; |
|
| 1011 |
+ *to_nxt = t; |
|
| 1012 |
+ frm_nxt += 4; |
|
| 1013 |
+ } |
|
| 1014 |
+ } |
|
| 1015 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1016 |
+ } |
|
| 1017 |
+ |
|
| 1018 |
+ inline int utf16le_to_ucs4_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1019 |
+ {
|
|
| 1020 |
+ auto frm_nxt = frm; |
|
| 1021 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1022 |
+ frm_nxt += 2; |
|
| 1023 |
+ for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) |
|
| 1024 |
+ {
|
|
| 1025 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1026 |
+ if ((c1 & 0xFC00) == 0xDC00) |
|
| 1027 |
+ break; |
|
| 1028 |
+ if ((c1 & 0xFC00) != 0xD800) |
|
| 1029 |
+ {
|
|
| 1030 |
+ if (c1 > Maxcode) |
|
| 1031 |
+ break; |
|
| 1032 |
+ frm_nxt += 2; |
|
| 1033 |
+ } |
|
| 1034 |
+ else |
|
| 1035 |
+ {
|
|
| 1036 |
+ if (frm_end - frm_nxt < 4) |
|
| 1037 |
+ break; |
|
| 1038 |
+ uint16_t c2 = static_cast<uint16_t>((frm_nxt[3] << 8) | frm_nxt[2]); |
|
| 1039 |
+ if ((c2 & 0xFC00) != 0xDC00) |
|
| 1040 |
+ break; |
|
| 1041 |
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF)); |
|
| 1042 |
+ if (t > Maxcode) |
|
| 1043 |
+ break; |
|
| 1044 |
+ frm_nxt += 4; |
|
| 1045 |
+ } |
|
| 1046 |
+ } |
|
| 1047 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 1048 |
+ } |
|
| 1049 |
+ |
|
| 1050 |
+ inline codecvt_base::result ucs2_to_utf16be(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1051 |
+ {
|
|
| 1052 |
+ frm_nxt = frm; |
|
| 1053 |
+ to_nxt = to; |
|
| 1054 |
+ if (mode & generate_header) |
|
| 1055 |
+ {
|
|
| 1056 |
+ if (to_end - to_nxt < 2) |
|
| 1057 |
+ return codecvt_base::partial; |
|
| 1058 |
+ *to_nxt++ = 0xFE; |
|
| 1059 |
+ *to_nxt++ = 0xFF; |
|
| 1060 |
+ } |
|
| 1061 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 1062 |
+ {
|
|
| 1063 |
+ uint16_t wc = *frm_nxt; |
|
| 1064 |
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 1065 |
+ return codecvt_base::error; |
|
| 1066 |
+ if (to_end - to_nxt < 2) |
|
| 1067 |
+ return codecvt_base::partial; |
|
| 1068 |
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 1069 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 1070 |
+ } |
|
| 1071 |
+ return codecvt_base::ok; |
|
| 1072 |
+ } |
|
| 1073 |
+ |
|
| 1074 |
+ inline codecvt_base::result utf16be_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1075 |
+ {
|
|
| 1076 |
+ frm_nxt = frm; |
|
| 1077 |
+ to_nxt = to; |
|
| 1078 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 1079 |
+ frm_nxt += 2; |
|
| 1080 |
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 1081 |
+ {
|
|
| 1082 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 1083 |
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1084 |
+ return codecvt_base::error; |
|
| 1085 |
+ *to_nxt = c1; |
|
| 1086 |
+ frm_nxt += 2; |
|
| 1087 |
+ } |
|
| 1088 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1089 |
+ } |
|
| 1090 |
+ |
|
| 1091 |
+ inline int utf16be_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1092 |
+ {
|
|
| 1093 |
+ auto frm_nxt = frm; |
|
| 1094 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) |
|
| 1095 |
+ frm_nxt += 2; |
|
| 1096 |
+ for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) |
|
| 1097 |
+ {
|
|
| 1098 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[0] << 8) | frm_nxt[1]); |
|
| 1099 |
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1100 |
+ break; |
|
| 1101 |
+ frm_nxt += 2; |
|
| 1102 |
+ } |
|
| 1103 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 1104 |
+ } |
|
| 1105 |
+ |
|
| 1106 |
+ inline codecvt_base::result ucs2_to_utf16le(const uint16_t *frm, const uint16_t *frm_end, const uint16_t *&frm_nxt, uint8_t *to, uint8_t *to_end, uint8_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1107 |
+ {
|
|
| 1108 |
+ frm_nxt = frm; |
|
| 1109 |
+ to_nxt = to; |
|
| 1110 |
+ if (mode & generate_header) |
|
| 1111 |
+ {
|
|
| 1112 |
+ if (to_end - to_nxt < 2) |
|
| 1113 |
+ return codecvt_base::partial; |
|
| 1114 |
+ *to_nxt++ = 0xFF; |
|
| 1115 |
+ *to_nxt++ = 0xFE; |
|
| 1116 |
+ } |
|
| 1117 |
+ for (; frm_nxt < frm_end; ++frm_nxt) |
|
| 1118 |
+ {
|
|
| 1119 |
+ uint16_t wc = *frm_nxt; |
|
| 1120 |
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode) |
|
| 1121 |
+ return codecvt_base::error; |
|
| 1122 |
+ if (to_end - to_nxt < 2) |
|
| 1123 |
+ return codecvt_base::partial; |
|
| 1124 |
+ *to_nxt++ = static_cast<uint8_t>(wc); |
|
| 1125 |
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8); |
|
| 1126 |
+ } |
|
| 1127 |
+ return codecvt_base::ok; |
|
| 1128 |
+ } |
|
| 1129 |
+ |
|
| 1130 |
+ inline codecvt_base::result utf16le_to_ucs2(const uint8_t *frm, const uint8_t *frm_end, const uint8_t *&frm_nxt, uint16_t *to, uint16_t *to_end, uint16_t *&to_nxt, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1131 |
+ {
|
|
| 1132 |
+ frm_nxt = frm; |
|
| 1133 |
+ to_nxt = to; |
|
| 1134 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1135 |
+ frm_nxt += 2; |
|
| 1136 |
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) |
|
| 1137 |
+ {
|
|
| 1138 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1139 |
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1140 |
+ return codecvt_base::error; |
|
| 1141 |
+ *to_nxt = c1; |
|
| 1142 |
+ frm_nxt += 2; |
|
| 1143 |
+ } |
|
| 1144 |
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok; |
|
| 1145 |
+ } |
|
| 1146 |
+ |
|
| 1147 |
+ inline int utf16le_to_ucs2_length(const uint8_t *frm, const uint8_t *frm_end, size_t mx, unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = static_cast<codecvt_mode>(0)) |
|
| 1148 |
+ {
|
|
| 1149 |
+ auto frm_nxt = frm; |
|
| 1150 |
+ if ((mode & consume_header) && frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) |
|
| 1151 |
+ frm_nxt += 2; |
|
| 1152 |
+ for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) |
|
| 1153 |
+ {
|
|
| 1154 |
+ uint16_t c1 = static_cast<uint16_t>((frm_nxt[1] << 8) | frm_nxt[0]); |
|
| 1155 |
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode) |
|
| 1156 |
+ break; |
|
| 1157 |
+ frm_nxt += 2; |
|
| 1158 |
+ } |
|
| 1159 |
+ return static_cast<int>(frm_nxt - frm); |
|
| 1160 |
+ } |
|
| 1161 |
+} |
|
| 1162 |
+ |
|
| 1163 |
+template<> class codecvt<char16_t, char, mbstate_t> : public locale::facet, public codecvt_base |
|
| 1164 |
+{
|
|
| 1165 |
+public: |
|
| 1166 |
+ typedef char16_t intern_type; |
|
| 1167 |
+ typedef char extern_type; |
|
| 1168 |
+ typedef mbstate_t state_type; |
|
| 1169 |
+ |
|
| 1170 |
+ explicit codecvt(size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1171 |
+ |
|
| 1172 |
+ result out(state_type &__st, const intern_type *__frm, const intern_type *__frm_end, const intern_type *&__frm_nxt, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1173 |
+ {
|
|
| 1174 |
+ return this->do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1175 |
+ } |
|
| 1176 |
+ |
|
| 1177 |
+ result unshift(state_type &__st, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1178 |
+ {
|
|
| 1179 |
+ return this->do_unshift(__st, __to, __to_end, __to_nxt); |
|
| 1180 |
+ } |
|
| 1181 |
+ |
|
| 1182 |
+ result in(state_type &__st, const extern_type *__frm, const extern_type *__frm_end, const extern_type *&__frm_nxt, intern_type *__to, intern_type *__to_end, intern_type *&__to_nxt) const |
|
| 1183 |
+ {
|
|
| 1184 |
+ return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1185 |
+ } |
|
| 1186 |
+ |
|
| 1187 |
+ int encoding() const throw() |
|
| 1188 |
+ {
|
|
| 1189 |
+ return this->do_encoding(); |
|
| 1190 |
+ } |
|
| 1191 |
+ |
|
| 1192 |
+ bool always_noconv() const throw() |
|
| 1193 |
+ {
|
|
| 1194 |
+ return this->do_always_noconv(); |
|
| 1195 |
+ } |
|
| 1196 |
+ |
|
| 1197 |
+ int length(state_type &__st, const extern_type *__frm, const extern_type *__end, size_t __mx) const |
|
| 1198 |
+ {
|
|
| 1199 |
+ return this->do_length(__st, __frm, __end, __mx); |
|
| 1200 |
+ } |
|
| 1201 |
+ |
|
| 1202 |
+ int max_length() const throw() |
|
| 1203 |
+ {
|
|
| 1204 |
+ return this->do_max_length(); |
|
| 1205 |
+ } |
|
| 1206 |
+ |
|
| 1207 |
+ static locale::id id; |
|
| 1208 |
+ |
|
| 1209 |
+protected: |
|
| 1210 |
+ explicit codecvt(const char *, size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1211 |
+ |
|
| 1212 |
+ ~codecvt() { }
|
|
| 1213 |
+ |
|
| 1214 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1215 |
+ {
|
|
| 1216 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1217 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1218 |
+ auto _frm_nxt = _frm; |
|
| 1219 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1220 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1221 |
+ auto _to_nxt = _to; |
|
| 1222 |
+ auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1223 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1224 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1225 |
+ return r; |
|
| 1226 |
+ } |
|
| 1227 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1228 |
+ {
|
|
| 1229 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1230 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1231 |
+ auto _frm_nxt = _frm; |
|
| 1232 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1233 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1234 |
+ auto _to_nxt = _to; |
|
| 1235 |
+ auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1236 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1237 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1238 |
+ return r; |
|
| 1239 |
+ } |
|
| 1240 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1241 |
+ {
|
|
| 1242 |
+ to_nxt = to; |
|
| 1243 |
+ return noconv; |
|
| 1244 |
+ } |
|
| 1245 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1246 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1247 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1248 |
+ {
|
|
| 1249 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1250 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1251 |
+ return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx); |
|
| 1252 |
+ } |
|
| 1253 |
+ virtual int do_max_length() const throw() { return 4; }
|
|
| 1254 |
+}; |
|
| 1255 |
+ |
|
| 1256 |
+template<> class codecvt<char32_t, char, mbstate_t> : public locale::facet, public codecvt_base |
|
| 1257 |
+{
|
|
| 1258 |
+public: |
|
| 1259 |
+ typedef char32_t intern_type; |
|
| 1260 |
+ typedef char extern_type; |
|
| 1261 |
+ typedef mbstate_t state_type; |
|
| 1262 |
+ |
|
| 1263 |
+ explicit codecvt(size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1264 |
+ |
|
| 1265 |
+ result out(state_type &__st, const intern_type *__frm, const intern_type *__frm_end, const intern_type *&__frm_nxt, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1266 |
+ {
|
|
| 1267 |
+ return this->do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1268 |
+ } |
|
| 1269 |
+ |
|
| 1270 |
+ result unshift(state_type &__st, extern_type *__to, extern_type *__to_end, extern_type *&__to_nxt) const |
|
| 1271 |
+ {
|
|
| 1272 |
+ return this->do_unshift(__st, __to, __to_end, __to_nxt); |
|
| 1273 |
+ } |
|
| 1274 |
+ |
|
| 1275 |
+ result in(state_type &__st, const extern_type *__frm, const extern_type *__frm_end, const extern_type *&__frm_nxt, intern_type *__to, intern_type *__to_end, intern_type *&__to_nxt) const |
|
| 1276 |
+ {
|
|
| 1277 |
+ return this->do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
|
| 1278 |
+ } |
|
| 1279 |
+ |
|
| 1280 |
+ int encoding() const throw() |
|
| 1281 |
+ {
|
|
| 1282 |
+ return this->do_encoding(); |
|
| 1283 |
+ } |
|
| 1284 |
+ |
|
| 1285 |
+ bool always_noconv() const throw() |
|
| 1286 |
+ {
|
|
| 1287 |
+ return this->do_always_noconv(); |
|
| 1288 |
+ } |
|
| 1289 |
+ |
|
| 1290 |
+ int length(state_type &__st, const extern_type *__frm, const extern_type *__end, size_t __mx) const |
|
| 1291 |
+ {
|
|
| 1292 |
+ return this->do_length(__st, __frm, __end, __mx); |
|
| 1293 |
+ } |
|
| 1294 |
+ |
|
| 1295 |
+ int max_length() const throw() |
|
| 1296 |
+ {
|
|
| 1297 |
+ return this->do_max_length(); |
|
| 1298 |
+ } |
|
| 1299 |
+ |
|
| 1300 |
+ static locale::id id; |
|
| 1301 |
+ |
|
| 1302 |
+protected: |
|
| 1303 |
+ explicit codecvt(const char *, size_t __refs = 0) : locale::facet(__refs) { }
|
|
| 1304 |
+ |
|
| 1305 |
+ ~codecvt() { }
|
|
| 1306 |
+ |
|
| 1307 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1308 |
+ {
|
|
| 1309 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1310 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1311 |
+ auto _frm_nxt = _frm; |
|
| 1312 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1313 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1314 |
+ auto _to_nxt = _to; |
|
| 1315 |
+ auto r = UnicodeConverters::ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1316 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1317 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1318 |
+ return r; |
|
| 1319 |
+ } |
|
| 1320 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1321 |
+ {
|
|
| 1322 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1323 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1324 |
+ auto _frm_nxt = _frm; |
|
| 1325 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1326 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1327 |
+ auto _to_nxt = _to; |
|
| 1328 |
+ auto r = UnicodeConverters::utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt); |
|
| 1329 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1330 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1331 |
+ return r; |
|
| 1332 |
+ } |
|
| 1333 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1334 |
+ {
|
|
| 1335 |
+ to_nxt = to; |
|
| 1336 |
+ return noconv; |
|
| 1337 |
+ } |
|
| 1338 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1339 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1340 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1341 |
+ {
|
|
| 1342 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1343 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1344 |
+ return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx); |
|
| 1345 |
+ } |
|
| 1346 |
+ virtual int do_max_length() const throw() { return 4; }
|
|
| 1347 |
+}; |
|
| 1348 |
+ |
|
| 1349 |
+template<class _Elem> class __codecvt_utf8; |
|
| 1350 |
+ |
|
| 1351 |
+template<> class __codecvt_utf8<wchar_t> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1352 |
+{
|
|
| 1353 |
+ unsigned long _Maxcode_; |
|
| 1354 |
+ codecvt_mode _Mode_; |
|
| 1355 |
+public: |
|
| 1356 |
+ typedef wchar_t intern_type; |
|
| 1357 |
+ typedef char extern_type; |
|
| 1358 |
+ typedef mbstate_t state_type; |
|
| 1359 |
+ |
|
| 1360 |
+ explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1361 |
+protected: |
|
| 1362 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1363 |
+ {
|
|
| 1364 |
+#ifdef _WIN32 |
|
| 1365 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1366 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1367 |
+#else |
|
| 1368 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1369 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1370 |
+#endif |
|
| 1371 |
+ auto _frm_nxt = _frm; |
|
| 1372 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1373 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1374 |
+ auto _to_nxt = _to; |
|
| 1375 |
+ auto r = UnicodeConverters:: |
|
| 1376 |
+#ifdef _WIN32 |
|
| 1377 |
+ ucs2_to_utf8 |
|
| 1378 |
+#else |
|
| 1379 |
+ ucs4_to_utf8 |
|
| 1380 |
+#endif |
|
| 1381 |
+ (_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1382 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1383 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1384 |
+ return r; |
|
| 1385 |
+ } |
|
| 1386 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1387 |
+ {
|
|
| 1388 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1389 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1390 |
+ auto _frm_nxt = _frm; |
|
| 1391 |
+#ifdef _WIN32 |
|
| 1392 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1393 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1394 |
+#else |
|
| 1395 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1396 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1397 |
+#endif |
|
| 1398 |
+ auto _to_nxt = _to; |
|
| 1399 |
+ auto r = UnicodeConverters:: |
|
| 1400 |
+#ifdef _WIN32 |
|
| 1401 |
+ utf8_to_ucs2 |
|
| 1402 |
+#else |
|
| 1403 |
+ utf8_to_ucs4 |
|
| 1404 |
+#endif |
|
| 1405 |
+ (_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1406 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1407 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1408 |
+ return r; |
|
| 1409 |
+ } |
|
| 1410 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1411 |
+ {
|
|
| 1412 |
+ to_nxt = to; |
|
| 1413 |
+ return noconv; |
|
| 1414 |
+ } |
|
| 1415 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1416 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1417 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1418 |
+ {
|
|
| 1419 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1420 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1421 |
+ return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1422 |
+ } |
|
| 1423 |
+ virtual int do_max_length() const throw() |
|
| 1424 |
+ {
|
|
| 1425 |
+ if (this->_Mode_ & consume_header) |
|
| 1426 |
+ return 7; |
|
| 1427 |
+ return 4; |
|
| 1428 |
+ } |
|
| 1429 |
+}; |
|
| 1430 |
+ |
|
| 1431 |
+template<> class __codecvt_utf8<char16_t> : public codecvt<char16_t, char, mbstate_t> |
|
| 1432 |
+{
|
|
| 1433 |
+ unsigned long _Maxcode_; |
|
| 1434 |
+ codecvt_mode _Mode_; |
|
| 1435 |
+public: |
|
| 1436 |
+ typedef char16_t intern_type; |
|
| 1437 |
+ typedef char extern_type; |
|
| 1438 |
+ typedef mbstate_t state_type; |
|
| 1439 |
+ |
|
| 1440 |
+ explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1441 |
+protected: |
|
| 1442 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1443 |
+ {
|
|
| 1444 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1445 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1446 |
+ auto _frm_nxt = _frm; |
|
| 1447 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1448 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1449 |
+ auto _to_nxt = _to; |
|
| 1450 |
+ auto r = UnicodeConverters::ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1451 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1452 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1453 |
+ return r; |
|
| 1454 |
+ } |
|
| 1455 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1456 |
+ {
|
|
| 1457 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1458 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1459 |
+ auto _frm_nxt = _frm; |
|
| 1460 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1461 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1462 |
+ auto _to_nxt = _to; |
|
| 1463 |
+ auto r = UnicodeConverters::utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1464 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1465 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1466 |
+ return r; |
|
| 1467 |
+ } |
|
| 1468 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1469 |
+ {
|
|
| 1470 |
+ to_nxt = to; |
|
| 1471 |
+ return noconv; |
|
| 1472 |
+ } |
|
| 1473 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1474 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1475 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1476 |
+ {
|
|
| 1477 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1478 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1479 |
+ return UnicodeConverters::utf8_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1480 |
+ } |
|
| 1481 |
+ virtual int do_max_length() const throw() |
|
| 1482 |
+ {
|
|
| 1483 |
+ if (this->_Mode_ & consume_header) |
|
| 1484 |
+ return 6; |
|
| 1485 |
+ return 3; |
|
| 1486 |
+ } |
|
| 1487 |
+}; |
|
| 1488 |
+ |
|
| 1489 |
+template<> class __codecvt_utf8<char32_t> : public codecvt<char32_t, char, mbstate_t> |
|
| 1490 |
+{
|
|
| 1491 |
+ unsigned long _Maxcode_; |
|
| 1492 |
+ codecvt_mode _Mode_; |
|
| 1493 |
+public: |
|
| 1494 |
+ typedef char32_t intern_type; |
|
| 1495 |
+ typedef char extern_type; |
|
| 1496 |
+ typedef mbstate_t state_type; |
|
| 1497 |
+ |
|
| 1498 |
+ explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1499 |
+protected: |
|
| 1500 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1501 |
+ {
|
|
| 1502 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1503 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1504 |
+ auto _frm_nxt = _frm; |
|
| 1505 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1506 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1507 |
+ auto _to_nxt = _to; |
|
| 1508 |
+ auto r = UnicodeConverters::ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1509 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1510 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1511 |
+ return r; |
|
| 1512 |
+ } |
|
| 1513 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1514 |
+ {
|
|
| 1515 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1516 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1517 |
+ auto _frm_nxt = _frm; |
|
| 1518 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1519 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1520 |
+ auto _to_nxt = _to; |
|
| 1521 |
+ auto r = UnicodeConverters::utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1522 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1523 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1524 |
+ return r; |
|
| 1525 |
+ } |
|
| 1526 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1527 |
+ {
|
|
| 1528 |
+ to_nxt = to; |
|
| 1529 |
+ return noconv; |
|
| 1530 |
+ } |
|
| 1531 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1532 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1533 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1534 |
+ {
|
|
| 1535 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1536 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1537 |
+ return UnicodeConverters::utf8_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1538 |
+ } |
|
| 1539 |
+ virtual int do_max_length() const throw() |
|
| 1540 |
+ {
|
|
| 1541 |
+ if (this->_Mode_ & consume_header) |
|
| 1542 |
+ return 7; |
|
| 1543 |
+ return 4; |
|
| 1544 |
+ } |
|
| 1545 |
+}; |
|
| 1546 |
+ |
|
| 1547 |
+template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf8 : public __codecvt_utf8<_Elem> |
|
| 1548 |
+{
|
|
| 1549 |
+public: |
|
| 1550 |
+ explicit codecvt_utf8(size_t __refs = 0) : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) { }
|
|
| 1551 |
+ |
|
| 1552 |
+ ~codecvt_utf8() { }
|
|
| 1553 |
+}; |
|
| 1554 |
+ |
|
| 1555 |
+template<class _Elem, bool _LittleEndian> class __codecvt_utf16; |
|
| 1556 |
+ |
|
| 1557 |
+template<> class __codecvt_utf16<wchar_t, false> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1558 |
+{
|
|
| 1559 |
+ unsigned long _Maxcode_; |
|
| 1560 |
+ codecvt_mode _Mode_; |
|
| 1561 |
+public: |
|
| 1562 |
+ typedef wchar_t intern_type; |
|
| 1563 |
+ typedef char extern_type; |
|
| 1564 |
+ typedef mbstate_t state_type; |
|
| 1565 |
+ |
|
| 1566 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1567 |
+protected: |
|
| 1568 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1569 |
+ {
|
|
| 1570 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1571 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1572 |
+ auto _frm_nxt = _frm; |
|
| 1573 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1574 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1575 |
+ auto _to_nxt = _to; |
|
| 1576 |
+ auto r = UnicodeConverters::ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1577 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1578 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1579 |
+ return r; |
|
| 1580 |
+ } |
|
| 1581 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1582 |
+ {
|
|
| 1583 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1584 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1585 |
+ auto _frm_nxt = _frm; |
|
| 1586 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1587 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1588 |
+ auto _to_nxt = _to; |
|
| 1589 |
+ auto r = UnicodeConverters::utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1590 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1591 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1592 |
+ return r; |
|
| 1593 |
+ } |
|
| 1594 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1595 |
+ {
|
|
| 1596 |
+ to_nxt = to; |
|
| 1597 |
+ return noconv; |
|
| 1598 |
+ } |
|
| 1599 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1600 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1601 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1602 |
+ {
|
|
| 1603 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1604 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1605 |
+ return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1606 |
+ } |
|
| 1607 |
+ virtual int do_max_length() const throw() |
|
| 1608 |
+ {
|
|
| 1609 |
+ if (this->_Mode_ & consume_header) |
|
| 1610 |
+ return 6; |
|
| 1611 |
+ return 4; |
|
| 1612 |
+ } |
|
| 1613 |
+}; |
|
| 1614 |
+ |
|
| 1615 |
+template<> class __codecvt_utf16<wchar_t, true> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1616 |
+{
|
|
| 1617 |
+ unsigned long _Maxcode_; |
|
| 1618 |
+ codecvt_mode _Mode_; |
|
| 1619 |
+public: |
|
| 1620 |
+ typedef wchar_t intern_type; |
|
| 1621 |
+ typedef char extern_type; |
|
| 1622 |
+ typedef mbstate_t state_type; |
|
| 1623 |
+ |
|
| 1624 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1625 |
+protected: |
|
| 1626 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1627 |
+ {
|
|
| 1628 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1629 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1630 |
+ auto _frm_nxt = _frm; |
|
| 1631 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1632 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1633 |
+ auto _to_nxt = _to; |
|
| 1634 |
+ auto r = UnicodeConverters::ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1635 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1636 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1637 |
+ return r; |
|
| 1638 |
+ } |
|
| 1639 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1640 |
+ {
|
|
| 1641 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1642 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1643 |
+ auto _frm_nxt = _frm; |
|
| 1644 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1645 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1646 |
+ auto _to_nxt = _to; |
|
| 1647 |
+ auto r = UnicodeConverters::utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1648 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1649 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1650 |
+ return r; |
|
| 1651 |
+ } |
|
| 1652 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1653 |
+ {
|
|
| 1654 |
+ to_nxt = to; |
|
| 1655 |
+ return noconv; |
|
| 1656 |
+ } |
|
| 1657 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1658 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1659 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1660 |
+ {
|
|
| 1661 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1662 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1663 |
+ return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1664 |
+ } |
|
| 1665 |
+ virtual int do_max_length() const throw() |
|
| 1666 |
+ {
|
|
| 1667 |
+ if (this->_Mode_ & consume_header) |
|
| 1668 |
+ return 6; |
|
| 1669 |
+ return 4; |
|
| 1670 |
+ } |
|
| 1671 |
+}; |
|
| 1672 |
+ |
|
| 1673 |
+template<> class __codecvt_utf16<char16_t, false> : public codecvt<char16_t, char, mbstate_t> |
|
| 1674 |
+{
|
|
| 1675 |
+ unsigned long _Maxcode_; |
|
| 1676 |
+ codecvt_mode _Mode_; |
|
| 1677 |
+public: |
|
| 1678 |
+ typedef char16_t intern_type; |
|
| 1679 |
+ typedef char extern_type; |
|
| 1680 |
+ typedef mbstate_t state_type; |
|
| 1681 |
+ |
|
| 1682 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1683 |
+protected: |
|
| 1684 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1685 |
+ {
|
|
| 1686 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1687 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1688 |
+ auto _frm_nxt = _frm; |
|
| 1689 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1690 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1691 |
+ auto _to_nxt = _to; |
|
| 1692 |
+ auto r = UnicodeConverters::ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1693 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1694 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1695 |
+ return r; |
|
| 1696 |
+ } |
|
| 1697 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1698 |
+ {
|
|
| 1699 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1700 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1701 |
+ auto _frm_nxt = _frm; |
|
| 1702 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1703 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1704 |
+ auto _to_nxt = _to; |
|
| 1705 |
+ auto r = UnicodeConverters::utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1706 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1707 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1708 |
+ return r; |
|
| 1709 |
+ } |
|
| 1710 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1711 |
+ {
|
|
| 1712 |
+ to_nxt = to; |
|
| 1713 |
+ return noconv; |
|
| 1714 |
+ } |
|
| 1715 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1716 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1717 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1718 |
+ {
|
|
| 1719 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1720 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1721 |
+ return UnicodeConverters::utf16be_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1722 |
+ } |
|
| 1723 |
+ virtual int do_max_length() const throw() |
|
| 1724 |
+ {
|
|
| 1725 |
+ if (this->_Mode_ & consume_header) |
|
| 1726 |
+ return 4; |
|
| 1727 |
+ return 2; |
|
| 1728 |
+ } |
|
| 1729 |
+}; |
|
| 1730 |
+ |
|
| 1731 |
+template<> class __codecvt_utf16<char16_t, true> : public codecvt<char16_t, char, mbstate_t> |
|
| 1732 |
+{
|
|
| 1733 |
+ unsigned long _Maxcode_; |
|
| 1734 |
+ codecvt_mode _Mode_; |
|
| 1735 |
+public: |
|
| 1736 |
+ typedef char16_t intern_type; |
|
| 1737 |
+ typedef char extern_type; |
|
| 1738 |
+ typedef mbstate_t state_type; |
|
| 1739 |
+ |
|
| 1740 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1741 |
+protected: |
|
| 1742 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1743 |
+ {
|
|
| 1744 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 1745 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 1746 |
+ auto _frm_nxt = _frm; |
|
| 1747 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1748 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1749 |
+ auto _to_nxt = _to; |
|
| 1750 |
+ auto r = UnicodeConverters::ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1751 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1752 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1753 |
+ return r; |
|
| 1754 |
+ } |
|
| 1755 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1756 |
+ {
|
|
| 1757 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1758 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1759 |
+ auto _frm_nxt = _frm; |
|
| 1760 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 1761 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 1762 |
+ auto _to_nxt = _to; |
|
| 1763 |
+ auto r = UnicodeConverters::utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1764 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1765 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1766 |
+ return r; |
|
| 1767 |
+ } |
|
| 1768 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1769 |
+ {
|
|
| 1770 |
+ to_nxt = to; |
|
| 1771 |
+ return noconv; |
|
| 1772 |
+ } |
|
| 1773 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1774 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1775 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1776 |
+ {
|
|
| 1777 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1778 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1779 |
+ return UnicodeConverters::utf16le_to_ucs2_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1780 |
+ } |
|
| 1781 |
+ virtual int do_max_length() const throw() |
|
| 1782 |
+ {
|
|
| 1783 |
+ if (this->_Mode_ & consume_header) |
|
| 1784 |
+ return 4; |
|
| 1785 |
+ return 2; |
|
| 1786 |
+ } |
|
| 1787 |
+}; |
|
| 1788 |
+ |
|
| 1789 |
+template<> class __codecvt_utf16<char32_t, false> : public codecvt<char32_t, char, mbstate_t> |
|
| 1790 |
+{
|
|
| 1791 |
+ unsigned long _Maxcode_; |
|
| 1792 |
+ codecvt_mode _Mode_; |
|
| 1793 |
+public: |
|
| 1794 |
+ typedef char32_t intern_type; |
|
| 1795 |
+ typedef char extern_type; |
|
| 1796 |
+ typedef mbstate_t state_type; |
|
| 1797 |
+ |
|
| 1798 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1799 |
+protected: |
|
| 1800 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1801 |
+ {
|
|
| 1802 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1803 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1804 |
+ auto _frm_nxt = _frm; |
|
| 1805 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1806 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1807 |
+ auto _to_nxt = _to; |
|
| 1808 |
+ auto r = UnicodeConverters::ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1809 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1810 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1811 |
+ return r; |
|
| 1812 |
+ } |
|
| 1813 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1814 |
+ {
|
|
| 1815 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1816 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1817 |
+ auto _frm_nxt = _frm; |
|
| 1818 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1819 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1820 |
+ auto _to_nxt = _to; |
|
| 1821 |
+ auto r = UnicodeConverters::utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1822 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1823 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1824 |
+ return r; |
|
| 1825 |
+ } |
|
| 1826 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1827 |
+ {
|
|
| 1828 |
+ to_nxt = to; |
|
| 1829 |
+ return noconv; |
|
| 1830 |
+ } |
|
| 1831 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1832 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1833 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1834 |
+ {
|
|
| 1835 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1836 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1837 |
+ return UnicodeConverters::utf16be_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1838 |
+ } |
|
| 1839 |
+ virtual int do_max_length() const throw() |
|
| 1840 |
+ {
|
|
| 1841 |
+ if (this->_Mode_ & consume_header) |
|
| 1842 |
+ return 6; |
|
| 1843 |
+ return 4; |
|
| 1844 |
+ } |
|
| 1845 |
+}; |
|
| 1846 |
+ |
|
| 1847 |
+template<> class __codecvt_utf16<char32_t, true> : public codecvt<char32_t, char, mbstate_t> |
|
| 1848 |
+{
|
|
| 1849 |
+ unsigned long _Maxcode_; |
|
| 1850 |
+ codecvt_mode _Mode_; |
|
| 1851 |
+public: |
|
| 1852 |
+ typedef char32_t intern_type; |
|
| 1853 |
+ typedef char extern_type; |
|
| 1854 |
+ typedef mbstate_t state_type; |
|
| 1855 |
+ |
|
| 1856 |
+ explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1857 |
+protected: |
|
| 1858 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1859 |
+ {
|
|
| 1860 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1861 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1862 |
+ auto _frm_nxt = _frm; |
|
| 1863 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1864 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1865 |
+ auto _to_nxt = _to; |
|
| 1866 |
+ auto r = UnicodeConverters::ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1867 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1868 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1869 |
+ return r; |
|
| 1870 |
+ } |
|
| 1871 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1872 |
+ {
|
|
| 1873 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1874 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1875 |
+ auto _frm_nxt = _frm; |
|
| 1876 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1877 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1878 |
+ auto _to_nxt = _to; |
|
| 1879 |
+ auto r = UnicodeConverters::utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1880 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1881 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1882 |
+ return r; |
|
| 1883 |
+ } |
|
| 1884 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1885 |
+ {
|
|
| 1886 |
+ to_nxt = to; |
|
| 1887 |
+ return noconv; |
|
| 1888 |
+ } |
|
| 1889 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1890 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1891 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1892 |
+ {
|
|
| 1893 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1894 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1895 |
+ return UnicodeConverters::utf16le_to_ucs4_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1896 |
+ } |
|
| 1897 |
+ virtual int do_max_length() const throw() |
|
| 1898 |
+ {
|
|
| 1899 |
+ if (this->_Mode_ & consume_header) |
|
| 1900 |
+ return 6; |
|
| 1901 |
+ return 4; |
|
| 1902 |
+ } |
|
| 1903 |
+}; |
|
| 1904 |
+ |
|
| 1905 |
+template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf16 : public __codecvt_utf16<_Elem, _Mode & little_endian> |
|
| 1906 |
+{
|
|
| 1907 |
+public: |
|
| 1908 |
+ explicit codecvt_utf16(size_t __refs = 0) : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) { }
|
|
| 1909 |
+ |
|
| 1910 |
+ ~codecvt_utf16() { }
|
|
| 1911 |
+}; |
|
| 1912 |
+ |
|
| 1913 |
+template<class _Elem> class __codecvt_utf8_utf16; |
|
| 1914 |
+ |
|
| 1915 |
+template<> class __codecvt_utf8_utf16<wchar_t> : public codecvt<wchar_t, char, mbstate_t> |
|
| 1916 |
+{
|
|
| 1917 |
+ unsigned long _Maxcode_; |
|
| 1918 |
+ codecvt_mode _Mode_; |
|
| 1919 |
+public: |
|
| 1920 |
+ typedef wchar_t intern_type; |
|
| 1921 |
+ typedef char extern_type; |
|
| 1922 |
+ typedef mbstate_t state_type; |
|
| 1923 |
+ |
|
| 1924 |
+ explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1925 |
+protected: |
|
| 1926 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1927 |
+ {
|
|
| 1928 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1929 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1930 |
+ auto _frm_nxt = _frm; |
|
| 1931 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1932 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1933 |
+ auto _to_nxt = _to; |
|
| 1934 |
+ auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1935 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1936 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1937 |
+ return r; |
|
| 1938 |
+ } |
|
| 1939 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1940 |
+ {
|
|
| 1941 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1942 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1943 |
+ auto _frm_nxt = _frm; |
|
| 1944 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 1945 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 1946 |
+ auto _to_nxt = _to; |
|
| 1947 |
+ auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1948 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1949 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1950 |
+ return r; |
|
| 1951 |
+ } |
|
| 1952 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 1953 |
+ {
|
|
| 1954 |
+ to_nxt = to; |
|
| 1955 |
+ return noconv; |
|
| 1956 |
+ } |
|
| 1957 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 1958 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 1959 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 1960 |
+ {
|
|
| 1961 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 1962 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 1963 |
+ return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 1964 |
+ } |
|
| 1965 |
+ virtual int do_max_length() const throw() |
|
| 1966 |
+ {
|
|
| 1967 |
+ if (this->_Mode_ & consume_header) |
|
| 1968 |
+ return 7; |
|
| 1969 |
+ return 4; |
|
| 1970 |
+ } |
|
| 1971 |
+}; |
|
| 1972 |
+ |
|
| 1973 |
+template<> class __codecvt_utf8_utf16<char32_t> : public codecvt<char32_t, char, mbstate_t> |
|
| 1974 |
+{
|
|
| 1975 |
+ unsigned long _Maxcode_; |
|
| 1976 |
+ codecvt_mode _Mode_; |
|
| 1977 |
+public: |
|
| 1978 |
+ typedef char32_t intern_type; |
|
| 1979 |
+ typedef char extern_type; |
|
| 1980 |
+ typedef mbstate_t state_type; |
|
| 1981 |
+ |
|
| 1982 |
+ explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 1983 |
+protected: |
|
| 1984 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 1985 |
+ {
|
|
| 1986 |
+ auto _frm = reinterpret_cast<const uint32_t *>(frm); |
|
| 1987 |
+ auto _frm_end = reinterpret_cast<const uint32_t *>(frm_end); |
|
| 1988 |
+ auto _frm_nxt = _frm; |
|
| 1989 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 1990 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 1991 |
+ auto _to_nxt = _to; |
|
| 1992 |
+ auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 1993 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 1994 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 1995 |
+ return r; |
|
| 1996 |
+ } |
|
| 1997 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 1998 |
+ {
|
|
| 1999 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2000 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2001 |
+ auto _frm_nxt = _frm; |
|
| 2002 |
+ auto _to = reinterpret_cast<uint32_t *>(to); |
|
| 2003 |
+ auto _to_end = reinterpret_cast<uint32_t *>(to_end); |
|
| 2004 |
+ auto _to_nxt = _to; |
|
| 2005 |
+ auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2006 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2007 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 2008 |
+ return r; |
|
| 2009 |
+ } |
|
| 2010 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 2011 |
+ {
|
|
| 2012 |
+ to_nxt = to; |
|
| 2013 |
+ return noconv; |
|
| 2014 |
+ } |
|
| 2015 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 2016 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 2017 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 2018 |
+ {
|
|
| 2019 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2020 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2021 |
+ return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 2022 |
+ } |
|
| 2023 |
+ virtual int do_max_length() const throw() |
|
| 2024 |
+ {
|
|
| 2025 |
+ if (this->_Mode_ & consume_header) |
|
| 2026 |
+ return 7; |
|
| 2027 |
+ return 4; |
|
| 2028 |
+ } |
|
| 2029 |
+}; |
|
| 2030 |
+ |
|
| 2031 |
+template<> class __codecvt_utf8_utf16<char16_t> : public codecvt<char16_t, char, mbstate_t> |
|
| 2032 |
+{
|
|
| 2033 |
+ unsigned long _Maxcode_; |
|
| 2034 |
+ codecvt_mode _Mode_; |
|
| 2035 |
+public: |
|
| 2036 |
+ typedef char16_t intern_type; |
|
| 2037 |
+ typedef char extern_type; |
|
| 2038 |
+ typedef mbstate_t state_type; |
|
| 2039 |
+ |
|
| 2040 |
+ explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, codecvt_mode _Mode) : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode), _Mode_(_Mode) { }
|
|
| 2041 |
+protected: |
|
| 2042 |
+ virtual result do_out(state_type &, const intern_type *frm, const intern_type *frm_end, const intern_type *&frm_nxt, extern_type *to, extern_type *to_end, extern_type *&to_nxt) const |
|
| 2043 |
+ {
|
|
| 2044 |
+ auto _frm = reinterpret_cast<const uint16_t *>(frm); |
|
| 2045 |
+ auto _frm_end = reinterpret_cast<const uint16_t *>(frm_end); |
|
| 2046 |
+ auto _frm_nxt = _frm; |
|
| 2047 |
+ auto _to = reinterpret_cast<uint8_t *>(to); |
|
| 2048 |
+ auto _to_end = reinterpret_cast<uint8_t *>(to_end); |
|
| 2049 |
+ auto _to_nxt = _to; |
|
| 2050 |
+ auto r = UnicodeConverters::utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2051 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2052 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 2053 |
+ return r; |
|
| 2054 |
+ } |
|
| 2055 |
+ virtual result do_in(state_type &, const extern_type *frm, const extern_type *frm_end, const extern_type *&frm_nxt, intern_type *to, intern_type *to_end, intern_type *&to_nxt) const |
|
| 2056 |
+ {
|
|
| 2057 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2058 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2059 |
+ auto _frm_nxt = _frm; |
|
| 2060 |
+ auto _to = reinterpret_cast<uint16_t *>(to); |
|
| 2061 |
+ auto _to_end = reinterpret_cast<uint16_t *>(to_end); |
|
| 2062 |
+ auto _to_nxt = _to; |
|
| 2063 |
+ auto r = UnicodeConverters::utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, this->_Maxcode_, this->_Mode_); |
|
| 2064 |
+ frm_nxt = frm + (_frm_nxt - _frm); |
|
| 2065 |
+ to_nxt = to + (_to_nxt - _to); |
|
| 2066 |
+ return r; |
|
| 2067 |
+ } |
|
| 2068 |
+ virtual result do_unshift(state_type &, extern_type *to, extern_type *, extern_type *&to_nxt) const |
|
| 2069 |
+ {
|
|
| 2070 |
+ to_nxt = to; |
|
| 2071 |
+ return noconv; |
|
| 2072 |
+ } |
|
| 2073 |
+ virtual int do_encoding() const throw() { return 0; }
|
|
| 2074 |
+ virtual bool do_always_noconv() const throw() { return false; }
|
|
| 2075 |
+ virtual int do_length(state_type &, const extern_type *frm, const extern_type *frm_end, size_t mx) const |
|
| 2076 |
+ {
|
|
| 2077 |
+ auto _frm = reinterpret_cast<const uint8_t *>(frm); |
|
| 2078 |
+ auto _frm_end = reinterpret_cast<const uint8_t *>(frm_end); |
|
| 2079 |
+ return UnicodeConverters::utf8_to_utf16_length(_frm, _frm_end, mx, this->_Maxcode_, this->_Mode_); |
|
| 2080 |
+ } |
|
| 2081 |
+ virtual int do_max_length() const throw() |
|
| 2082 |
+ {
|
|
| 2083 |
+ if (this->_Mode_ & consume_header) |
|
| 2084 |
+ return 7; |
|
| 2085 |
+ return 4; |
|
| 2086 |
+ } |
|
| 2087 |
+}; |
|
| 2088 |
+ |
|
| 2089 |
+template<class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = static_cast<codecvt_mode>(0)> class codecvt_utf8_utf16 : public __codecvt_utf8_utf16<_Elem> |
|
| 2090 |
+{
|
|
| 2091 |
+public: |
|
| 2092 |
+ explicit codecvt_utf8_utf16(size_t __refs = 0) : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) { }
|
|
| 2093 |
+ |
|
| 2094 |
+ ~codecvt_utf8_utf16() {}
|
|
| 2095 |
+}; |
|
| 2096 |
+ |
|
| 2097 |
+}; |
|
| 2098 |
+#endif |