| 344 | |
| 345 | |
| 346 | int luaO_utf8esc (char *buff, unsigned long x) { |
| 347 | int n = 1; /* number of bytes put in buffer (backwards) */ |
| 348 | lua_assert(x <= 0x10FFFF); |
| 349 | if (x < 0x80) /* ascii? */ |
| 350 | buff[UTF8BUFFSZ - 1] = cast(char, x); |
| 351 | else { /* need continuation bytes */ |
| 352 | unsigned int mfb = 0x3f; /* maximum that fits in first byte */ |
| 353 | do { /* add continuation bytes */ |
| 354 | buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f)); |
| 355 | x >>= 6; /* remove added bits */ |
| 356 | mfb >>= 1; /* now there is one less bit available in first byte */ |
| 357 | } while (x > mfb); /* still needs continuation byte? */ |
| 358 | buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x); /* add first byte */ |
| 359 | } |
| 360 | return n; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | /* maximum length of the conversion of a number to a string */ |
no test coverage detected