mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-23 04:34:33 +02:00
*** empty log message ***
git-svn-id: file:///var/svn/lua-iconv/trunk@11 9538949d-8f27-0410-946f-ce01ef448559
This commit is contained in:
parent
0be1828c41
commit
2155d1b315
29
luaiconv.c
29
luaiconv.c
@ -99,12 +99,12 @@ static int Liconv(lua_State *L)
|
||||
char *inbuf = (char*) getstring(L, 2);
|
||||
char *outbuf;
|
||||
char *outbufs;
|
||||
size_t bsize = 4 * ibleft; /* Try to avoid concatenations on stack */
|
||||
size_t obleft = bsize;
|
||||
size_t obsize = ibleft; /* Try to avoid concatenations on stack */
|
||||
size_t obleft = obsize;
|
||||
size_t ret = -1;
|
||||
int hasone = 0;
|
||||
|
||||
outbuf = (char*) malloc(bsize * sizeof(char));
|
||||
outbuf = (char*) malloc(obsize * sizeof(char));
|
||||
if(outbuf == NULL)
|
||||
{
|
||||
lua_pushstring(L, "");
|
||||
@ -118,40 +118,29 @@ static int Liconv(lua_State *L)
|
||||
ret = iconv(cd, &inbuf, &ibleft, &outbuf, &obleft);
|
||||
if(ret == (size_t)(-1))
|
||||
{
|
||||
if(errno == EILSEQ)
|
||||
{
|
||||
lua_pushlstring(L, outbufs, bsize-obleft);
|
||||
lua_pushlstring(L, outbufs, obsize - obleft);
|
||||
if(hasone == 1)
|
||||
lua_concat(L, 2);
|
||||
hasone = 1;
|
||||
if(errno == EILSEQ)
|
||||
{
|
||||
lua_pushnumber(L, ERROR_INVALID);
|
||||
free(outbufs);
|
||||
return 2; /* Invalid character sequence */
|
||||
}
|
||||
else if(errno == EINVAL)
|
||||
{
|
||||
lua_pushlstring(L, outbufs, bsize-obleft);
|
||||
if(hasone == 1)
|
||||
lua_concat(L, 2);
|
||||
hasone = 1;
|
||||
lua_pushnumber(L, ERROR_INCOMPLETE);
|
||||
free(outbufs);
|
||||
return 2; /* Incomplete character sequence */
|
||||
}
|
||||
else if(errno == E2BIG)
|
||||
{
|
||||
lua_pushlstring(L, outbufs, bsize-obleft);
|
||||
if(hasone == 1)
|
||||
lua_concat(L, 2);
|
||||
hasone = 1;
|
||||
obleft = bsize;
|
||||
obleft = obsize;
|
||||
outbuf = outbufs;
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushlstring(L, outbufs, bsize-obleft);
|
||||
if(hasone == 1)
|
||||
lua_concat(L, 2);
|
||||
hasone = 1;
|
||||
lua_pushnumber(L, ERROR_UNKNOWN);
|
||||
free(outbufs);
|
||||
return 2; /* Unknown error */
|
||||
@ -160,7 +149,7 @@ static int Liconv(lua_State *L)
|
||||
}
|
||||
while(ret != (size_t) 0);
|
||||
|
||||
lua_pushlstring(L, outbufs, bsize-obleft);
|
||||
lua_pushlstring(L, outbufs, obsize - obleft);
|
||||
if(hasone == 1)
|
||||
lua_concat(L, 2);
|
||||
free(outbufs);
|
||||
|
@ -7,8 +7,8 @@ cd = iconv.new("utf-8", "iso-8859-1")
|
||||
|
||||
assert(cd, "Invalid conversion")
|
||||
|
||||
ret, err = cd:iconv("Isso é um teste com acentuação")
|
||||
-- ret, err = cd:iconv("çãÃÉÍÓÚÇÑÿ ")
|
||||
--ret, err = cd:iconv("Isso é um teste com acentuação")
|
||||
ret, err = cd:iconv("çãÃÉÍÓÚÇÑÿa")
|
||||
|
||||
if err == iconv.ERROR_INCOMPLETE then
|
||||
print("Error: Incomplete input.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user