summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-28 14:07:04 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-28 18:21:44 +0000
commite7a99de4f711302d57fe22682a9a8c3cfddb458c (patch)
tree7bb176d42e2a2181f014b41bd621d6b242ed20e7 /xfa/fxfa
parent106eecd27f346a0bc7f11f29a058a8fd16a77682 (diff)
downloadpdfium-e7a99de4f711302d57fe22682a9a8c3cfddb458c.tar.xz
Convert calls to Mid() to Left() or Right() if possible
The various string/byte classes support Mid(), Left(), and Right() for extracting substrings. Mid() can handle all possible cases, but Left() and Right() are useful for common cases and more explicit about what is going on. Calls like Mid(offset, length - offset) can be converted to Right(length - offset). Calls like Mid(0, length) can be converted to Left(length). If the substring being extracted does not extend all the way to one of the edges of the string, then Mid() still needs to be used. BUG=pdfium:828 Change-Id: I2ec46ad3d71aac0f7b513e103c69cbe8c854cf62 Reviewed-on: https://pdfium-review.googlesource.com/9510 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp8
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmexpression.cpp20
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_measurement.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp3
7 files changed, 23 insertions, 26 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 1910e60e3e..84064efb45 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -1139,7 +1139,7 @@ void CXFA_FM2JSContext::IsoTime2Num(CFXJSE_Value* pThis,
CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
CFX_ByteString szArgString = ValueToUTF8String(argOne.get());
FX_STRSIZE pos = szArgString.Find('T', 0);
- szArgString = szArgString.Mid(pos + 1, szArgString.GetLength() - (pos + 1));
+ szArgString = szArgString.Right(szArgString.GetLength() - (pos + 1));
if (szArgString.IsEmpty()) {
args.GetReturnValue()->SetInteger(0);
return;
@@ -3694,8 +3694,7 @@ void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis,
CFX_WideString wsTimePattern(L"time{");
wsTimePattern +=
- wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) +
- L"}";
+ wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) + L"}";
wsPattern = wsDatePattern + wsTimePattern;
} break;
case XFA_VT_DATE: {
@@ -3881,8 +3880,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis,
FX_STRSIZE iTChar = wsPattern.Find(L'T');
CFX_WideString wsDatePattern(L"date{" + wsPattern.Left(iTChar) + L"} ");
CFX_WideString wsTimePattern(
- L"time{" +
- wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) +
+ L"time{" + wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) +
L"}");
wsPattern = wsDatePattern + wsTimePattern;
CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index b201863b25..a74239ff82 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -62,7 +62,7 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << L"function ";
if (m_wsName.GetAt(0) == L'!') {
CFX_WideString tempName =
- EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+ EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
javascript << tempName;
} else {
javascript << m_wsName;
@@ -75,7 +75,7 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
if (identifier.GetAt(0) == L'!') {
CFX_WideString tempIdentifier =
EXCLAMATION_IN_IDENTIFIER +
- identifier.Mid(1, identifier.GetLength() - 1);
+ identifier.Right(identifier.GetLength() - 1);
javascript << tempIdentifier;
} else {
javascript << identifier;
@@ -130,7 +130,7 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
CFX_WideString tempName(m_wsName);
if (m_wsName.GetAt(0) == L'!') {
tempName =
- EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+ EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
}
javascript << tempName;
javascript << L" = ";
@@ -154,7 +154,7 @@ bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
CFX_WideString tempName(m_wsName);
if (m_wsName.GetAt(0) == L'!') {
tempName =
- EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+ EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
}
javascript << tempName;
javascript << L" = ";
@@ -461,7 +461,7 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
CFX_WideString tempVariant;
if (m_wsVariant.GetAt(0) == L'!') {
tempVariant = EXCLAMATION_IN_IDENTIFIER +
- m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1);
+ m_wsVariant.Right(m_wsVariant.GetLength() - 1);
javascript << tempVariant;
} else {
tempVariant = m_wsVariant;
@@ -516,7 +516,7 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
CFX_WideString tempVariant;
if (m_wsVariant.GetAt(0) == L'!') {
tempVariant = EXCLAMATION_IN_IDENTIFIER +
- m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1);
+ m_wsVariant.Right(m_wsVariant.GetLength() - 1);
javascript << tempVariant;
} else {
tempVariant = m_wsVariant;
@@ -583,7 +583,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
if (m_wsIdentifier.GetAt(0) == L'!') {
CFX_WideString tempIdentifier =
EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+ m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
javascript << tempIdentifier;
} else {
javascript << m_wsIdentifier;
@@ -615,7 +615,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
if (m_wsIdentifier.GetAt(0) == L'!') {
CFX_WideString tempIdentifier =
EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+ m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
javascript << tempIdentifier;
} else {
javascript << m_wsIdentifier;
@@ -640,7 +640,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
if (m_wsIdentifier.GetAt(0) == L'!') {
CFX_WideString tempIdentifier =
EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+ m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
javascript << tempIdentifier;
} else {
javascript << m_wsIdentifier;
@@ -671,7 +671,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
if (m_wsIdentifier.GetAt(0) == L'!') {
CFX_WideString tempIdentifier =
EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+ m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
javascript << tempIdentifier;
} else {
javascript << m_wsIdentifier;
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
index 1a3a125032..32876e3b65 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
@@ -181,7 +181,7 @@ bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
tempStr = L"xfa.template";
} else if (tempStr[0] == L'!') {
tempStr =
- EXCLAMATION_IN_IDENTIFIER + tempStr.Mid(1, tempStr.GetLength() - 1);
+ EXCLAMATION_IN_IDENTIFIER + tempStr.Right(tempStr.GetLength() - 1);
}
javascript << tempStr;
return true;
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index e3565835c3..4d6886d7e1 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -162,7 +162,7 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
if (wsExpr.GetAt(0) == '#') {
CXFA_Node* pNode = pDocument->GetNodeByID(
ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Template)),
- wsExpr.Mid(1, wsExpr.GetLength() - 1).AsStringC());
+ wsExpr.Right(wsExpr.GetLength() - 1).AsStringC());
if (pNode)
return pNode;
} else if (bNewExprStyle) {
diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp
index 50076583bb..66b715ec38 100644
--- a/xfa/fxfa/parser/cxfa_measurement.cpp
+++ b/xfa/fxfa/parser/cxfa_measurement.cpp
@@ -40,8 +40,8 @@ void CXFA_Measurement::SetString(const CFX_WideStringC& wsMeasure) {
int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0;
float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str() + iOffset,
wsMeasure.GetLength() - iOffset, &iUsedLen);
- XFA_UNIT eUnit = GetUnitFromString(wsMeasure.Mid(
- iOffset + iUsedLen, wsMeasure.GetLength() - (iOffset + iUsedLen)));
+ XFA_UNIT eUnit = GetUnitFromString(
+ wsMeasure.Right(wsMeasure.GetLength() - (iOffset + iUsedLen)));
Set(fValue, eUnit);
}
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 1265988902..261fee1971 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -77,7 +77,7 @@ int32_t GetCount(CXFA_Node* pInstMgrNode) {
CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
- wsInstName.Mid(1, wsInstName.GetLength() - 1) != wsName) {
+ wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return iCount;
}
dwNameHash = pNode->GetNameHash();
@@ -198,7 +198,7 @@ CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
- wsInstName.Mid(1, wsInstName.GetLength() - 1) != wsName) {
+ wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return nullptr;
}
dwNameHash = pNode->GetNameHash();
@@ -2737,7 +2737,7 @@ void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
if (pNode->GetElementType() == XFA_Element::InstanceManager) {
CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
- wsInstMgrName.Mid(1, wsInstMgrName.GetLength() - 1) == wsName) {
+ wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) {
pInstanceMgr = pNode;
}
break;
@@ -3165,7 +3165,7 @@ int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
CFX_WideString wsInstanceName = CFX_WideString(
wsInstManagerName.IsEmpty()
? wsInstManagerName
- : wsInstManagerName.Mid(1, wsInstManagerName.GetLength() - 1));
+ : wsInstManagerName.Right(wsInstManagerName.GetLength() - 1));
uint32_t dInstanceNameHash =
FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
CXFA_Node* pPrevSibling =
@@ -4665,7 +4665,7 @@ CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
- wsInstName.Mid(1, wsInstName.GetLength() - 1) == wsName) {
+ wsInstName.Right(wsInstName.GetLength() - 1) == wsName) {
pInstanceMgr = pNode;
}
break;
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 1920e9f3fd..5efc0ea481 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1324,8 +1324,7 @@ bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) {
int32_t fA, fB;
fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos).c_str());
fB = FXSYS_wtoi(
- wsWideNarrowRatio
- .Mid(ptPos + 1, wsWideNarrowRatio.GetLength() - (ptPos + 1))
+ wsWideNarrowRatio.Right(wsWideNarrowRatio.GetLength() - (ptPos + 1))
.c_str());
if (fB)
fRatio = (float)fA / fB;