| 316 | |
| 317 | |
| 318 | int luaO_utf8esc (char *buff, unsigned long x) { |
| 319 | int n = 1; /* number of bytes put in buffer (backwards) */ |
| 320 | lua_assert(x <= 0x7FFFFFFFu); |
| 321 | if (x < 0x80) /* ascii? */ |
| 322 | buff[UTF8BUFFSZ - 1] = cast_char(x); |
| 323 | else { /* need continuation bytes */ |
| 324 | unsigned int mfb = 0x3f; /* maximum that fits in first byte */ |
| 325 | do { /* add continuation bytes */ |
| 326 | buff[UTF8BUFFSZ - (n++)] = cast_char(0x80 | (x & 0x3f)); |
| 327 | x >>= 6; /* remove added bits */ |
| 328 | mfb >>= 1; /* now there is one less bit available in first byte */ |
| 329 | } while (x > mfb); /* still needs continuation byte? */ |
| 330 | buff[UTF8BUFFSZ - n] = cast_char((~mfb << 1) | x); /* add first byte */ |
| 331 | } |
| 332 | return n; |
| 333 | } |
| 334 | |
| 335 | |
| 336 | /* maximum length of the conversion of a number to a string */ |
no outgoing calls
no test coverage detected