summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-02-13 10:26:01 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-02-13 19:00:17 +0000
commitf0b65545313f065790de7f91c02e5dd160753abd (patch)
tree747c55722c6b45a979d5c2894a259396a3189ed7 /xfa/fxfa/parser
parent5fb0ad8adac5fcbf8c8f1965164f41d11c0af669 (diff)
downloadpdfium-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>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cscript_eventpseudomodel.cpp2
-rw-r--r--xfa/fxfa/parser/cscript_hostpseudomodel.cpp13
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp88
-rw-r--r--xfa/fxfa/parser/cxfa_object.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp8
5 files changed, 46 insertions, 72 deletions
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 =