mirror of https://github.com/axmolengine/axmol.git
fix the problem in ccUTF8.cpp and CCLuaJavaBridge.cpp (#16314)
* fix the return value when return null in java fix the return value when return null in java * fix getStringUTFCharsJNI fix getStringUTFCharsJNI when srcjStr is null * remove a word remove a word added by mistake * make a indention line 233 utf8Str
This commit is contained in:
parent
c3130caf27
commit
f9abbf02f6
|
@ -231,21 +231,30 @@ bool UTF32ToUTF16(const std::u32string& utf32, std::u16string& outUtf16)
|
|||
std::string getStringUTFCharsJNI(JNIEnv* env, jstring srcjStr, bool* ret)
|
||||
{
|
||||
std::string utf8Str;
|
||||
const unsigned short * unicodeChar = ( const unsigned short *)env->GetStringChars(srcjStr, nullptr);
|
||||
size_t unicodeCharLength = env->GetStringLength(srcjStr);
|
||||
const std::u16string unicodeStr((const char16_t *)unicodeChar, unicodeCharLength);
|
||||
bool flag = UTF16ToUTF8(unicodeStr, utf8Str);
|
||||
|
||||
if (ret)
|
||||
if(srcjStr != nullptr)
|
||||
{
|
||||
*ret = flag;
|
||||
const unsigned short * unicodeChar = ( const unsigned short *)env->GetStringChars(srcjStr, nullptr);
|
||||
size_t unicodeCharLength = env->GetStringLength(srcjStr);
|
||||
const std::u16string unicodeStr((const char16_t *)unicodeChar, unicodeCharLength);
|
||||
bool flag = UTF16ToUTF8(unicodeStr, utf8Str);
|
||||
if (ret)
|
||||
{
|
||||
*ret = flag;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
utf8Str = "";
|
||||
}
|
||||
env->ReleaseStringChars(srcjStr, unicodeChar);
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
else
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = false;
|
||||
}
|
||||
utf8Str = "";
|
||||
}
|
||||
env->ReleaseStringChars(srcjStr, unicodeChar);
|
||||
return utf8Str;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ bool LuaJavaBridge::CallInfo::execute(void)
|
|||
case TypeString:
|
||||
{
|
||||
m_retjs = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID);
|
||||
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs);
|
||||
m_ret.stringValue = new string(strValue);
|
||||
bool bValidStr = true;
|
||||
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs, &bValidStr);
|
||||
m_ret.stringValue = (false == bValidStr) ? nullptr : new string(strValue);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -87,9 +88,10 @@ bool LuaJavaBridge::CallInfo::executeWithArgs(jvalue *args)
|
|||
|
||||
case TypeString:
|
||||
{
|
||||
m_retjs = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
|
||||
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs);
|
||||
m_ret.stringValue = new string(strValue);
|
||||
m_retjs = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
|
||||
bool bValidStr = true;
|
||||
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs, &bValidStr);
|
||||
m_ret.stringValue = (false == bValidStr) ? nullptr : new string(strValue);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -130,7 +132,11 @@ int LuaJavaBridge::CallInfo::pushReturnValue(lua_State *L)
|
|||
lua_pushboolean(L, m_ret.boolValue);
|
||||
return 1;
|
||||
case TypeString:
|
||||
lua_pushstring(L, m_ret.stringValue->c_str());
|
||||
if(m_ret.stringValue == nullptr){
|
||||
lua_pushnil(L);
|
||||
}else{
|
||||
lua_pushstring(L, m_ret.stringValue->c_str());
|
||||
}
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue