| 415 | |
| 416 | |
| 417 | void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) |
| 418 | { |
| 419 | const unsigned long BYTE_MASK = 0xBF; |
| 420 | const unsigned long BYTE_MARK = 0x80; |
| 421 | const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; |
| 422 | |
| 423 | if (input < 0x80) { |
| 424 | *length = 1; |
| 425 | } |
| 426 | else if ( input < 0x800 ) { |
| 427 | *length = 2; |
| 428 | } |
| 429 | else if ( input < 0x10000 ) { |
| 430 | *length = 3; |
| 431 | } |
| 432 | else if ( input < 0x200000 ) { |
| 433 | *length = 4; |
| 434 | } |
| 435 | else { |
| 436 | *length = 0; // This code won't convert this correctly anyway. |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | output += *length; |
| 441 | |
| 442 | // Scary scary fall throughs are annotated with carefully designed comments |
| 443 | // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc |
| 444 | switch (*length) { |
| 445 | case 4: |
| 446 | --output; |
| 447 | *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); |
| 448 | input >>= 6; |
| 449 | //fall through |
| 450 | case 3: |
| 451 | --output; |
| 452 | *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); |
| 453 | input >>= 6; |
| 454 | //fall through |
| 455 | case 2: |
| 456 | --output; |
| 457 | *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); |
| 458 | input >>= 6; |
| 459 | //fall through |
| 460 | case 1: |
| 461 | --output; |
| 462 | *output = static_cast<char>(input | FIRST_BYTE_MARK[*length]); |
| 463 | break; |
| 464 | default: |
| 465 | TIXMLASSERT( false ); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | |
| 470 | const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length) |
nothing calls this directly
no outgoing calls
no test coverage detected