MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaO_utf8esc

Function luaO_utf8esc

extlibs/lua/src/lobject.c:318–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316
317
318int 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 */

Callers 2

utf8escFunction · 0.85
luaO_pushvfstringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected