/*
Wraps the iconv API present on most systems, which allows for conversion
of bytes from one encoding to another. This package additionally provides
some convenient interface implementations like a Reader and Writer.
*/
package iconv
/*
#include <errno.h>
*/
import "C"
import "os"
// Alias os.Error for convenience
type Error os.Error
// Error codes returned from iconv functions
var (
E2BIG Error = os.Errno(int(C.E2BIG))
EBADF Error = os.Errno(int(C.EBADF))
EINVAL Error = os.Errno(int(C.EINVAL))
EILSEQ Error = os.Errno(int(C.EILSEQ))
ENOMEM Error = os.Errno(int(C.ENOMEM))
)
// All in one Convert method, rather than requiring the construction of an iconv.Converter
func Convert(input []byte, output []byte, fromEncoding string, toEncoding string) (bytesRead int, bytesWritten int, err Error) {
// create a temporary converter
converter, err := NewConverter(fromEncoding, toEncoding)
if err == nil {
// call converter's Convert
bytesRead, bytesWritten, err = converter.Convert(input, output)
if err == nil {
var shiftBytesWritten int
// call Convert with a nil input to generate any end shift sequences
_, shiftBytesWritten, err = converter.Convert(nil, output[bytesWritten:])
// add shift bytes to total bytes
bytesWritten += shiftBytesWritten
}
// close the converter
converter.Close()
}
return
}
// All in one ConvertString method, rather than requiring the construction of an iconv.Converter
func ConvertString(input string, fromEncoding string, toEncoding string) (output string, err Error) {
// create a temporary converter
converter, err := NewConverter(fromEncoding, toEncoding)
if err == nil {
// convert the string
output, err = converter.ConvertString(input)
// close the converter
converter.Close()
}
return
}
分享到:
相关推荐
在Linux下有个iconv.h头文件,里面是对编码转换处理的封装。但在windows下是没有这个头文件的。这里有三个文件,高手编写,用在windows下:iconv.h,iconv.dll和iconv.lib,导出库,就可以用iconv.h了。用法与Linux下...
iconv.h iconv.lib charset.lib 编译时缺少文件时可以用
iconv库32位版和64位版都含有,其中包含编译好的: charset.lib、iconv.lib、iconv.dll、charset.dll、iconv.exe 以及头文件:iconv.h、libcharset.h、localcharset.h 还有说明:iconv.1.html、iconv.3.html 等资源
iconv.
我在做一个加密芯片项目...1.如要iconv_open、iconv_close这样的名字,需在iconv.h中加入#define LIBICONV_PLUG即可。 2.如要libiconv_open、libiconv_close这样的名字,需在iconv.h中移除#define LIBICONV_PLUG即可。
win_iconv - 编码转换工具,下载后解压,复制iconv.exe到C:\Windows\System32,即可使用。
windows下修改文件编码工具,可批量处理 C:\Users\test>iconv -help Usage: iconv [-c] [-s] [-f fromcode] [-t tocode] [file ...] or: iconv -l
批处理文件转码包iconv.exe
iconv是知名的开源跨平台编码转换库,iconv.exe是iconv库在windows下的命令行工具,iconv.exe的一般用法:iconv.exe -f gbk -t utf-8 gbk.txt > utf-8.txt。其中 -f gbk 指明转换前的文件编码是gbk,-t utf-8 指明...
iconv.dll 及其 lua 测试文件,在目录中运行 lua test.lua 启动测试
iconv.dll 的 lua 测试文件,建议解压文件夹到 dll 所在目录,在测试目录中运行 lua test.lua
用于编码格式转换作用,可用于windows支持。
windows下可使用的iconv静态库,只需引入iconv.h,iconv.lib即可,使用方法见示例文件。
内含luaDll,luacom以及luaiconv源码。luaDll和luaiconv直接打开sln在Visual studio中即可进行编译。luacom可使用nmake进行编译。也可直接使用已经生成了的dll.
extern size_t iconv (iconv_t cd, @ICONV_CONST@ char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft); /* Frees resources allocated for conversion descriptor ‘cd’. */ #ifndef ...
iconv是文件编码格式转换工具。 提供的iconv.exe是iconv的Windows版。
iconv 库,用于配置libxml2,找了很久,分享给大家
iconv-lite - 纯javascript转换字符编码
iconv.dll 修复