aboutsummaryrefslogtreecommitdiff
path: root/lutf8lib.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lutf8lib.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lutf8lib.c b/lutf8lib.c
index 4c9784e0..df49c901 100644
--- a/lutf8lib.c
+++ b/lutf8lib.c
@@ -47,7 +47,7 @@ static lua_Integer u_posrelat (lua_Integer pos, size_t len) {
47** Decode one UTF-8 sequence, returning NULL if byte sequence is 47** Decode one UTF-8 sequence, returning NULL if byte sequence is
48** invalid. The array 'limits' stores the minimum value for each 48** invalid. The array 'limits' stores the minimum value for each
49** sequence length, to check for overlong representations. Its first 49** sequence length, to check for overlong representations. Its first
50** entry forces an error for non-ascii bytes with no continuation 50** entry forces an error for non-ASCII bytes with no continuation
51** bytes (count == 0). 51** bytes (count == 0).
52*/ 52*/
53static const char *utf8_decode (const char *s, l_uint32 *val, int strict) { 53static const char *utf8_decode (const char *s, l_uint32 *val, int strict) {
@@ -55,7 +55,7 @@ static const char *utf8_decode (const char *s, l_uint32 *val, int strict) {
55 {~(l_uint32)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u}; 55 {~(l_uint32)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u};
56 unsigned int c = (unsigned char)s[0]; 56 unsigned int c = (unsigned char)s[0];
57 l_uint32 res = 0; /* final result */ 57 l_uint32 res = 0; /* final result */
58 if (c < 0x80) /* ascii? */ 58 if (c < 0x80) /* ASCII? */
59 res = c; 59 res = c;
60 else { 60 else {
61 int count = 0; /* to count number of continuation bytes */ 61 int count = 0; /* to count number of continuation bytes */
@@ -215,9 +215,10 @@ static int byteoffset (lua_State *L) {
215 } 215 }
216 lua_pushinteger(L, posi + 1); /* initial position */ 216 lua_pushinteger(L, posi + 1); /* initial position */
217 if ((s[posi] & 0x80) != 0) { /* multi-byte character? */ 217 if ((s[posi] & 0x80) != 0) { /* multi-byte character? */
218 do { 218 if (iscont(s[posi]))
219 posi++; 219 return luaL_error(L, "initial position is a continuation byte");
220 } while (iscontp(s + posi + 1)); /* skip to final byte */ 220 while (iscontp(s + posi + 1))
221 posi++; /* skip to last continuation byte */
221 } 222 }
222 /* else one-byte character: final position is the initial one */ 223 /* else one-byte character: final position is the initial one */
223 lua_pushinteger(L, posi + 1); /* 'posi' now is the final position */ 224 lua_pushinteger(L, posi + 1); /* 'posi' now is the final position */