MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / oneUTF16toUTF32

Function oneUTF16toUTF32

engine/source/string/unicode.cc:428–478  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

426
427//-----------------------------------------------------------------------------
428const UTF32 oneUTF16toUTF32(const UTF16* codepoint, U32 *unitsWalked)
429{
430 PROFILE_START(oneUTF16toUTF32);
431 U8 expectedType;
432 U32 unitCount;
433 UTF32 ret = 0;
434 UTF16 codeunit1,codeunit2;
435
436 codeunit1 = codepoint[0];
437 expectedType = surrogateLUT[codeunit1 >> 10];
438 switch(expectedType)
439 {
440 case 0: // simple
441 ret = codeunit1;
442 unitCount = 1;
443 break;
444 case 1: // 2 surrogates
445 codeunit2 = codepoint[1];
446 if( surrogateLUT[codeunit2 >> 10] == 2)
447 {
448 ret = ((codeunit1 & byteMaskLow10 ) << 10) | (codeunit2 & byteMaskLow10);
449 unitCount = 2;
450 break;
451 }
452 // else, did not find a trailing surrogate where we expected one,
453 // so fall through to the error
454 case 2: // error
455 // found a trailing surrogate where we expected a codepoint or leading surrogate.
456 // Dump the replacement.
457 ret = kReplacementChar;
458 unitCount = 1;
459 break;
460 }
461
462 if(unitsWalked != NULL)
463 *unitsWalked = unitCount;
464
465 // codepoints in the surrogate range are illegal, and should be replaced.
466 if(isSurrogateRange(ret))
467 ret = kReplacementChar;
468
469 // codepoints outside the Basic Multilingual Plane add complexity to our UTF16 string classes,
470 // we've read them correctly so they wont foul the byte stream,
471 // but we kill them here to make sure they wont foul anything else
472 // NOTE: these are perfectly legal codepoints, we just dont want to deal with them.
473 if(isAboveBMP(ret))
474 ret = kReplacementChar;
475
476 PROFILE_END();
477 return ret;
478}
479
480//-----------------------------------------------------------------------------
481const UTF16 oneUTF32toUTF16(const UTF32 codepoint)

Callers 3

convertUTF16toUTF8Function · 0.85
convertUTF16toUTF32Function · 0.85

Calls 2

isSurrogateRangeFunction · 0.85
isAboveBMPFunction · 0.85

Tested by

no test coverage detected