MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaO_utf8esc

Function luaO_utf8esc

third-party/lua-5.5.0/src/lobject.c:386–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384
385
386int 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/*

Callers 2

utf8escFunction · 0.70
luaO_pushvfstringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected