MCPcopy Create free account
hub / github.com/ajkhoury/ReClassEx / ConvertUTF32ToUTF8

Method ConvertUTF32ToUTF8

ReClass/tinyxml2.cpp:404–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402
403
404void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
405{
406 const unsigned long BYTE_MASK = 0xBF;
407 const unsigned long BYTE_MARK = 0x80;
408 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
409
410 if (input < 0x80) {
411 *length = 1;
412 }
413 else if ( input < 0x800 ) {
414 *length = 2;
415 }
416 else if ( input < 0x10000 ) {
417 *length = 3;
418 }
419 else if ( input < 0x200000 ) {
420 *length = 4;
421 }
422 else {
423 *length = 0; // This code won't convert this correctly anyway.
424 return;
425 }
426
427 output += *length;
428
429 // Scary scary fall throughs are annotated with carefully designed comments
430 // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc
431 switch (*length) {
432 case 4:
433 --output;
434 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
435 input >>= 6;
436 //fall through
437 case 3:
438 --output;
439 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
440 input >>= 6;
441 //fall through
442 case 2:
443 --output;
444 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
445 input >>= 6;
446 //fall through
447 case 1:
448 --output;
449 *output = (char)(input | FIRST_BYTE_MARK[*length]);
450 break;
451 default:
452 TIXMLASSERT( false );
453 }
454}
455
456
457const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected