| 384 | |
| 385 | |
| 386 | int luaO_utf8esc (char *buff, l_uint32 x) { |
| 387 | int n = 1; /* number of bytes put in buffer (backwards) */ |
| 388 | lua_assert(x <= 0x7FFFFFFFu); |
| 389 | if (x < 0x80) /* ASCII? */ |
| 390 | buff[UTF8BUFFSZ - 1] = cast_char(x); |
| 391 | else { /* need continuation bytes */ |
| 392 | unsigned int mfb = 0x3f; /* maximum that fits in first byte */ |
| 393 | do { /* add continuation bytes */ |
| 394 | buff[UTF8BUFFSZ - (n++)] = cast_char(0x80 | (x & 0x3f)); |
| 395 | x >>= 6; /* remove added bits */ |
| 396 | mfb >>= 1; /* now there is one less bit available in first byte */ |
| 397 | } while (x > mfb); /* still needs continuation byte? */ |
| 398 | buff[UTF8BUFFSZ - n] = cast_char((~mfb << 1) | x); /* add first byte */ |
| 399 | } |
| 400 | return n; |
| 401 | } |
| 402 | |
| 403 | |
| 404 | /* |
no outgoing calls
no test coverage detected