当前位置:网站首页>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;
}
边栏推荐
- China as resin Market Research and investment forecast report (2022 Edition)
- PR first time
- 2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
- #775 Div.1 C. Tyler and Strings 组合数学
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- [LeetCode] 整数反转【7】
- UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
- xss注入
- Dotween usage records ----- appendinterval, appendcallback
- stm32Cubemx(8):RTC和RTC唤醒中断
猜你喜欢

Panel panel of UI

2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
![[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)](/img/90/0cf08ae6fea61891e3e1fdf29d310c.jpg)
[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)

669. Prune binary search tree ●●

3dsmax snaps to frozen objects

AutoCAD - command repetition, undo and redo

Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套

How to choose a panoramic camera that suits you?

Emlog博客主题模板源码简约好看响应式

"Measuring curve length" of CAD dream drawing
随机推荐
On-off and on-off of quality system construction
2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis
AutoCAD - lengthening
Is $20billion a little less? Cisco is interested in Splunk?
Sixth note
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
XSS injection
Download the details and sequence of the original data access from the ENA database in EBI
Use assimp library to read MTL file data
Minor spanning tree
次小生成树
[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
jmeter -- 分布式压测
AutoCAD - command repetition, undo and redo
775 Div.1 C. Tyler and strings combinatorial mathematics
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link
GameObject class and transform class of unity
The difference between bundle, chunk and module
AutoCAD - stretching
【acwing】240. food chain