当前位置:网站首页>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 synergy
- Unity parallax infinite scrolling background
- China as resin Market Research and investment forecast report (2022 Edition)
- Common technologies of unity
- [groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
- 中国金刚烷行业研究与投资预测报告(2022版)
- SQLServer 存储过程传递数组参数
- Establish cloth effect in 10 seconds
- Leetcode word search (backtracking method)
- 3dsmax2018 common operations and some shortcut keys of editable polygons
猜你喜欢

Thinking of 2022 American College Students' mathematical modeling competition
![[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)

Redis 排查大 key 的4种方法,优化必备

AutoCAD - feature matching

用 Jmeter 工具做个小型压力测试

AutoCAD -- dimension break

Number theoretic function and its summation to be updated

54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●

AutoCAD - workspace settings

Minor spanning tree
随机推荐
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
Panel panel of UI
The difference between heap and stack
LeetCode之单词搜索(回溯法求解)
How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
Leetcode word search (backtracking method)
AutoCAD - feature matching
Inline built-in function
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
Manually implement heap sorting -838 Heap sort
Unity3d learning notes
Common technologies of unity
3dsmax2018 common operations and some shortcut keys of editable polygons
China as resin Market Research and investment forecast report (2022 Edition)
猿人学第一题
Function template
How to choose a panoramic camera that suits you?
【acwing】836. Merge sets
Database under unity
Personal required code