| 402 | |
| 403 | |
| 404 | void 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 | |
| 457 | const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) |
nothing calls this directly
no outgoing calls
no test coverage detected