MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / luaO_utf8esc

Function luaO_utf8esc

ThirdParty/lua/lua/lobject.c:297–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295
296
297int 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 */

Callers 2

utf8escFunction · 0.85
luaO_pushvfstringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected