summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-27 12:44:20 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-27 20:00:37 +0000
commit5c500acc3380d96db0ab5e2e6c2bc448644992de (patch)
tree6d901f2a357095e00965165f94a0e1769f62d326 /xfa/fxfa/parser
parentd59442b054072dabfcd5c9cb766e7b60c13a1e69 (diff)
downloadpdfium-5c500acc3380d96db0ab5e2e6c2bc448644992de.tar.xz
Return arrays where appropriate in fxfa.
Also, remove some default method arguments along the way. Change-Id: Ifbd157499881ed6a3777f3903dd7f0193753cf59 Reviewed-on: https://pdfium-review.googlesource.com/3219 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp166
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.h13
-rw-r--r--xfa/fxfa/parser/xfa_document_datamerger_imp.cpp15
3 files changed, 74 insertions, 120 deletions
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index b2673818d9..a314bec2b8 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -795,94 +795,74 @@ bool CXFA_WidgetData::GetChoiceListItem(CFX_WideString& wsText,
return false;
}
-void CXFA_WidgetData::GetChoiceListItems(
- std::vector<CFX_WideString>& wsTextArray,
+std::vector<CFX_WideString> CXFA_WidgetData::GetChoiceListItems(
bool bSaveValue) {
- std::vector<CXFA_Node*> pItems;
- int32_t iCount = 0;
- for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
+ std::vector<CXFA_Node*> items;
+ for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
+ pNode && items.size() < 2;
pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- if (pNode->GetElementType() != XFA_Element::Items)
- continue;
- iCount++;
- pItems.push_back(pNode);
- if (iCount == 2)
- break;
+ if (pNode->GetElementType() == XFA_Element::Items)
+ items.push_back(pNode);
}
- if (iCount == 0)
- return;
+ if (items.empty())
+ return std::vector<CFX_WideString>();
- CXFA_Node* pItem = pItems[0];
- if (iCount > 1) {
- bool bItemOneHasSave = pItems[0]->GetBoolean(XFA_ATTRIBUTE_Save);
- bool bItemTwoHasSave = pItems[1]->GetBoolean(XFA_ATTRIBUTE_Save);
+ CXFA_Node* pItem = items.front();
+ if (items.size() > 1) {
+ bool bItemOneHasSave = items[0]->GetBoolean(XFA_ATTRIBUTE_Save);
+ bool bItemTwoHasSave = items[1]->GetBoolean(XFA_ATTRIBUTE_Save);
if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave)
- pItem = pItems[1];
+ pItem = items[1];
}
+
+ std::vector<CFX_WideString> wsTextArray;
for (CXFA_Node* pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
wsTextArray.emplace_back();
pNode->TryContent(wsTextArray.back());
}
+ return wsTextArray;
}
int32_t CXFA_WidgetData::CountSelectedItems() {
- std::vector<CFX_WideString> wsValueArray;
- GetSelectedItemsValue(wsValueArray);
+ std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue();
if (IsListBox() || !IsChoiceListAllowTextEntry())
return pdfium::CollectionSize<int32_t>(wsValueArray);
int32_t iSelected = 0;
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
- int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
- for (int32_t i = 0; i < iValues; i++) {
- int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
- for (int32_t j = 0; j < iSaves; j++) {
- if (wsValueArray[i] == wsSaveTextArray[j]) {
- iSelected++;
- break;
- }
- }
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
+ for (const auto& value : wsValueArray) {
+ if (pdfium::ContainsValue(wsSaveTextArray, value))
+ iSelected++;
}
return iSelected;
}
int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) {
- std::vector<CFX_WideString> wsValueArray;
- GetSelectedItemsValue(wsValueArray);
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
- int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
- for (int32_t j = 0; j < iSaves; j++) {
- if (wsValueArray[nIndex] == wsSaveTextArray[j])
- return j;
- }
- return -1;
-}
+ std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue();
+ if (!pdfium::IndexInBounds(wsValueArray, nIndex))
+ return -1;
-void CXFA_WidgetData::GetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray) {
- std::vector<CFX_WideString> wsValueArray;
- GetSelectedItemsValue(wsValueArray);
- int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
- if (iValues < 1)
- return;
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
+ auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(),
+ wsValueArray[nIndex]);
+ return it != wsSaveTextArray.end() ? it - wsSaveTextArray.begin() : -1;
+}
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
- 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]) {
- iSelArray.Add(j);
- break;
- }
- }
+std::vector<int32_t> CXFA_WidgetData::GetSelectedItems() {
+ std::vector<int32_t> iSelArray;
+ std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue();
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
+ for (const auto& value : wsValueArray) {
+ auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), value);
+ if (it != wsSaveTextArray.end())
+ iSelArray.push_back(it - wsSaveTextArray.begin());
}
+ return iSelArray;
}
-void CXFA_WidgetData::GetSelectedItemsValue(
- std::vector<CFX_WideString>& wsSelTextArray) {
+std::vector<CFX_WideString> CXFA_WidgetData::GetSelectedItemsValue() {
+ std::vector<CFX_WideString> wsSelTextArray;
CFX_WideString wsValue = GetRawValue();
if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
if (!wsValue.IsEmpty()) {
@@ -895,7 +875,6 @@ void CXFA_WidgetData::GetSelectedItemsValue(
iStart = iEnd + 1;
if (iStart >= iLength)
break;
-
iEnd = wsValue.Find(L'\n', iStart);
if (iEnd < 0)
wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart));
@@ -904,25 +883,14 @@ void CXFA_WidgetData::GetSelectedItemsValue(
} else {
wsSelTextArray.push_back(wsValue);
}
+ return wsSelTextArray;
}
bool CXFA_WidgetData::GetItemState(int32_t nIndex) {
- if (nIndex < 0)
- return false;
-
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
- if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex)
- return false;
-
- std::vector<CFX_WideString> wsValueArray;
- GetSelectedItemsValue(wsValueArray);
- int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
- for (int32_t j = 0; j < iValues; j++) {
- if (wsValueArray[j] == wsSaveTextArray[nIndex])
- return true;
- }
- return false;
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
+ return pdfium::IndexInBounds(wsSaveTextArray, nIndex) &&
+ pdfium::ContainsValue(GetSelectedItemsValue(),
+ wsSaveTextArray[nIndex]);
}
void CXFA_WidgetData::SetItemState(int32_t nIndex,
@@ -930,24 +898,17 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex,
bool bNotify,
bool bScriptModify,
bool bSyncData) {
- if (nIndex < 0)
- return;
-
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
- if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex)
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
+ if (!pdfium::IndexInBounds(wsSaveTextArray, nIndex))
return;
int32_t iSel = -1;
- std::vector<CFX_WideString> wsValueArray;
- GetSelectedItemsValue(wsValueArray);
- int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray);
- for (int32_t j = 0; j < iValues; j++) {
- if (wsValueArray[j] == wsSaveTextArray[nIndex]) {
- iSel = j;
- break;
- }
- }
+ std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue();
+ auto it = std::find(wsValueArray.begin(), wsValueArray.end(),
+ wsSaveTextArray[nIndex]);
+ if (it != wsValueArray.end())
+ iSel = it - wsValueArray.begin();
+
if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
if (bSelected) {
if (iSel < 0) {
@@ -960,14 +921,10 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex,
bSyncData);
}
} else if (iSel >= 0) {
- CFX_ArrayTemplate<int32_t> iSelArray;
- GetSelectedItems(iSelArray);
- for (int32_t i = 0; i < iSelArray.GetSize(); i++) {
- if (iSelArray[i] == nIndex) {
- iSelArray.RemoveAt(i);
- break;
- }
- }
+ std::vector<int32_t> iSelArray = GetSelectedItems();
+ auto it = std::find(iSelArray.begin(), iSelArray.end(), nIndex);
+ if (it != iSelArray.end())
+ iSelArray.erase(it);
SetSelectedItems(iSelArray, bNotify, bScriptModify, bSyncData);
}
} else {
@@ -986,15 +943,14 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex,
}
}
-void CXFA_WidgetData::SetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray,
+void CXFA_WidgetData::SetSelectedItems(const std::vector<int32_t>& iSelArray,
bool bNotify,
bool bScriptModify,
bool bSyncData) {
CFX_WideString wsValue;
- int32_t iSize = iSelArray.GetSize();
+ int32_t iSize = pdfium::CollectionSize<int32_t>(iSelArray);
if (iSize >= 1) {
- std::vector<CFX_WideString> wsSaveTextArray;
- GetChoiceListItems(wsSaveTextArray, true);
+ std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true);
CFX_WideString wsItemValue;
for (int32_t i = 0; i < iSize; i++) {
wsItemValue = (iSize == 1) ? wsSaveTextArray[iSelArray[i]]
@@ -1641,7 +1597,7 @@ bool CXFA_WidgetData::GetValue(CFX_WideString& wsValue,
if (eValueType == XFA_VALUEPICTURE_Display) {
int32_t iSelItemIndex = GetSelectedItem(0);
if (iSelItemIndex >= 0) {
- GetChoiceListItem(wsValue, iSelItemIndex);
+ GetChoiceListItem(wsValue, iSelItemIndex, false);
wsPicture.clear();
}
}
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h
index 3e74018432..1caecea2b2 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.h
+++ b/xfa/fxfa/parser/cxfa_widgetdata.h
@@ -93,23 +93,22 @@ class CXFA_WidgetData : public CXFA_Data {
bool IsChoiceListAllowTextEntry();
int32_t GetChoiceListOpen();
bool IsListBox();
- int32_t CountChoiceListItems(bool bSaveValue = false);
+ int32_t CountChoiceListItems(bool bSaveValue);
bool GetChoiceListItem(CFX_WideString& wsText,
int32_t nIndex,
- bool bSaveValue = false);
- void GetChoiceListItems(std::vector<CFX_WideString>& wsTextArray,
- bool bSaveValue = false);
+ bool bSaveValue);
+ std::vector<CFX_WideString> GetChoiceListItems(bool bSaveValue);
int32_t CountSelectedItems();
int32_t GetSelectedItem(int32_t nIndex = 0);
- void GetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray);
- void GetSelectedItemsValue(std::vector<CFX_WideString>& wsSelTextArray);
+ std::vector<int32_t> GetSelectedItems();
+ std::vector<CFX_WideString> GetSelectedItemsValue();
bool GetItemState(int32_t nIndex);
void SetItemState(int32_t nIndex,
bool bSelected,
bool bNotify,
bool bScriptModify,
bool bSyncData);
- void SetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray,
+ void SetSelectedItems(const std::vector<int32_t>& iSelArray,
bool bNotify,
bool bScriptModify,
bool bSyncData);
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
index 227064a73b..cfc54a11d9 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -153,17 +153,16 @@ void CreateDataBinding(CXFA_Node* pFormNode,
case XFA_Element::ChoiceList:
defValue.GetChildValueContent(wsValue);
if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
- std::vector<CFX_WideString> wsSelTextArray;
- pWidgetData->GetSelectedItemsValue(wsSelTextArray);
- int32_t iSize = pdfium::CollectionSize<int32_t>(wsSelTextArray);
- if (iSize >= 1) {
- CXFA_Node* pValue = nullptr;
- for (int32_t i = 0; i < iSize; i++) {
- pValue = pDataNode->CreateSamePacketNode(XFA_Element::DataValue);
+ std::vector<CFX_WideString> wsSelTextArray =
+ pWidgetData->GetSelectedItemsValue();
+ if (!wsSelTextArray.empty()) {
+ for (const auto& text : wsSelTextArray) {
+ CXFA_Node* pValue =
+ pDataNode->CreateSamePacketNode(XFA_Element::DataValue);
pValue->SetCData(XFA_ATTRIBUTE_Name, L"value");
pValue->CreateXMLMappingNode();
pDataNode->InsertChild(pValue);
- pValue->SetCData(XFA_ATTRIBUTE_Value, wsSelTextArray[i]);
+ pValue->SetCData(XFA_ATTRIBUTE_Value, text);
}
} else {
CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();