MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaO_utf8esc

Function luaO_utf8esc

depends/lua/src/lobject.c:346–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344
345
346int luaO_utf8esc (char *buff, unsigned long x) {
347 int n = 1; /* number of bytes put in buffer (backwards) */
348 lua_assert(x <= 0x10FFFF);
349 if (x < 0x80) /* ascii? */
350 buff[UTF8BUFFSZ - 1] = cast(char, x);
351 else { /* need continuation bytes */
352 unsigned int mfb = 0x3f; /* maximum that fits in first byte */
353 do { /* add continuation bytes */
354 buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));
355 x >>= 6; /* remove added bits */
356 mfb >>= 1; /* now there is one less bit available in first byte */
357 } while (x > mfb); /* still needs continuation byte? */
358 buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x); /* add first byte */
359 }
360 return n;
361}
362
363
364/* maximum length of the conversion of a number to a string */

Callers 2

utf8escFunction · 0.85
luaO_pushvfstringFunction · 0.85

Calls 1

castFunction · 0.85

Tested by

no test coverage detected