libiconv for android

景阳平
2023-12-01

环境配置:

./configure --host=arm-eabi

 

Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := iconv_static
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 \

include $(BUILD_STATIC_LIBRARY)

 

#include <string>
#include "../../../cocos2dx/platform/CCPlatformConfig.h"

#if(CC_TARGET_PLATFORM != CC_PLATFORM_IOS)

#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "iconv/iconv.h"
#pragma comment(lib,"libiconv.lib")
#else
#include "../../../external/iconv/include/iconv.h"
#endif

int convert(const char *from_charset, const char *to_charset, const char *inbuf,
		size_t inlen, char *outbuf, size_t outlen) {
	iconv_t iconvH;
	iconvH = iconv_open(to_charset, from_charset);
	if (!iconvH)
		return false;
	memset(outbuf, 0, outlen);

#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	const char *temp = inbuf;
	const char **pin = &temp;
	char **pout = &outbuf;
	if(!iconv(iconvH, pin, &inlen, pout, &outlen))
	{
		iconv_close(iconvH);
		return false;
	}
#else
	if (!iconv(iconvH, const_cast<char**>(&inbuf), &inlen, &outbuf, &outlen)) {
		iconv_close(iconvH);
		return false;
	}
#endif
	iconv_close(iconvH);
	return true;
}

#endif

int gbk2utf8(const char *inbuf, size_t inlen, char *outbuf, size_t outlen) {

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	strcpy(outbuf,inbuf);
	return true;
#else
	return convert("gb2312", "utf-8", inbuf, inlen, outbuf, outlen);
#endif

}

 

 类似资料:

相关阅读

相关文章

相关问答