summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-15 10:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:03:10 +0000
commit8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch)
tree82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /xfa/fxfa/parser
parent171cb27a720036c48ae3a6176084e880742af0a9 (diff)
downloadpdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and doesn't offer any additional safety. Folding them into one implementation. SetAt is retained, since implementing the non-const [] operator to replace SetAt has potential performance concerns. Specifically many non-obvious cases of reading an element using [] will cause a realloc & copy. BUG=pdfium:860 Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67 Reviewed-on: https://pdfium-review.googlesource.com/10870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_localemgr.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_measurement.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_nodehelper.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_resolveprocessor.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp4
9 files changed, 21 insertions, 22 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index ff9e981e9f..b502bbdfa7 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -58,7 +58,7 @@ CFX_WideString ExportEncodeContent(const CFX_WideStringC& str) {
CFX_WideTextBuf textBuf;
int32_t iLen = str.GetLength();
for (int32_t i = 0; i < iLen; i++) {
- wchar_t ch = str.GetAt(i);
+ wchar_t ch = str[i];
if (!IsXMLValidChar(ch))
continue;
@@ -73,13 +73,13 @@ CFX_WideString ExportEncodeContent(const CFX_WideStringC& str) {
} else if (ch == '\"') {
textBuf << L"&quot;";
} else if (ch == ' ') {
- if (i && str.GetAt(i - 1) != ' ') {
+ if (i && str[i - 1] != ' ') {
textBuf.AppendChar(' ');
} else {
textBuf << L"&#x20;";
}
} else {
- textBuf.AppendChar(str.GetAt(i));
+ textBuf.AppendChar(str[i]);
}
}
return textBuf.MakeString();
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 55851bb34a..e643bc502f 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -160,7 +160,7 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
return nullptr;
bTargetAllFind = false;
- if (wsExpr.GetAt(0) == '#') {
+ if (wsExpr[0] == '#') {
CXFA_Node* pNode = pDocument->GetNodeByID(
ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Template)),
wsExpr.Right(wsExpr.GetLength() - 1).AsStringC());
diff --git a/xfa/fxfa/parser/cxfa_localemgr.cpp b/xfa/fxfa/parser/cxfa_localemgr.cpp
index 633f4b41fd..833f72c33f 100644
--- a/xfa/fxfa/parser/cxfa_localemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_localemgr.cpp
@@ -1083,10 +1083,9 @@ static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) {
return FX_LANG_en_US;
wsLanguage.MakeLower();
- uint32_t dwIDFirst = wsLanguage.GetAt(0) << 8 | wsLanguage.GetAt(1);
- uint32_t dwIDSecond = wsLanguage.GetLength() >= 5
- ? wsLanguage.GetAt(3) << 8 | wsLanguage.GetAt(4)
- : 0;
+ uint32_t dwIDFirst = wsLanguage[0] << 8 | wsLanguage[1];
+ uint32_t dwIDSecond =
+ wsLanguage.GetLength() >= 5 ? wsLanguage[3] << 8 | wsLanguage[4] : 0;
switch (dwIDFirst) {
case FXBSTR_ID(0, 0, 'z', 'h'):
if (dwIDSecond == FXBSTR_ID(0, 0, 'c', 'n'))
diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp
index 66b715ec38..1c427209f9 100644
--- a/xfa/fxfa/parser/cxfa_measurement.cpp
+++ b/xfa/fxfa/parser/cxfa_measurement.cpp
@@ -37,7 +37,7 @@ void CXFA_Measurement::SetString(const CFX_WideStringC& wsMeasure) {
return;
}
int32_t iUsedLen = 0;
- int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0;
+ int32_t iOffset = (wsMeasure[0] == L'=') ? 1 : 0;
float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str() + iOffset,
wsMeasure.GetLength() - iOffset, &iUsedLen);
XFA_UNIT eUnit = GetUnitFromString(
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 8497e60a74..2b4bdd22c0 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -76,7 +76,7 @@ int32_t GetCount(CXFA_Node* pInstMgrNode) {
if (iCount == 0) {
CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
- if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
+ if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return iCount;
}
@@ -197,7 +197,7 @@ CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
if (iCount == 0) {
CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
- if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
+ if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return nullptr;
}
@@ -406,7 +406,7 @@ void StrToRGB(const CFX_WideString& strRGB,
int32_t iIndex = 0;
int32_t iLen = strRGB.GetLength();
for (int32_t i = 0; i < iLen; ++i) {
- wchar_t ch = strRGB.GetAt(i);
+ wchar_t ch = strRGB[i];
if (ch == L',')
++iIndex;
if (iIndex > 2)
@@ -2736,7 +2736,7 @@ void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
if (pNode->GetElementType() == XFA_Element::InstanceManager) {
CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
- if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
+ if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' &&
wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) {
pInstanceMgr = pNode;
}
@@ -4664,7 +4664,7 @@ CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
if (eType == XFA_Element::InstanceManager) {
CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
- if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
+ if (wsInstName.GetLength() > 0 && wsInstName[0] == '_' &&
wsInstName.Right(wsInstName.GetLength() - 1) == wsName) {
pInstanceMgr = pNode;
}
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp
index 547831caca..4f1ed04fe3 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.cpp
+++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp
@@ -283,7 +283,7 @@ bool CXFA_NodeHelper::CreateNode_ForCondition(CFX_WideString& wsCondition) {
m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne;
return false;
}
- if (wsCondition.GetAt(0) == '[') {
+ if (wsCondition[0] == '[') {
int32_t i = 1;
for (; i < iLen; ++i) {
wchar_t ch = wsCondition[i];
@@ -323,12 +323,12 @@ bool CXFA_NodeHelper::ResolveNodes_CreateNode(
}
bool bIsClassName = false;
bool bResult = false;
- if (wsName.GetAt(0) == '!') {
+ if (wsName[0] == '!') {
wsName = wsName.Right(wsName.GetLength() - 1);
m_pCreateParent = ToNode(
pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets));
}
- if (wsName.GetAt(0) == '#') {
+ if (wsName[0] == '#') {
bIsClassName = true;
wsName = wsName.Right(wsName.GetLength() - 1);
}
diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
index 93b2d86061..9edb3bce81 100644
--- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
@@ -41,7 +41,7 @@ int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) {
if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) {
return ResolveAnyChild(rnd);
}
- wchar_t wch = rnd.m_wsName.GetAt(0);
+ wchar_t wch = rnd.m_wsName[0];
switch (wch) {
case '$':
return ResolveDollar(rnd);
@@ -89,7 +89,7 @@ int32_t CXFA_ResolveProcessor::ResolveAnyChild(CXFA_ResolveNodesData& rnd) {
CFX_WideString wsCondition = rnd.m_wsCondition;
CXFA_Node* findNode = nullptr;
bool bClassName = false;
- if (wsName.GetAt(0) == '#') {
+ if (wsName[0] == '#') {
bClassName = true;
wsName = wsName.Right(wsName.GetLength() - 1);
}
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
index 115cd5651e..57caa9981b 100644
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
@@ -340,7 +340,7 @@ void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue,
pReturnValue, true, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
} else {
if (pObject->IsNode()) {
- if (wsPropName.GetAt(0) == '#') {
+ if (wsPropName[0] == '#') {
wsPropName = wsPropName.Right(wsPropName.GetLength() - 1);
}
CXFA_Node* pNode = ToNode(pObject);
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index d68a907e18..5b9f62c93f 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1215,7 +1215,7 @@ bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(char* val) {
CFX_WideStringC wsStartEndChar;
if (pUIChild->TryCData(XFA_ATTRIBUTE_StartChar, wsStartEndChar)) {
if (wsStartEndChar.GetLength()) {
- *val = static_cast<char>(wsStartEndChar.GetAt(0));
+ *val = static_cast<char>(wsStartEndChar[0]);
return true;
}
}
@@ -1227,7 +1227,7 @@ bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char* val) {
CFX_WideStringC wsStartEndChar;
if (pUIChild->TryCData(XFA_ATTRIBUTE_EndChar, wsStartEndChar)) {
if (wsStartEndChar.GetLength()) {
- *val = static_cast<char>(wsStartEndChar.GetAt(0));
+ *val = static_cast<char>(wsStartEndChar[0]);
return true;
}
}