-----------------------------------------------------------------------------
| 494 | |
| 495 | //----------------------------------------------------------------------------- |
| 496 | const U32 oneUTF32toUTF8(const UTF32 codepoint, UTF8 *threeByteCodeunitBuf) |
| 497 | { |
| 498 | PROFILE_START(oneUTF32toUTF8); |
| 499 | U32 bytecount = 0; |
| 500 | UTF8 *buf; |
| 501 | U32 working = codepoint; |
| 502 | buf = threeByteCodeunitBuf; |
| 503 | |
| 504 | //----------------- |
| 505 | if(isSurrogateRange(working)) // found an illegal codepoint! |
| 506 | working = kReplacementChar; |
| 507 | //return oneUTF32toUTF8(kReplacementChar, threeByteCodeunitBuf); |
| 508 | |
| 509 | if(isAboveBMP(working)) // these are legal, we just dont want to deal with them. |
| 510 | working = kReplacementChar; |
| 511 | //return oneUTF32toUTF8(kReplacementChar, threeByteCodeunitBuf); |
| 512 | |
| 513 | //----------------- |
| 514 | if( working < (1 << 7)) // codeable in 7 bits |
| 515 | bytecount = 1; |
| 516 | else if( working < (1 << 11)) // codeable in 11 bits |
| 517 | bytecount = 2; |
| 518 | else if( working < (1 << 16)) // codeable in 16 bits |
| 519 | bytecount = 3; |
| 520 | |
| 521 | AssertISV( bytecount > 0, "Error converting to UTF-8 in oneUTF32toUTF8(). isAboveBMP() should have caught this!"); |
| 522 | |
| 523 | //----------------- |
| 524 | U8 mask = byteMask8LUT[0]; // 0011 1111 |
| 525 | U8 marker = ( ~mask << 1); // 1000 0000 |
| 526 | |
| 527 | // Process the low order bytes, shifting the codepoint down 6 each pass. |
| 528 | for( int i = bytecount-1; i > 0; i--) |
| 529 | { |
| 530 | threeByteCodeunitBuf[i] = marker | (working & mask); |
| 531 | working >>= 6; |
| 532 | } |
| 533 | |
| 534 | // Process the 1st byte. filter based on the # of expected bytes. |
| 535 | mask = byteMask8LUT[bytecount]; |
| 536 | marker = ( ~mask << 1 ); |
| 537 | threeByteCodeunitBuf[0] = marker | (working & mask); |
| 538 | |
| 539 | PROFILE_END(); |
| 540 | return bytecount; |
| 541 | } |
| 542 | |
| 543 | //----------------------------------------------------------------------------- |
| 544 | const U32 dStrlen(const UTF16 *unistring) |
no test coverage detected