标签:cocos2dx android iconv libiconv win32
#include "iconv.h" bool iconv_convert(void *src, unsigned int src_len,char *src_charset, void *dest, unsigned int dest_len, char *dest_charset) { const char *in; char *out,*dest_ptr; size_t in_left,out_left,mutant,converted; in_left=src_len; out_left=dest_len; in=(char *)src; out=dest_ptr=(char *)dest; iconv_t oConv=iconv_open(dest_charset,src_charset); if(oConv==(iconv_t)(-1)) { CCLog("ERROR: unable to open libiconv."); return false; } mutant = iconv(oConv, &in, &in_left, &out, &out_left ); iconv_close(oConv); if(mutant == (size_t)(-1)) { CCLog("ERROR: unable to convert anything."); return false; } converted = dest_len - out_left; CCLog("to convert %u characters, %u mutanted , %u converted \n",src_len,mutant,converted); dest_ptr[converted]='\0'; return true; }
void convertTest() { char inStr[] = "Hello, 这是个测试程序"; char outStr[1024]; iconv_convert(&inStr, sizeof(inStr), "GBK", &outStr, sizeof(outStr), "UTF-8"); CCLog("scr string:%s\n", inStr); CCLog("dst string:%s\n", outStr); }
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 #include "iconv.h" #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS #include <iconv.h> #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #include "icov/iconv.h" #endif
./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
切记此处不是./configure,不然到后面会报一大堆stdio.h里面的错。
make
make clean
将libiconv放置在cocos2d-x-2.1.4根目录下
在libiconv目录下新建一个Android.mk文件,内容如下:
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := iconv_static LOCAL_MODULE_FILENAME := libiconv LOCAL_CFLAGS := -Wno-multichar -DAndroid -DLIBDIR="c" -DBUILDING_LIBICONV -DIN_LIBRARY LOCAL_SRC_FILES := libcharset/lib/localcharset.c lib/iconv.c lib/relocatable.c LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/libcharset $(LOCAL_PATH)/lib $(LOCAL_PATH)/libcharset/include $(LOCAL_PATH)/srclib include $(BUILD_STATIC_LIBRARY)
cocos2dx中使用iconv转码(win32,iOS,Android)
标签:cocos2dx android iconv libiconv win32
原文地址:http://blog.csdn.net/xufeng0991/article/details/41015781