summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-08 10:55:57 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-08 10:55:57 -0800
commit51709bea3ce113df7d36a5fe6415036e26fc3236 (patch)
treeff2cc5da9de834bda8cbc5c92d45c9a5c00b21c3 /xfa/fxfa/parser
parent447b1f3ffc7e0df233d15300bbf8a85ce2bc7278 (diff)
downloadpdfium-51709bea3ce113df7d36a5fe6415036e26fc3236.tar.xz
Replace CFX_WideStringArray with std::vector
Minimalist changes with the tidying of the code to use better loop iterators as a follow-up. Review-Url: https://codereview.chromium.org/2556963004
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp62
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.h6
-rw-r--r--xfa/fxfa/parser/xfa_document_datamerger_imp.cpp7
-rw-r--r--xfa/fxfa/parser/xfa_layout_itemlayout.cpp13
-rw-r--r--xfa/fxfa/parser/xfa_localevalue.cpp15
7 files changed, 71 insertions, 52 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index a9965f52a5..72d1fa76ba 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -6,7 +6,10 @@
#include "xfa/fxfa/parser/cxfa_dataexporter.h"
+#include <vector>
+
#include "core/fxcrt/fx_basic.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fde/xml/fde_xml_imp.h"
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -217,12 +220,12 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
if (wsRawValue.IsEmpty())
break;
- CFX_WideStringArray wsSelTextArray;
+ std::vector<CFX_WideString> wsSelTextArray;
int32_t iStart = 0;
int32_t iEnd = wsRawValue.Find(L'\n', iStart);
iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd;
while (iEnd >= iStart) {
- wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart));
+ wsSelTextArray.push_back(wsRawValue.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
if (iStart >= wsRawValue.GetLength())
break;
@@ -242,7 +245,8 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
buf << FX_WSTRC(L"<");
buf << bodyTagName;
buf << FX_WSTRC(L" xmlns=\"\"\n>");
- for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) {
+ for (int32_t i = 0; i < pdfium::CollectionSize<int32_t>(wsSelTextArray);
+ i++) {
buf << FX_WSTRC(L"<value\n>");
buf << ExportEncodeContent(wsSelTextArray[i].AsStringC());
buf << FX_WSTRC(L"</value\n>");
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index f3f79cbbec..1721cb7982 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
#include <utility>
+#include <vector>
#include "core/fxcrt/fx_ext.h"
#include "fxjs/cfxjse_value.h"
@@ -4150,7 +4151,7 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
bScriptModify, false);
CXFA_Node* pBind = GetBindData();
if (bSyncData && pBind) {
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
int32_t iSize = 0;
if (!wsContent.IsEmpty()) {
int32_t iStart = 0;
@@ -4158,17 +4159,18 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
int32_t iEnd = wsContent.Find(L'\n', iStart);
iEnd = (iEnd == -1) ? iLength : iEnd;
while (iEnd >= iStart) {
- wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart));
+ wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
if (iStart >= iLength) {
break;
}
iEnd = wsContent.Find(L'\n', iStart);
if (iEnd < 0) {
- wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart));
+ wsSaveTextArray.push_back(
+ wsContent.Mid(iStart, iLength - iStart));
}
}
- iSize = wsSaveTextArray.GetSize();
+ iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
}
if (iSize == 0) {
while (CXFA_Node* pChildNode =
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index c9523383dd..48a26aafad 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/parser/cxfa_widgetdata.h"
#include "core/fxcrt/fx_ext.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fxbarcode/BC_Library.h"
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -805,8 +806,9 @@ bool CXFA_WidgetData::GetChoiceListItem(CFX_WideString& wsText,
return false;
}
-void CXFA_WidgetData::GetChoiceListItems(CFX_WideStringArray& wsTextArray,
- bool bSaveValue) {
+void CXFA_WidgetData::GetChoiceListItems(
+ std::vector<CFX_WideString>& wsTextArray,
+ bool bSaveValue) {
CXFA_NodeArray pItems;
CXFA_Node* pItem = nullptr;
int32_t iCount = 0;
@@ -832,22 +834,24 @@ void CXFA_WidgetData::GetChoiceListItems(CFX_WideStringArray& wsTextArray,
}
pItems.RemoveAll();
pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild);
- for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling))
- pNode->TryContent(wsTextArray.Add());
+ for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ wsTextArray.emplace_back();
+ pNode->TryContent(wsTextArray.back());
+ }
}
int32_t CXFA_WidgetData::CountSelectedItems() {
- CFX_WideStringArray wsValueArray;
+ std::vector<CFX_WideString> wsValueArray;
GetSelectedItemsValue(wsValueArray);
if (IsListBox() || !IsChoiceListAllowTextEntry())
- return wsValueArray.GetSize();
+ return pdfium::CollectionSize<int32_t>(wsValueArray);
int32_t iSelected = 0;
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
- int32_t iValues = wsValueArray.GetSize();
+ int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
for (int32_t i = 0; i < iValues; i++) {
- int32_t iSaves = wsSaveTextArray.GetSize();
+ int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
for (int32_t j = 0; j < iSaves; j++) {
if (wsValueArray[i] == wsSaveTextArray[j]) {
iSelected++;
@@ -859,11 +863,11 @@ int32_t CXFA_WidgetData::CountSelectedItems() {
}
int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) {
- CFX_WideStringArray wsValueArray;
+ std::vector<CFX_WideString> wsValueArray;
GetSelectedItemsValue(wsValueArray);
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
- int32_t iSaves = wsSaveTextArray.GetSize();
+ int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
for (int32_t j = 0; j < iSaves; j++) {
if (wsValueArray[nIndex] == wsSaveTextArray[j])
return j;
@@ -872,15 +876,15 @@ int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) {
}
void CXFA_WidgetData::GetSelectedItems(CFX_Int32Array& iSelArray) {
- CFX_WideStringArray wsValueArray;
+ std::vector<CFX_WideString> wsValueArray;
GetSelectedItemsValue(wsValueArray);
- int32_t iValues = wsValueArray.GetSize();
+ int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
if (iValues < 1)
return;
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
- int32_t iSaves = wsSaveTextArray.GetSize();
+ int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
for (int32_t i = 0; i < iValues; i++) {
for (int32_t j = 0; j < iSaves; j++) {
if (wsValueArray[i] == wsSaveTextArray[j]) {
@@ -892,7 +896,7 @@ void CXFA_WidgetData::GetSelectedItems(CFX_Int32Array& iSelArray) {
}
void CXFA_WidgetData::GetSelectedItemsValue(
- CFX_WideStringArray& wsSelTextArray) {
+ std::vector<CFX_WideString>& wsSelTextArray) {
CFX_WideString wsValue = GetRawValue();
if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
if (!wsValue.IsEmpty()) {
@@ -901,18 +905,18 @@ void CXFA_WidgetData::GetSelectedItemsValue(
int32_t iEnd = wsValue.Find(L'\n', iStart);
iEnd = (iEnd == -1) ? iLength : iEnd;
while (iEnd >= iStart) {
- wsSelTextArray.Add(wsValue.Mid(iStart, iEnd - iStart));
+ wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
if (iStart >= iLength)
break;
iEnd = wsValue.Find(L'\n', iStart);
if (iEnd < 0)
- wsSelTextArray.Add(wsValue.Mid(iStart, iLength - iStart));
+ wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart));
}
}
} else {
- wsSelTextArray.Add(wsValue);
+ wsSelTextArray.push_back(wsValue);
}
}
@@ -920,14 +924,14 @@ bool CXFA_WidgetData::GetItemState(int32_t nIndex) {
if (nIndex < 0)
return false;
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
- if (wsSaveTextArray.GetSize() <= nIndex)
+ if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex)
return false;
- CFX_WideStringArray wsValueArray;
+ std::vector<CFX_WideString> wsValueArray;
GetSelectedItemsValue(wsValueArray);
- int32_t iValues = wsValueArray.GetSize();
+ int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
for (int32_t j = 0; j < iValues; j++) {
if (wsValueArray[j] == wsSaveTextArray[nIndex])
return true;
@@ -943,15 +947,15 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex,
if (nIndex < 0)
return;
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
- if (wsSaveTextArray.GetSize() <= nIndex)
+ if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex)
return;
int32_t iSel = -1;
- CFX_WideStringArray wsValueArray;
+ std::vector<CFX_WideString> wsValueArray;
GetSelectedItemsValue(wsValueArray);
- int32_t iValues = wsValueArray.GetSize();
+ int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
for (int32_t j = 0; j < iValues; j++) {
if (wsValueArray[j] == wsSaveTextArray[nIndex]) {
iSel = j;
@@ -1003,7 +1007,7 @@ void CXFA_WidgetData::SetSelectedItems(CFX_Int32Array& iSelArray,
CFX_WideString wsValue;
int32_t iSize = iSelArray.GetSize();
if (iSize >= 1) {
- CFX_WideStringArray wsSaveTextArray;
+ std::vector<CFX_WideString> wsSaveTextArray;
GetChoiceListItems(wsSaveTextArray, true);
CFX_WideString wsItemValue;
for (int32_t i = 0; i < iSize; i++) {
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h
index 5c030d6b52..0079996735 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.h
+++ b/xfa/fxfa/parser/cxfa_widgetdata.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_PARSER_CXFA_WIDGETDATA_H_
#define XFA_FXFA_PARSER_CXFA_WIDGETDATA_H_
+#include <vector>
+
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "xfa/fxfa/parser/cxfa_assist.h"
@@ -97,12 +99,12 @@ class CXFA_WidgetData : public CXFA_Data {
bool GetChoiceListItem(CFX_WideString& wsText,
int32_t nIndex,
bool bSaveValue = false);
- void GetChoiceListItems(CFX_WideStringArray& wsTextArray,
+ void GetChoiceListItems(std::vector<CFX_WideString>& wsTextArray,
bool bSaveValue = false);
int32_t CountSelectedItems();
int32_t GetSelectedItem(int32_t nIndex = 0);
void GetSelectedItems(CFX_Int32Array& iSelArray);
- void GetSelectedItemsValue(CFX_WideStringArray& wsSelTextArray);
+ void GetSelectedItemsValue(std::vector<CFX_WideString>& wsSelTextArray);
bool GetItemState(int32_t nIndex);
void SetItemState(int32_t nIndex,
bool bSelected,
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
index 1fc9530e09..dab61e65d8 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -6,7 +6,10 @@
#include "xfa/fxfa/parser/xfa_document_datamerger_imp.h"
+#include <vector>
+
#include "core/fxcrt/fx_ext.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fde/xml/fde_xml_imp.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
@@ -149,9 +152,9 @@ void CreateDataBinding(CXFA_Node* pFormNode,
case XFA_Element::ChoiceList:
defValue.GetChildValueContent(wsValue);
if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
- CFX_WideStringArray wsSelTextArray;
+ std::vector<CFX_WideString> wsSelTextArray;
pWidgetData->GetSelectedItemsValue(wsSelTextArray);
- int32_t iSize = wsSelTextArray.GetSize();
+ int32_t iSize = pdfium::CollectionSize<int32_t>(wsSelTextArray);
if (iSize >= 1) {
CXFA_Node* pValue = nullptr;
for (int32_t i = 0; i < iSize; i++) {
diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp
index 6926a99309..45dc327710 100644
--- a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp
+++ b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp
@@ -8,7 +8,9 @@
#include <algorithm>
#include <memory>
+#include <vector>
+#include "third_party/base/stl_util.h"
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_containerlayoutitem.h"
#include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
@@ -25,7 +27,7 @@ namespace {
int32_t SeparateStringW(const FX_WCHAR* pStr,
int32_t iStrLen,
FX_WCHAR delimiter,
- CFX_WideStringArray& pieces) {
+ std::vector<CFX_WideString>& pieces) {
if (!pStr)
return 0;
if (iStrLen < 0)
@@ -35,15 +37,14 @@ int32_t SeparateStringW(const FX_WCHAR* pStr,
const FX_WCHAR* pEnd = pStr + iStrLen;
while (true) {
if (pStr >= pEnd || delimiter == *pStr) {
- CFX_WideString sub(pToken, pStr - pToken);
- pieces.Add(sub);
+ pieces.push_back(CFX_WideString(pToken, pStr - pToken));
pToken = pStr + 1;
if (pStr >= pEnd)
break;
}
pStr++;
}
- return pieces.GetSize();
+ return pdfium::CollectionSize<int32_t>(pieces);
}
} // namespace
@@ -1401,10 +1402,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) {
: fContainerWidth - fLeftInset - fRightInset;
CFX_WideStringC wsColumnWidths;
if (pLayoutNode->TryCData(XFA_ATTRIBUTE_ColumnWidths, wsColumnWidths)) {
- CFX_WideStringArray widths;
+ std::vector<CFX_WideString> widths;
if (SeparateStringW(wsColumnWidths.c_str(), wsColumnWidths.GetLength(),
L' ', widths) > 0) {
- int32_t iCols = widths.GetSize();
+ int32_t iCols = pdfium::CollectionSize<int32_t>(widths);
CFX_WideString wsWidth;
for (int32_t i = 0; i < iCols; i++) {
wsWidth = widths[i];
diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp
index c060fe8166..87961358e8 100644
--- a/xfa/fxfa/parser/xfa_localevalue.cpp
+++ b/xfa/fxfa/parser/xfa_localevalue.cpp
@@ -6,8 +6,11 @@
#include "xfa/fxfa/parser/xfa_localevalue.h"
+#include <vector>
+
#include "core/fxcrt/fx_ext.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fgas/localization/fgas_localeimp.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/xfa_localemgr.h"
@@ -105,11 +108,11 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
m_pLocaleMgr->SetDefLocale(pLocale);
auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
- CFX_WideStringArray wsPatterns;
+ std::vector<CFX_WideString> wsPatterns;
pFormat->SplitFormatString(wsPattern, wsPatterns);
bool bRet = false;
- int32_t iCount = wsPatterns.GetSize();
+ int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns);
int32_t i = 0;
for (; i < iCount && !bRet; i++) {
CFX_WideString wsFormat = wsPatterns[i];
@@ -464,10 +467,10 @@ bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult,
IFX_Locale* pLocale,
XFA_VALUEPICTURE eValueType) const {
auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
- CFX_WideStringArray wsPatterns;
+ std::vector<CFX_WideString> wsPatterns;
pFormat->SplitFormatString(wsFormat, wsPatterns);
wsResult.clear();
- int32_t iCount = wsPatterns.GetSize();
+ int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns);
for (int32_t i = 0; i < iCount; i++) {
if (FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType))
return true;
@@ -793,10 +796,10 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
m_pLocaleMgr->SetDefLocale(pLocale);
auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
- CFX_WideStringArray wsPatterns;
+ std::vector<CFX_WideString> wsPatterns;
pFormat->SplitFormatString(wsPattern, wsPatterns);
bool bRet = false;
- int32_t iCount = wsPatterns.GetSize();
+ int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns);
for (int32_t i = 0; i < iCount && !bRet; i++) {
CFX_WideString wsFormat = wsPatterns[i];
FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat);