当前位置:网站首页>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;
}
边栏推荐
- Use assimp library to read MTL file data
- 3dsmax snaps to frozen objects
- Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
- [groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)
- 2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
- Difference between singleton and factory pattern
- The difference between bundle, chunk and module
- stm32Cubemx(8):RTC和RTC唤醒中断
- Interface joint commissioning test script optimization V5.0 (end)
- Emlog blog theme template source code simple good-looking responsive
猜你喜欢
On-off and on-off of quality system construction
AutoCAD - command repetition, undo and redo
LeetCode之單詞搜索(回溯法求解)
669. Prune binary search tree ●●
Solutions and answers for the 2021 Shenzhen cup
xss注入
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
C4D simple cloth (version above R21)
随机推荐
JVM 原理和流程简介
Download the details and sequence of the original data access from the ENA database in EBI
The difference between heap and stack
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
#775 Div.1 B. Integral Array 数学
Out and ref functions of unity
Unity and database
2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
Flink集群配置
Use assimp library to read MTL file data
MD5绕过
Autocad-- Real Time zoom
【acwing】528. cheese
2022/7/1学习总结
AutoCAD - full screen display
Unity get component
Inline built-in function
GameObject class and transform class of unity
中国针状焦行业发展研究与投资价值报告(2022版)