当前位置:网站首页>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;
}
边栏推荐
- xss注入
- Function template
- 【acwing】836. Merge sets
- 2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
- 中国艾草行业研究与投资前景预测报告(2022版)
- C4D simple cloth (version above R21)
- Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
- UE 虚幻引擎,项目结构
- PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
- 質量體系建設之路的分分合合
猜你喜欢

【acwing】528. cheese
![[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)](/img/1b/1fa2ebc9a6c5d271c9b39f5e508fb0.jpg)
[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)

Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation

Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9

3dsmax scanning function point connection drawing connection line

Special information | real estate and office buildings - 22.1.9

Establish cloth effect in 10 seconds
![[groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)](/img/92/937122b059b6f3a91ae0e0858685e7.jpg)
[groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)

Use assimp library to read MTL file data

数论函数及其求和 待更新
随机推荐
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
MD5 bypass
Basic knowledge points of dictionary
中国艾草行业研究与投资前景预测报告(2022版)
Redis 排查大 key 的4种方法,优化必备
Solutions and answers for the 2021 Shenzhen cup
Unity parallax infinite scrolling background
Séparation et combinaison de la construction du système qualité
Use assimp library to read MTL file data
C4D simple cloth (version above R21)
Number theoretic function and its summation to be updated
数论函数及其求和 待更新
Thinking of 2022 American College Students' mathematical modeling competition
stm32Cubemx(8):RTC和RTC唤醒中断
中国聚氨酯硬泡市场调研与投资预测报告(2022版)
[groovy] closure (Introduction to closure class closure | this, owner, delegate member assignment and source code analysis)
Common database statements in unity
Special information | real estate and office buildings - 22.1.9
AutoCAD - Zoom previous
2020-10-27