-----------------------------------------------------------------------------
| 443 | |
| 444 | //----------------------------------------------------------------------------- |
| 445 | U32 oneUTF32toUTF8(const UTF32 codepoint, UTF8 *threeByteCodeunitBuf) |
| 446 | { |
| 447 | PROFILE_START(oneUTF32toUTF8); |
| 448 | U32 bytecount = 0; |
| 449 | UTF8 *buf; |
| 450 | U32 working = codepoint; |
| 451 | buf = threeByteCodeunitBuf; |
| 452 | |
| 453 | //----------------- |
| 454 | if(isSurrogateRange(working)) // found an illegal codepoint! |
| 455 | working = kReplacementChar; |
| 456 | |
| 457 | if(isAboveBMP(working)) // these are legal, we just dont want to deal with them. |
| 458 | working = kReplacementChar; |
| 459 | |
| 460 | //----------------- |
| 461 | if( working < (1 << 7)) // codeable in 7 bits |
| 462 | bytecount = 1; |
| 463 | else if( working < (1 << 11)) // codeable in 11 bits |
| 464 | bytecount = 2; |
| 465 | else if( working < (1 << 16)) // codeable in 16 bits |
| 466 | bytecount = 3; |
| 467 | |
| 468 | AssertISV( bytecount > 0, "Error converting to UTF-8 in oneUTF32toUTF8(). isAboveBMP() should have caught this!"); |
| 469 | |
| 470 | //----------------- |
| 471 | U8 mask = sgByteMask8LUT[0]; // 0011 1111 |
| 472 | U8 marker = ( ~static_cast<U32>(mask) << 1u); // 1000 0000 |
| 473 | |
| 474 | // Process the low order bytes, shifting the codepoint down 6 each pass. |
| 475 | for( S32 i = bytecount-1; i > 0; i--) |
| 476 | { |
| 477 | threeByteCodeunitBuf[i] = marker | (working & mask); |
| 478 | working >>= 6; |
| 479 | } |
| 480 | |
| 481 | // Process the 1st byte. filter based on the # of expected bytes. |
| 482 | mask = sgByteMask8LUT[bytecount]; |
| 483 | marker = ( ~mask << 1 ); |
| 484 | threeByteCodeunitBuf[0] = marker | (working & mask); |
| 485 | |
| 486 | PROFILE_END(); |
| 487 | return bytecount; |
| 488 | } |
| 489 | |
| 490 | //----------------------------------------------------------------------------- |
| 491 | U32 dStrlen(const UTF16 *unistring) |
no test coverage detected