| 295 | |
| 296 | |
| 297 | int luaO_utf8esc (char *buff, unsigned long x) { |
| 298 | int n = 1; /* number of bytes put in buffer (backwards) */ |
| 299 | lua_assert(x <= 0x10FFFF); |
| 300 | if (x < 0x80) /* ascii? */ |
| 301 | buff[UTF8BUFFSZ - 1] = cast(char, x); |
| 302 | else { /* need continuation bytes */ |
| 303 | unsigned int mfb = 0x3f; /* maximum that fits in first byte */ |
| 304 | do { /* add continuation bytes */ |
| 305 | buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f)); |
| 306 | x >>= 6; /* remove added bits */ |
| 307 | mfb >>= 1; /* now there is one less bit available in first byte */ |
| 308 | } while (x > mfb); /* still needs continuation byte? */ |
| 309 | buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x); /* add first byte */ |
| 310 | } |
| 311 | return n; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | /* maximum length of the conversion of a number to a string */ |
no outgoing calls
no test coverage detected