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