diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-02-13 10:26:01 -0800 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-13 19:00:17 +0000 |
commit | f0b65545313f065790de7f91c02e5dd160753abd (patch) | |
tree | 747c55722c6b45a979d5c2894a259396a3189ed7 | |
parent | 5fb0ad8adac5fcbf8c8f1965164f41d11c0af669 (diff) | |
download | pdfium-f0b65545313f065790de7f91c02e5dd160753abd.tar.xz |
Simplify FX_UTF8Encode variants.chromium/3012
Doing so reveals places where there are needless copies
and conversions.
Change-Id: I24a868d40aa63836f4167eaf4541964049df7916
Reviewed-on: https://pdfium-review.googlesource.com/2555
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | core/fxcrt/fx_basic_utf.cpp | 8 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_wstring.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fx_string.h | 11 | ||||
-rw-r--r-- | core/fxcrt/fx_xml_parser.cpp | 2 | ||||
-rw-r--r-- | fxjs/fxjs_v8.cpp | 12 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 73 | ||||
-rw-r--r-- | xfa/fxfa/parser/cscript_eventpseudomodel.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cscript_hostpseudomodel.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 88 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_object.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptcontext.cpp | 8 |
12 files changed, 87 insertions, 145 deletions
diff --git a/core/fxcrt/fx_basic_utf.cpp b/core/fxcrt/fx_basic_utf.cpp index 8dbbb28877..c0f14c8178 100644 --- a/core/fxcrt/fx_basic_utf.cpp +++ b/core/fxcrt/fx_basic_utf.cpp @@ -73,13 +73,13 @@ void CFX_UTF8Encoder::Input(FX_WCHAR unicode) { } } } -CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len) { - if (len < 0) - len = FXSYS_wcslen(pwsStr); +CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { + FX_STRSIZE len = wsStr.GetLength(); + const FX_WCHAR* pStr = wsStr.c_str(); CFX_UTF8Encoder encoder; while (len-- > 0) - encoder.Input(*pwsStr++); + encoder.Input(*pStr++); return CFX_ByteString(encoder.GetResult()); } diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index e779621e60..93b9ba7c25 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -343,12 +343,10 @@ void CFX_WideString::Concat(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen) { m_pData.Swap(pNewData); } -// static CFX_ByteString CFX_WideString::UTF8Encode() const { - return FX_UTF8Encode(*this); + return FX_UTF8Encode(AsStringC()); } -// static CFX_ByteString CFX_WideString::UTF16LE_Encode() const { if (!m_pData) { return CFX_ByteString("\0\0", 2); diff --git a/core/fxcrt/fx_string.h b/core/fxcrt/fx_string.h index 750216fd3e..cd93f27275 100644 --- a/core/fxcrt/fx_string.h +++ b/core/fxcrt/fx_string.h @@ -424,17 +424,10 @@ inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { return rhs != lhs; } -CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); -inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { - return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); -} -inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { - return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); -} - +CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr); FX_FLOAT FX_atof(const CFX_ByteStringC& str); inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { - return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); + return FX_atof(FX_UTF8Encode(wsStr).c_str()); } bool FX_atonum(const CFX_ByteStringC& str, void* pData); FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp index 1b562c2083..7658620424 100644 --- a/core/fxcrt/fx_xml_parser.cpp +++ b/core/fxcrt/fx_xml_parser.cpp @@ -773,7 +773,7 @@ CFX_ByteString CXML_Element::GetNamespaceURI( } pElement = pElement->GetParent(); } while (pElement); - return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString(); + return pwsSpace ? pwsSpace->UTF8Encode() : CFX_ByteString(); } void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index c96cc1f0e0..667d63be02 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -274,7 +274,7 @@ void CFXJS_Engine::DefineObjMethod(int nObjDefnID, v8::FunctionCallback pMethodCall) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode(); + CFX_ByteString bsMethodName = FX_UTF8Encode(CFX_WideStringC(sMethodName)); CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID); v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( @@ -293,7 +293,7 @@ void CFXJS_Engine::DefineObjProperty(int nObjDefnID, v8::AccessorSetterCallback pPropPut) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsPropertyName = CFX_WideString(sPropName).UTF8Encode(); + CFX_ByteString bsPropertyName = FX_UTF8Encode(CFX_WideStringC(sPropName)); CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID); pObjDef->GetInstanceTemplate()->SetAccessor( @@ -322,7 +322,7 @@ void CFXJS_Engine::DefineObjConst(int nObjDefnID, v8::Local<v8::Value> pDefault) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsConstName = CFX_WideString(sConstName).UTF8Encode(); + CFX_ByteString bsConstName = FX_UTF8Encode(CFX_WideStringC(sConstName)); CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID); pObjDef->GetInstanceTemplate()->Set(m_isolate, bsConstName.c_str(), pDefault); @@ -332,7 +332,7 @@ void CFXJS_Engine::DefineGlobalMethod(const wchar_t* sMethodName, v8::FunctionCallback pMethodCall) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode(); + CFX_ByteString bsMethodName = FX_UTF8Encode(CFX_WideStringC(sMethodName)); v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(m_isolate, pMethodCall); fun->RemovePrototype(); @@ -347,7 +347,7 @@ void CFXJS_Engine::DefineGlobalConst(const wchar_t* sConstName, v8::FunctionCallback pConstGetter) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); + CFX_ByteString bsConst = FX_UTF8Encode(CFX_WideStringC(sConstName)); v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(m_isolate, pConstGetter); fun->RemovePrototype(); @@ -392,7 +392,7 @@ void CFXJS_Engine::InitializeEngine() { ->ToObject(v8Context) .ToLocalChecked()); } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { - CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode(); + CFX_ByteString bs = FX_UTF8Encode(CFX_WideStringC(pObjDef->m_ObjName)); v8::Local<v8::String> m_ObjName = v8::String::NewFromUtf8(m_isolate, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()) diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index add66899a7..bf243a49c6 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -629,7 +629,7 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage( const FX_WCHAR* pszFontFamily) { CFX_ByteString bsHash; bsHash.Format("%d, %d", wCodePage, dwFontStyles); - bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); + bsHash += FX_UTF8Encode(CFX_WideStringC(pszFontFamily)); uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFontArray = &m_Hash2Fonts[dwHash]; if (!pFontArray->empty()) @@ -673,7 +673,7 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); else bsHash.Format("%d, %d", wCodePage, dwFontStyles); - bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); + bsHash += FX_UTF8Encode(CFX_WideStringC(pszFontFamily)); uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFonts = &m_Hash2Fonts[dwHash]; for (size_t i = 0; i < pFonts->size(); ++i) { diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index ba65beffc4..e8cb2d0279 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -2026,7 +2026,7 @@ bool CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, CFX_WideString wsRet; widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display); - strLocalDate = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); + strLocalDate = wsRet.UTF8Encode(); return true; } @@ -2065,7 +2065,7 @@ bool CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, CFX_WideString wsRet; widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display); - strLocalTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); + strLocalTime = wsRet.UTF8Encode(); return true; } @@ -2104,7 +2104,7 @@ bool CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, CFX_WideString wsRet; widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display); - strGMTTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); + strGMTTime = wsRet.UTF8Encode(); return true; } @@ -2213,7 +2213,7 @@ void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis, pLocale->GetDateTimeSymbols(wsSymbols); AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); } - strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); + strFormat = strRet.UTF8Encode(); } // static @@ -2264,7 +2264,7 @@ void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis, pLocale->GetDateTimeSymbols(wsSymbols); AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); } - strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); + strFormat = strRet.UTF8Encode(); } // static @@ -2959,10 +2959,8 @@ void CXFA_FM2JSContext::Eval(CFXJSE_Value* pThis, CFXJSE_Context::Create(pIsolate, nullptr, nullptr)); auto returnValue = pdfium::MakeUnique<CFXJSE_Value>(pIsolate); - CFX_WideString javaScript(wsJavaScriptBuf.AsStringC()); - pNewContext->ExecuteScript( - FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), - returnValue.get()); + pNewContext->ExecuteScript(FX_UTF8Encode(wsJavaScriptBuf.AsStringC()).c_str(), + returnValue.get()); args.GetReturnValue()->Assign(returnValue.get()); } @@ -3428,11 +3426,8 @@ void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, ++i; } wsResultBuf.AppendChar(0); - szResultString.Clear(); - szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), - wsResultBuf.GetLength()) - .AsStringC(); + szResultString << FX_UTF8Encode(wsResultBuf.AsStringC()); } // static @@ -3508,9 +3503,7 @@ void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, wsResultBuf.AppendChar(0); szResultString.Clear(); - szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), - wsResultBuf.GetLength()) - .AsStringC(); + szResultString << FX_UTF8Encode(wsResultBuf.AsStringC()); } // static @@ -3610,10 +3603,8 @@ void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, iCode = 0; } wsXMLBuf.AppendChar(0); - szResultString.Clear(); - szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) - .AsStringC(); + szResultString << FX_UTF8Encode(wsXMLBuf.AsStringC()); } // static @@ -3761,9 +3752,7 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, } wsResultBuf.AppendChar(0); szResultBuf.Clear(); - - szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) - .AsStringC(); + szResultBuf << FX_UTF8Encode(wsResultBuf.AsStringC()); } // static @@ -3813,9 +3802,7 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, } wsResultBuf.AppendChar(0); szResultBuf.Clear(); - - szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) - .AsStringC(); + szResultBuf << FX_UTF8Encode(wsResultBuf.AsStringC()); } // static @@ -3886,9 +3873,7 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, } wsResultBuf.AppendChar(0); szResultBuf.Clear(); - - szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) - .AsStringC(); + szResultBuf << FX_UTF8Encode(wsResultBuf.AsStringC()); } // static @@ -4009,8 +3994,7 @@ void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis, return; } - args.GetReturnValue()->SetString( - FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()).AsStringC()); + args.GetReturnValue()->SetString(wsRet.UTF8Encode().AsStringC()); } // static @@ -4091,8 +4075,7 @@ void CXFA_FM2JSContext::Lower(CFXJSE_Value* pThis, lowStringBuf.AppendChar(0); args.GetReturnValue()->SetString( - FX_UTF8Encode(lowStringBuf.GetBuffer(), lowStringBuf.GetLength()) - .AsStringC()); + FX_UTF8Encode(lowStringBuf.AsStringC()).AsStringC()); } // static @@ -4156,7 +4139,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue.GetValue()).AsStringC()); + localeValue.GetValue().UTF8Encode().AsStringC()); return; } @@ -4173,7 +4156,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue.GetValue()).AsStringC()); + localeValue.GetValue().UTF8Encode().AsStringC()); return; } case XFA_VT_DATE: { @@ -4185,7 +4168,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue.GetValue()).AsStringC()); + localeValue.GetValue().UTF8Encode().AsStringC()); return; } case XFA_VT_TIME: { @@ -4197,7 +4180,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue.GetValue()).AsStringC()); + localeValue.GetValue().UTF8Encode().AsStringC()); return; } case XFA_VT_TEXT: { @@ -4209,7 +4192,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue.GetValue()).AsStringC()); + localeValue.GetValue().UTF8Encode().AsStringC()); return; } case XFA_VT_FLOAT: { @@ -4241,7 +4224,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } args.GetReturnValue()->SetString( - FX_UTF8Encode(localeValue2.GetValue()).AsStringC()); + localeValue2.GetValue().UTF8Encode().AsStringC()); return; } } @@ -4640,8 +4623,7 @@ void CXFA_FM2JSContext::Upper(CFXJSE_Value* pThis, upperStringBuf.AppendChar(0); args.GetReturnValue()->SetString( - FX_UTF8Encode(upperStringBuf.GetBuffer(), upperStringBuf.GetLength()) - .AsStringC()); + FX_UTF8Encode(upperStringBuf.AsStringC()).AsStringC()); } // static @@ -4931,10 +4913,7 @@ void CXFA_FM2JSContext::Post(CFXJSE_Value* pThis, pContext->ThrowServerDeniedException(); return; } - - args.GetReturnValue()->SetString( - FX_UTF8Encode(decodedResponse.c_str(), decodedResponse.GetLength()) - .AsStringC()); + args.GetReturnValue()->SetString(decodedResponse.UTF8Encode().AsStringC()); } // static @@ -5680,9 +5659,8 @@ void CXFA_FM2JSContext::eval_translation(CFXJSE_Value* pThis, return; } - CFX_WideString javaScript = wsJavaScriptBuf.MakeString(); args.GetReturnValue()->SetString( - FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).AsStringC()); + FX_UTF8Encode(wsJavaScriptBuf.AsStringC()).AsStringC()); } // static @@ -6439,6 +6417,5 @@ void CXFA_FM2JSContext::ThrowException(const FX_WCHAR* str, ...) const { va_start(arg_ptr, str); wsMessage.FormatV(str, arg_ptr); va_end(arg_ptr); - FXJSE_ThrowMessage( - FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); + FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); } diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp index 8a7d80b5d3..8cfedd2998 100644 --- a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -25,7 +25,7 @@ void StringProperty(CFXJSE_Value* pValue, wsValue = pValue->ToWideString(); return; } - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, bool bSetting) { diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index eb8177ebf6..a06e02f56d 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -89,7 +89,7 @@ void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, return; } pValue->SetString( - FX_UTF8Encode(pNotify->GetAppProvider()->GetLanguage()).AsStringC()); + pNotify->GetAppProvider()->GetLanguage().UTF8Encode().AsStringC()); } void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, @@ -118,8 +118,9 @@ void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, return; } pValue->SetString( - FX_UTF8Encode(pNotify->GetAppProvider()->GetPlatform()).AsStringC()); + pNotify->GetAppProvider()->GetPlatform().UTF8Encode().AsStringC()); } + void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { @@ -137,7 +138,7 @@ void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, } CFX_WideString wsTitle; pNotify->GetDocEnvironment()->GetTitle(hDoc, wsTitle); - pValue->SetString(FX_UTF8Encode(wsTitle).AsStringC()); + pValue->SetString(wsTitle.UTF8Encode().AsStringC()); } void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue, @@ -199,7 +200,7 @@ void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, return; } pValue->SetString( - FX_UTF8Encode(pNotify->GetAppProvider()->GetAppName()).AsStringC()); + pNotify->GetAppProvider()->GetAppName().UTF8Encode().AsStringC()); } void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) { @@ -306,7 +307,7 @@ void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { wsQuestion, wsTitle, wsDefaultAnswer, bMark); CFXJSE_Value* pValue = pArguments->GetReturnValue(); if (pValue) - pValue->SetString(FX_UTF8Encode(wsAnswer).AsStringC()); + pValue->SetString(wsAnswer.UTF8Encode().AsStringC()); } void CScript_HostPseudoModel::DocumentInBatch(CFXJSE_Arguments* pArguments) { @@ -674,7 +675,7 @@ void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); CFXJSE_Value* pValue = pArguments->GetReturnValue(); if (pValue) - pValue->SetString(FX_UTF8Encode(wsDataTime).AsStringC()); + pValue->SetString(wsDataTime.UTF8Encode().AsStringC()); } void CScript_HostPseudoModel::ThrowSetLanguageException() const { diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 0fc114be10..1e508969d1 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1109,8 +1109,7 @@ void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, return; if (bSetting) { CFX_WideString wsMessage = L"Unable to set "; - FXJSE_ThrowMessage( - FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); + FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); } else { CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); @@ -1124,7 +1123,6 @@ void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]"; Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); @@ -1174,7 +1172,7 @@ void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, } CFX_WideString wsSOMExpression; GetSOMExpression(wsSOMExpression); - pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); + pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC()); } void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { @@ -1238,7 +1236,7 @@ void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { GetAttribute(wsExpression.AsStringC(), wsValue); CFXJSE_Value* pValue = pArguments->GetReturnValue(); if (pValue) - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { @@ -1508,7 +1506,7 @@ void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, CFX_WideString wsNameSpace; TryNamespace(wsNameSpace); - pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); + pValue->SetString(wsNameSpace.UTF8Encode().AsStringC()); } void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, @@ -1858,8 +1856,7 @@ void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, } else { CFX_WideString wsValue; GetAttribute(eAttribute, wsValue); - pValue->SetString( - FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } } @@ -1873,8 +1870,7 @@ void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, CFX_WideString wsValue; GetAttribute(eAttribute, wsValue); - pValue->SetString( - FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { @@ -1952,7 +1948,7 @@ void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, default: break; } - pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC()); + pValue->SetString(wsMessage.UTF8Encode().AsStringC()); } } @@ -2038,8 +2034,7 @@ void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, CFX_Decimal decimal(content.AsStringC()); pValue->SetFloat((FX_FLOAT)(double)decimal); } else { - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); + pValue->SetString(content.UTF8Encode().AsStringC()); } } } @@ -2057,8 +2052,7 @@ void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, pValue->SetNull(); return; } - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); + pValue->SetString(content.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, @@ -2109,7 +2103,7 @@ void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, ArgbDecode(color, a, r, g, b); CFX_WideString strColor; strColor.Format(L"%d,%d,%d", r, g, b); - pValue->SetString(FX_UTF8Encode(strColor).AsStringC()); + pValue->SetString(strColor.UTF8Encode().AsStringC()); } } @@ -2134,7 +2128,7 @@ void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, CXFA_Edge edge = border.GetEdge(0); CXFA_Measurement thickness = edge.GetMSThickness(); thickness.ToString(wsThickness); - pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC()); + pValue->SetString(wsThickness.UTF8Encode().AsStringC()); } } @@ -2167,7 +2161,7 @@ void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, ArgbDecode(color, a, r, g, b); CFX_WideString wsColor; wsColor.Format(L"%d,%d,%d", r, g, b); - pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); + pValue->SetString(wsColor.UTF8Encode().AsStringC()); } } @@ -2204,12 +2198,10 @@ void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, } } else { CFX_WideString content = GetScriptContent(true); - if (content.IsEmpty()) { + if (content.IsEmpty()) pValue->SetNull(); - } else { - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); - } + else + pValue->SetString(content.UTF8Encode().AsStringC()); } } @@ -2258,8 +2250,7 @@ void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { if (pUIChild->GetElementType() == XFA_Element::NumericEdit && (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); + pValue->SetString(content.UTF8Encode().AsStringC()); } else { CFX_Decimal decimal(content.AsStringC()); pValue->SetFloat((FX_FLOAT)(double)decimal); @@ -2272,8 +2263,7 @@ void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, CFX_Decimal decimal(content.AsStringC()); pValue->SetFloat((FX_FLOAT)(double)decimal); } else { - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); + pValue->SetString(content.UTF8Encode().AsStringC()); } } } @@ -2291,7 +2281,7 @@ void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, } else { CFX_WideString wsValue; pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } } @@ -2323,7 +2313,7 @@ void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, ArgbDecode(color, a, r, g, b); CFX_WideString wsColor; wsColor.Format(L"%d,%d,%d", r, g, b); - pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); + pValue->SetString(wsColor.UTF8Encode().AsStringC()); } } @@ -2345,7 +2335,7 @@ void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, } else { CFX_WideString wsValue; pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } } @@ -2366,7 +2356,7 @@ void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, CFX_WideString wsValue; if (pInfo) wsValue = pInfo->pName; - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } } @@ -2477,13 +2467,11 @@ void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { return; } CFX_WideString wsValue; - bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true); - if (bHasItem) { - pArguments->GetReturnValue()->SetString( - FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); - } else { + if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) { pArguments->GetReturnValue()->SetNull(); + return; } + pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { @@ -2502,7 +2490,7 @@ void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); CFXJSE_Value* pValue = pArguments->GetReturnValue(); if (pValue) - pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC()); + pValue->SetString(wsBoundValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { @@ -2554,13 +2542,11 @@ void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { return; } CFX_WideString wsValue; - bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false); - if (bHasItem) { - pArguments->GetReturnValue()->SetString( - FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); - } else { + if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) { pArguments->GetReturnValue()->SetNull(); + return; } + pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { @@ -2646,7 +2632,7 @@ void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { pValue->SetNull(); } else { - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); + pValue->SetString(wsValue.UTF8Encode().AsStringC()); } } } @@ -2814,9 +2800,7 @@ void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, } else { CFX_WideString wsLocaleName; GetLocaleName(wsLocaleName); - pValue->SetString( - FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength()) - .AsStringC()); + pValue->SetString(wsLocaleName.UTF8Encode().AsStringC()); } } @@ -3415,11 +3399,9 @@ void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); return; } - CFX_WideString wsChecksum; GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); - pValue->SetString( - FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); + pValue->SetString(wsChecksum.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { @@ -3427,7 +3409,6 @@ void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { ThrowParamCountMismatchException(L"getAttribute"); return; } - CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); CFX_WideString wsAttributeValue; CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); @@ -3437,8 +3418,7 @@ void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { wsAttributeValue); } pArguments->GetReturnValue()->SetString( - FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) - .AsStringC()); + wsAttributeValue.UTF8Encode().AsStringC()); } void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { @@ -3446,7 +3426,6 @@ void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { ThrowParamCountMismatchException(L"setAttribute"); return; } - CFX_ByteString bsValue = pArguments->GetUTF8String(0); CFX_ByteString bsName = pArguments->GetUTF8String(1); CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); @@ -3492,8 +3471,7 @@ void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); pXMLElement->GetTextData(wsTextData); } - pValue->SetString( - FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC()); + pValue->SetString(wsTextData.UTF8Encode().AsStringC()); } } diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index 45e34424aa..c8cd354b48 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp @@ -42,9 +42,7 @@ void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - CFX_WideStringC className = GetClassName(); - pValue->SetString( - FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC()); + pValue->SetString(FX_UTF8Encode(GetClassName()).AsStringC()); } void CXFA_Object::ThrowInvalidPropertyException() const { @@ -71,6 +69,5 @@ void CXFA_Object::ThrowException(const FX_WCHAR* str, ...) const { va_start(arg_ptr, str); wsMessage.FormatV(str, arg_ptr); va_end(arg_ptr); - FXJSE_ThrowMessage( - FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); + FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); } diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp index a54ef99af5..584cd76bed 100644 --- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp +++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -161,10 +161,9 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, hRetValue->SetUndefined(); return false; } - btScript = - FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); + btScript = FX_UTF8Encode(wsJavaScript.AsStringC()); } else { - btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); + btScript = FX_UTF8Encode(wsScript); } CXFA_Object* pOriginalObject = m_pThisObject; m_pThisObject = pThisObject; @@ -491,8 +490,7 @@ bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) return false; - CFX_ByteString btScript = - FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); + CFX_ByteString btScript = FX_UTF8Encode(wsScript); std::unique_ptr<CFXJSE_Value> hRetValue(new CFXJSE_Value(m_pIsolate)); CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); CFXJSE_Context* pVariablesContext = |