better to use 'long' to represent UTF-8 code points
This commit is contained in:
6
llex.c
6
llex.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 2.79 2014/07/18 12:17:54 roberto Exp roberto $
|
** $Id: llex.c,v 2.80 2014/07/18 13:36:14 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -360,8 +360,8 @@ static int readhexaesc (LexState *ls) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static unsigned int readutf8esc (LexState *ls) {
|
static unsigned long readutf8esc (LexState *ls) {
|
||||||
unsigned int r;
|
unsigned long r;
|
||||||
int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
|
int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
|
||||||
save_and_next(ls); /* skip 'u' */
|
save_and_next(ls); /* skip 'u' */
|
||||||
esccheck(ls, ls->current == '{', "missing '{'");
|
esccheck(ls, ls->current == '{', "missing '{'");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 2.88 2014/07/30 14:00:14 roberto Exp roberto $
|
** $Id: lobject.c,v 2.89 2014/08/01 17:24:02 roberto Exp roberto $
|
||||||
** Some generic functions over Lua objects
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -310,8 +310,9 @@ size_t luaO_str2num (const char *s, TValue *o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int luaO_utf8esc (char *buff, unsigned int x) {
|
int luaO_utf8esc (char *buff, unsigned long x) {
|
||||||
int n = 1; /* number of bytes put in buffer (backwards) */
|
int n = 1; /* number of bytes put in buffer (backwards) */
|
||||||
|
lua_assert(x <= 0x10FFFF);
|
||||||
if (x < 0x80) /* ascii? */
|
if (x < 0x80) /* ascii? */
|
||||||
buff[UTF8BUFFSZ - 1] = x;
|
buff[UTF8BUFFSZ - 1] = x;
|
||||||
else { /* need continuation bytes */
|
else { /* need continuation bytes */
|
||||||
@@ -402,7 +403,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
|||||||
}
|
}
|
||||||
case 'U': {
|
case 'U': {
|
||||||
char buff[UTF8BUFFSZ];
|
char buff[UTF8BUFFSZ];
|
||||||
int l = luaO_utf8esc(buff, va_arg(argp, int));
|
int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));
|
||||||
pushstr(L, buff + UTF8BUFFSZ - l, l);
|
pushstr(L, buff + UTF8BUFFSZ - l, l);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.h,v 2.101 2014/07/30 14:00:14 roberto Exp roberto $
|
** $Id: lobject.h,v 2.102 2014/09/04 18:15:29 roberto Exp roberto $
|
||||||
** Type definitions for Lua objects
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -521,7 +521,7 @@ LUAI_DDEC const TValue luaO_nilobject_;
|
|||||||
|
|
||||||
LUAI_FUNC int luaO_int2fb (unsigned int x);
|
LUAI_FUNC int luaO_int2fb (unsigned int x);
|
||||||
LUAI_FUNC int luaO_fb2int (int x);
|
LUAI_FUNC int luaO_fb2int (int x);
|
||||||
LUAI_FUNC int luaO_utf8esc (char *buff, unsigned int x);
|
LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);
|
||||||
LUAI_FUNC int luaO_ceillog2 (unsigned int x);
|
LUAI_FUNC int luaO_ceillog2 (unsigned int x);
|
||||||
LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,
|
LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,
|
||||||
const TValue *p2, TValue *res);
|
const TValue *p2, TValue *res);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lutf8lib.c,v 1.9 2014/05/14 18:33:37 roberto Exp roberto $
|
** $Id: lutf8lib.c,v 1.10 2014/07/16 13:56:14 roberto Exp roberto $
|
||||||
** Standard library for UTF-8 manipulation
|
** Standard library for UTF-8 manipulation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -123,9 +123,9 @@ static int codepoint (lua_State *L) {
|
|||||||
|
|
||||||
|
|
||||||
static void pushutfchar (lua_State *L, int arg) {
|
static void pushutfchar (lua_State *L, int arg) {
|
||||||
int code = luaL_checkint(L, arg);
|
lua_Integer code = luaL_checkinteger(L, arg);
|
||||||
luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range");
|
luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range");
|
||||||
lua_pushfstring(L, "%U", code);
|
lua_pushfstring(L, "%U", (long)code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ static int utfchar (lua_State *L) {
|
|||||||
static int byteoffset (lua_State *L) {
|
static int byteoffset (lua_State *L) {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *s = luaL_checklstring(L, 1, &len);
|
const char *s = luaL_checklstring(L, 1, &len);
|
||||||
int n = luaL_checkint(L, 2);
|
lua_Integer n = luaL_checkinteger(L, 2);
|
||||||
lua_Integer posi = (n >= 0) ? 1 : len + 1;
|
lua_Integer posi = (n >= 0) ? 1 : len + 1;
|
||||||
posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
|
posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
|
||||||
luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
|
luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
|
||||||
|
|||||||
Reference in New Issue
Block a user