-----------------------------------------------------------------------------
| 369 | |
| 370 | //----------------------------------------------------------------------------- |
| 371 | UTF32 oneUTF16toUTF32(const UTF16* codepoint, U32 *unitsWalked) |
| 372 | { |
| 373 | PROFILE_START(oneUTF16toUTF32); |
| 374 | U8 expectedType; |
| 375 | U32 unitCount; |
| 376 | UTF32 ret = 0; |
| 377 | UTF16 codeunit1,codeunit2; |
| 378 | |
| 379 | codeunit1 = codepoint[0]; |
| 380 | expectedType = sgSurrogateLUT[codeunit1 >> 10]; |
| 381 | switch(expectedType) |
| 382 | { |
| 383 | case 0: // simple |
| 384 | ret = codeunit1; |
| 385 | unitCount = 1; |
| 386 | break; |
| 387 | case 1: // 2 surrogates |
| 388 | codeunit2 = codepoint[1]; |
| 389 | if( sgSurrogateLUT[codeunit2 >> 10] == 2) |
| 390 | { |
| 391 | ret = ((codeunit1 & sgByteMaskLow10 ) << 10) | (codeunit2 & sgByteMaskLow10); |
| 392 | unitCount = 2; |
| 393 | break; |
| 394 | } |
| 395 | // else, did not find a trailing surrogate where we expected one, |
| 396 | // so fall through to the error |
| 397 | case 2: // error |
| 398 | // found a trailing surrogate where we expected a codepoint or leading surrogate. |
| 399 | // Dump the replacement. |
| 400 | ret = kReplacementChar; |
| 401 | unitCount = 1; |
| 402 | break; |
| 403 | default: |
| 404 | // unexpected return |
| 405 | AssertFatal(false, "oneUTF16toUTF323: unexpected type"); |
| 406 | ret = kReplacementChar; |
| 407 | unitCount = 1; |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | if(unitsWalked != NULL) |
| 412 | *unitsWalked = unitCount; |
| 413 | |
| 414 | // codepoints in the surrogate range are illegal, and should be replaced. |
| 415 | if(isSurrogateRange(ret)) |
| 416 | ret = kReplacementChar; |
| 417 | |
| 418 | // codepoints outside the Basic Multilingual Plane add complexity to our UTF16 string classes, |
| 419 | // we've read them correctly so they wont foul the byte stream, |
| 420 | // but we kill them here to make sure they wont foul anything else |
| 421 | // NOTE: these are perfectly legal codepoints, we just dont want to deal with them. |
| 422 | if(isAboveBMP(ret)) |
| 423 | ret = kReplacementChar; |
| 424 | |
| 425 | PROFILE_END(); |
| 426 | return ret; |
| 427 | } |
| 428 |
no test coverage detected