MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaO_utf8esc

Function luaO_utf8esc

3rd/lua-5.4.3/src/lobject.c:323–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321
322
323int 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/*

Callers 2

utf8escFunction · 0.85
luaO_pushvfstringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected