当前位置:网站首页>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;
}
边栏推荐
- UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
- [Business Research Report] Research Report on male consumption trends in other economic times -- with download link
- [groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
- 中国聚氨酯硬泡市场调研与投资预测报告(2022版)
- Create a pyGame window with a blue background
- On-off and on-off of quality system construction
- China polyurethane rigid foam Market Research and investment forecast report (2022 Edition)
- Thinking of 2022 American College Students' mathematical modeling competition
- AutoCAD - feature matching
- Difference between singleton and factory pattern
猜你喜欢

AutoCAD - workspace settings

Introduce Hamming distance and calculation examples

Recherche de mots pour leetcode (solution rétrospective)

Autocad-- Real Time zoom

Create a pyGame window with a blue background

【acwing】836. Merge sets
![Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]](/img/e7/f699ee982ea325b8d04f8bd467a559.jpg)
Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]

On-off and on-off of quality system construction

Manually implement heap sorting -838 Heap sort

Establish cloth effect in 10 seconds
随机推荐
Interface joint commissioning test script optimization V5.0 (end)
3dsmax common commands
AutoCAD - set layer
AutoCAD - feature matching
SQL set operation
[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
中国AS树脂市场调研与投资预测报告(2022版)
AutoCAD - command repetition, undo and redo
Error statuslogger log4j2 could not find a logging implementation
Unity writes timetables (without UI)
AutoCAD - graphic input and output
AutoCAD - lengthening
An article takes you to thoroughly understand descriptors
Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
[ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
Sixth note
MD5绕过
669. Prune binary search tree ●●
AutoCAD - Zoom previous
AutoCAD - stretching