MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / ConvertUTF32ToUTF8

Method ConvertUTF32ToUTF8

sourcecommon/tinyxml2.cpp:270–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269
270void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
271{
272 const unsigned long BYTE_MASK = 0xBF;
273 const unsigned long BYTE_MARK = 0x80;
274 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
275
276 if (input < 0x80) {
277 *length = 1;
278 }
279 else if ( input < 0x800 ) {
280 *length = 2;
281 }
282 else if ( input < 0x10000 ) {
283 *length = 3;
284 }
285 else if ( input < 0x200000 ) {
286 *length = 4;
287 }
288 else {
289 *length = 0; // This code won't covert this correctly anyway.
290 return;
291 }
292
293 output += *length;
294
295 // Scary scary fall throughs.
296 switch (*length) {
297 case 4:
298 --output;
299 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
300 input >>= 6;
301 case 3:
302 --output;
303 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
304 input >>= 6;
305 case 2:
306 --output;
307 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
308 input >>= 6;
309 case 1:
310 --output;
311 *output = (char)(input | FIRST_BYTE_MARK[*length]);
312 default:
313 break;
314 }
315}
316
317
318const 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