当前位置:网站首页>Lua GBK and UTF8 turn to each other
Lua GBK and UTF8 turn to each other
2022-07-05 04:56:00 【Meteor spot】
function Helper.utf8ToGBK(str)
if true then
return str
end
if device.platform == "android" then
return AppUtils:utf8ToGBK(str)
else
local convertStr = str
local togbk = iconv.new("GB2312", "UTF-8")
if togbk then
convertStr = togbk:iconv(str)
end
return convertStr
end
end
function Helper.gbkToUTF8(str)
if true then
return str
end
local convertStr = str
local toutf8 = iconv.new("UTF-8", "GB2312")
if toutf8 then
convertStr = toutf8:iconv(str)
end
return convertStr
end
string AppUtils::gbkToUTF8(const string& str)
{
string convertStr = str;
JniMethodInfo t;
if (JniHelper::getMethodInfo(t, "java/lang/String", "getBytes", "(Ljava/lang/String;)[B")) {
jstring jstr = t.env->NewStringUTF(str.c_str());
jstring jcode = t.env->NewStringUTF("UTF-8");
jbyteArray jarr = (jbyteArray)t.env->CallObjectMethod(jstr, t.methodID, jcode);
jsize len = t.env->GetArrayLength(jarr);
jbyte* pByte = t.env->GetByteArrayElements(jarr, JNI_FALSE);
char * pBuffer = new char[len + 1];
memcpy(pBuffer, pByte, len);
pBuffer[len] = 0;
convertStr = string(pBuffer);
delete[] pBuffer;
t.env->DeleteLocalRef(jstr);
t.env->DeleteLocalRef(jcode);
t.env->DeleteLocalRef(t.classID);
}
return convertStr;
}
string AppUtils::utf8ToGBK(const string& str)
{
string convertStr = str;
JniMethodInfo t;
if (JniHelper::getMethodInfo(t, "java/lang/String", "getBytes", "(Ljava/lang/String;)[B")) {
jstring jstr = t.env->NewStringUTF(str.c_str());
jstring jcode = t.env->NewStringUTF("GB2312");
jbyteArray jarr = (jbyteArray)t.env->CallObjectMethod(jstr, t.methodID, jcode);
jsize len = t.env->GetArrayLength(jarr);
jbyte* pByte = t.env->GetByteArrayElements(jarr, JNI_FALSE);
char * pBuffer = new char[len + 1];
memcpy(pBuffer, pByte, len);
pBuffer[len] = 0;
convertStr = string(pBuffer);
delete[] pBuffer;
t.env->DeleteLocalRef(jstr);
t.env->DeleteLocalRef(jcode);
t.env->DeleteLocalRef(t.classID);
}
return convertStr;
}
边栏推荐
- Unity and database
- 【acwing】836. Merge sets
- [groovy] closure (closure as function parameter | code example)
- Create a pyGame window with a blue background
- 質量體系建設之路的分分合合
- The first topic of ape Anthropology
- 2021-10-29
- AutoCAD - full screen display
- [groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
- Interface joint commissioning test script optimization V5.0 (end)
猜你喜欢
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
[groovy] closure (closure as function parameter | code example)
django连接数据库报错,这是什么原因
Recherche de mots pour leetcode (solution rétrospective)
AutoCAD - set layer
Autocad-- dynamic zoom
Wan broadband access technology V EPON Technology
Number theoretic function and its summation to be updated
Solution of circular dependency
【acwing】836. Merge sets
随机推荐
2022/7/2做题总结
Detailed explanation of the ranking of the best universities
Special information | finance, accounting, audit - 22.1.23
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
3dsmax common commands
数论函数及其求和 待更新
jmeter -- 分布式压测
AutoCAD - Document Management
[groovy] closure (closure call | closure default parameter it | code example)
中国艾草行业研究与投资前景预测报告(2022版)
Research and investment forecast report of adamantane industry in China (2022 Edition)
Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
2021 electrician cup (the 12th "China Society of electrical engineering Cup" National Undergraduate electrician mathematical modeling) detailed ideas + codes + references
2021 electrician cup idea + code - photovoltaic building integration plate index development trend analysis and prediction: prediction planning issues
Variable category (automatic, static, register, external)
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
#775 Div.1 B. Integral Array 数学
Unity3d learning notes
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis