Lines Matching +full:byte +full:- +full:len
3 ** Standard library for UTF-8 manipulation
29 #define MSGInvalid "invalid UTF-8 code"
32 ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
47 static lua_Integer u_posrelat (lua_Integer pos, size_t len) { in u_posrelat() argument
49 else if (0u - (size_t)pos > len) return 0; in u_posrelat()
50 else return (lua_Integer)len + pos + 1; in u_posrelat()
55 ** Decode one UTF-8 sequence, returning NULL if byte sequence is
58 ** entry forces an error for non-ascii bytes with no continuation
71 unsigned int cc = (unsigned char)s[++count]; /* read next byte */ in utf8_decode()
72 if (!iscont(cc)) /* not a continuation byte? */ in utf8_decode()
73 return NULL; /* invalid byte sequence */ in utf8_decode()
74 res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ in utf8_decode()
76 res |= ((utfint)(c & 0x7F) << (count * 5)); /* add first byte */ in utf8_decode()
78 return NULL; /* invalid byte sequence */ in utf8_decode()
87 return s + 1; /* +1 to include first byte */ in utf8_decode()
92 ** utf8len(s [, i [, j [, lax]]]) --> number of characters that
98 size_t len; /* string length in bytes */ in utflen() local
99 const char *s = luaL_checklstring(L, 1, &len); in utflen()
100 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); in utflen()
101 lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); in utflen()
103 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, in utflen()
105 luaL_argcheck(L, --posj < (lua_Integer)len, 3, in utflen()
114 posi = s1 - s; in utflen()
123 ** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all
127 size_t len; in codepoint() local
128 const char *s = luaL_checklstring(L, 1, &len); in codepoint()
129 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); in codepoint()
130 lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); in codepoint()
135 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds"); in codepoint()
137 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */ in codepoint()
139 n = (int)(pose - posi) + 1; /* upper bound for number of returns */ in codepoint()
143 for (s += posi - 1; s < se;) { in codepoint()
163 ** utfchar(n1, n2, ...) -> char(n1)..char(n2)...
184 ** offset(s, n, [i]) -> index where n-th character counting from
188 size_t len; in byteoffset() local
189 const char *s = luaL_checklstring(L, 1, &len); in byteoffset()
191 lua_Integer posi = (n >= 0) ? 1 : len + 1; in byteoffset()
192 posi = u_posrelat(luaL_optinteger(L, 3, posi), len); in byteoffset()
193 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, in byteoffset()
196 /* find beginning of current byte sequence */ in byteoffset()
197 while (posi > 0 && iscontp(s + posi)) posi--; in byteoffset()
201 return luaL_error(L, "initial position is a continuation byte"); in byteoffset()
205 posi--; in byteoffset()
211 n--; /* do not move for 1st character */ in byteoffset()
212 while (n > 0 && posi < (lua_Integer)len) { in byteoffset()
216 n--; in byteoffset()
229 size_t len; in iter_aux() local
230 const char *s = luaL_checklstring(L, 1, &len); in iter_aux()
232 if (n < len) { in iter_aux()
235 if (n >= len) /* (also handles original 'n' being negative) */ in iter_aux()
269 /* pattern to match a single UTF-8 character */
270 #define UTF8PATT "[\0-\x7F\xC2-\xFD][\x80-\xBF]*"
277 {"len", utflen},
287 lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1); in luaopen_utf8()
288 lua_setfield(L, -2, "charpattern"); in luaopen_utf8()