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