summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_dataexporter.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 14:17:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 14:17:17 +0000
commit9d608ff14177cd665f6b2ead639415bda935fbe2 (patch)
treed538fbf435ed55cf07ff37c24bc835507c12466d /xfa/fxfa/parser/cxfa_dataexporter.cpp
parent9d47de6b27b167db46b6aba38352fc42a8b6adae (diff)
downloadpdfium-9d608ff14177cd665f6b2ead639415bda935fbe2.tar.xz
Cleanup CJX_Node::GetAttribute
This CL renames GetAttribute to TryAttribute and changes to return a pdfium::Optional instead of a boolean with an out parameter. GetAttribute is then added to call TryAttribute to mirror the other methods in the file. Change-Id: I875dac120776af7c53fe069e4dd36e5486838447 Reviewed-on: https://pdfium-review.googlesource.com/18514 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_dataexporter.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index 35ad4adccf..f7715dc374 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -90,16 +90,18 @@ void SaveAttribute(CXFA_Node* pNode,
const WideStringView& wsName,
bool bProto,
WideString& wsOutput) {
- WideString wsValue;
- if ((!bProto && !pNode->JSNode()->HasAttribute(eName)) ||
- !pNode->JSNode()->GetAttribute(eName, wsValue, false)) {
+ if (!bProto && !pNode->JSNode()->HasAttribute(eName))
return;
- }
- wsValue = ExportEncodeAttribute(wsValue);
+
+ pdfium::Optional<WideString> value =
+ pNode->JSNode()->TryAttribute(eName, false);
+ if (!value)
+ return;
+
wsOutput += L" ";
wsOutput += wsName;
wsOutput += L"=\"";
- wsOutput += wsValue;
+ wsOutput += ExportEncodeAttribute(*value);
wsOutput += L"\"";
}
@@ -196,11 +198,10 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
if (!pRawValueNode)
break;
- WideString wsContentType;
- pNode->JSNode()->GetAttribute(XFA_Attribute::ContentType, wsContentType,
- false);
+ pdfium::Optional<WideString> contentType =
+ pNode->JSNode()->TryAttribute(XFA_Attribute::ContentType, false);
if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML &&
- wsContentType == L"text/html") {
+ (contentType && *contentType == L"text/html")) {
CFX_XMLNode* pExDataXML = pNode->GetXMLMappingNode();
if (!pExDataXML)
break;
@@ -219,25 +220,25 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
wsChildren += WideString::FromUTF8(
ByteStringView(pMemStream->GetBuffer(), pMemStream->GetSize()));
} else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml &&
- wsContentType == L"text/xml") {
- WideString wsRawValue;
- pRawValueNode->JSNode()->GetAttribute(XFA_Attribute::Value, wsRawValue,
- false);
- if (wsRawValue.IsEmpty())
+ (contentType && *contentType == L"text/xml")) {
+ pdfium::Optional<WideString> rawValue =
+ pRawValueNode->JSNode()->TryAttribute(XFA_Attribute::Value, false);
+ if (!rawValue || rawValue->IsEmpty())
break;
std::vector<WideString> wsSelTextArray;
size_t iStart = 0;
- auto iEnd = wsRawValue.Find(L'\n', iStart);
- iEnd = !iEnd.has_value() ? wsRawValue.GetLength() : iEnd;
+ auto iEnd = rawValue->Find(L'\n', iStart);
+ iEnd = !iEnd.has_value() ? rawValue->GetLength() : iEnd;
while (iEnd.has_value() && iEnd >= iStart) {
wsSelTextArray.push_back(
- wsRawValue.Mid(iStart, iEnd.value() - iStart));
+ rawValue->Mid(iStart, iEnd.value() - iStart));
iStart = iEnd.value() + 1;
- if (iStart >= wsRawValue.GetLength())
+ if (iStart >= rawValue->GetLength())
break;
- iEnd = wsRawValue.Find(L'\n', iStart);
+ iEnd = rawValue->Find(L'\n', iStart);
}
+
CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
ASSERT(pParentNode);
CXFA_Node* pGrandparentNode =