Skip to content

Commit

Permalink
fix: 修正iconv库的API错误描述
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Jan 15, 2025
1 parent c8282f3 commit f992dbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 53 deletions.
51 changes: 2 additions & 49 deletions components/iconv/iconv.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
/**************************************************************************
* Copyright (C), AirM2M Tech. Co., Ltd.
*
* Name: iconv.c
* Author: liweiqiang
* Version: V0.1
* Date: 2013/7/15
*
* Description:
* 字符编码转换
**************************************************************************/
/*
@module iconv
@summary 字符编码转换
@version V0.1
@data 2021年12月13日
*/

#include <string.h>
#include "iconv.h"
Expand Down Expand Up @@ -43,16 +26,6 @@ static const builtin_iconv_map iconv_map[] =
/*-\NEW\liweiqiang\2013.7.19\增加utf8<->ucs2,ucs2be编码转换*/
};

/*
打开相应字符编码转换函数
@function iconv.open(tocode, fromcode)
@string tocode$目标编码格式$gb2312/ucs2/ucs2be/utf8
@string fromcode$源编码格式$gb2312/ucs2/ucs2be/utf8
@return table$cd$编码转换函数的转换句柄$
@usage
--unicode大端编码 转化为 utf8编码
local cd = iconv.open("utf8", "ucs2be")
*/
iconv_t iconv_open (const char * to_code, const char * from_code)
{
size_t i;
Expand All @@ -69,18 +42,7 @@ iconv_t iconv_open (const char * to_code, const char * from_code)
return (iconv_t)-1;
}

/*
字符编码转换
@function cd:iconv(inbuf)
@string inbuf$输入字符串$例如:ucs2s
@return number$result$返回编码转换后的结果$0成功,-1失败
@usage
--unicode大端编码 转化为 utf8编码
function ucs2beToUtf8(ucs2s)
local cd = iconv.open("utf8", "ucs2be")
return cd:iconv(ucs2s)
end
*/

size_t iconv_convert (iconv_t __cd, char ** __inbuf, size_t * __inbytesleft, char ** __outbuf, size_t * __outbytesleft)
{
builtin_iconv_map *_map_cd = (builtin_iconv_map *)__cd;
Expand All @@ -95,16 +57,7 @@ size_t iconv_convert (iconv_t __cd, char ** __inbuf, size_t * __inbytesleft, cha
return _map_cd->fct(__inbuf, __inbytesleft, __outbuf, __outbytesleft);
}

/*
关闭字符编码转换
@function iconv.close(cd)
@string cd$iconv.open返回的句柄$
@return
@usage
--关闭字符编码转换
local cd = iconv.open("utf8", "ucs2be")
iconv.close(cd)
*/

int iconv_close (iconv_t cd)
{
return 0;
Expand Down
18 changes: 14 additions & 4 deletions components/iconv/luat_lib_iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static iconv_t get_iconv_t(lua_State *L, int i) {
@return userdata 编码转换函数的转换句柄,若不存在会返回nil
@usage
--unicode大端编码 转化为 utf8编码
local iconv = iconv.open("utf8", "ucs2be")
local ic = iconv.open("utf8", "ucs2be")
*/
static int Liconv_open(lua_State *L) {
const char *tocode = luaL_checkstring(L, 1);
Expand All @@ -114,14 +114,14 @@ static int Liconv_open(lua_State *L) {

/*
字符编码转换
@api iconv:iconv(inbuf)
@api ic:iconv(inbuf)
@string 释义:待转换字符串
@return number 释义:返回编码转换后的结果<br>取值:0成功,-1失败
@usage
--unicode大端编码 转化为 utf8编码
function ucs2beToUtf8(ucs2s)
local iconv = iconv.open("utf8", "ucs2be")
return iconv:iconv(ucs2s)
local ic = iconv.open("utf8", "ucs2be")
return ic:iconv(ucs2s)
end
*/
static int Liconv(lua_State *L) {
Expand Down Expand Up @@ -193,6 +193,16 @@ static int Liconvlist(lua_State *L) {

#endif

/*
关闭字符编码转换
@api iconv.close(cd)
@userdata iconv.open返回的句柄
@return bool 成功返回true,否则返回false
@usage
--关闭字符编码转换
local cd = iconv.open("utf8", "ucs2be")
iconv.close(cd)
*/
static int Liconv_close(lua_State *L) {
iconv_t cd = get_iconv_t(L, 1);
if (iconv_close(cd) == 0)
Expand Down

0 comments on commit f992dbe

Please sign in to comment.