| 305 | |
| 306 | |
| 307 | void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) |
| 308 | { |
| 309 | const unsigned long BYTE_MASK = 0xBF; |
| 310 | const unsigned long BYTE_MARK = 0x80; |
| 311 | const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; |
| 312 | |
| 313 | if (input < 0x80) { |
| 314 | *length = 1; |
| 315 | } |
| 316 | else if ( input < 0x800 ) { |
| 317 | *length = 2; |
| 318 | } |
| 319 | else if ( input < 0x10000 ) { |
| 320 | *length = 3; |
| 321 | } |
| 322 | else if ( input < 0x200000 ) { |
| 323 | *length = 4; |
| 324 | } |
| 325 | else { |
| 326 | *length = 0; // This code won't covert this correctly anyway. |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | output += *length; |
| 331 | |
| 332 | // Scary scary fall throughs. |
| 333 | switch (*length) { |
| 334 | case 4: |
| 335 | --output; |
| 336 | *output = (char)((input | BYTE_MARK) & BYTE_MASK); |
| 337 | input >>= 6; |
| 338 | case 3: |
| 339 | --output; |
| 340 | *output = (char)((input | BYTE_MARK) & BYTE_MASK); |
| 341 | input >>= 6; |
| 342 | case 2: |
| 343 | --output; |
| 344 | *output = (char)((input | BYTE_MARK) & BYTE_MASK); |
| 345 | input >>= 6; |
| 346 | case 1: |
| 347 | --output; |
| 348 | *output = (char)(input | FIRST_BYTE_MARK[*length]); |
| 349 | break; |
| 350 | default: |
| 351 | TIXMLASSERT( false ); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) |
nothing calls this directly
no outgoing calls
no test coverage detected