summaryrefslogtreecommitdiff
path: root/fxjs/cjx_node.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 13:44:38 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 13:44:38 +0000
commit0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44 (patch)
tree2ed1f71183096853a7d552276047a67b473a9721 /fxjs/cjx_node.cpp
parentb066704a22ba4f242567f508c12bf2545cbed9e1 (diff)
downloadpdfium-0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44.tar.xz
Convert TryInteger to return an optional
This Cl changes CJX_Node::TryInteger to return a pdfium::Optional<int32_t> instead of a boolean with an out param. Change-Id: I4675e08d3b132041f7d87e4639efa1d555089dc2 Reviewed-on: https://pdfium-review.googlesource.com/18511 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/cjx_node.cpp')
-rw-r--r--fxjs/cjx_node.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index a1b2f048dc..0e0f2d0274 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -294,11 +294,11 @@ bool CJX_Node::GetAttribute(XFA_Attribute eAttr,
return true;
}
case XFA_AttributeType::Integer: {
- int32_t iValue;
- if (!TryInteger(pAttr->eName, iValue, bUseDefault))
+ pdfium::Optional<int32_t> iValue = TryInteger(pAttr->eName, bUseDefault);
+ if (!iValue)
return false;
- wsValue.Format(L"%d", iValue);
+ wsValue.Format(L"%d", *iValue);
return true;
}
case XFA_AttributeType::Measure: {
@@ -3038,28 +3038,19 @@ bool CJX_Node::SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify) {
}
int32_t CJX_Node::GetInteger(XFA_Attribute eAttr) {
- int32_t iValue;
- return TryInteger(eAttr, iValue, true) ? iValue : 0;
+ return TryInteger(eAttr, true).value_or(0);
}
-bool CJX_Node::TryInteger(XFA_Attribute eAttr,
- int32_t& iValue,
- bool bUseDefault) {
+pdfium::Optional<int32_t> CJX_Node::TryInteger(XFA_Attribute eAttr,
+ bool bUseDefault) {
void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr);
void* pValue = nullptr;
- if (GetMapModuleValue(pKey, pValue)) {
- iValue = (int32_t)(uintptr_t)pValue;
- return true;
- }
+ if (GetMapModuleValue(pKey, pValue))
+ return {static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))};
if (!bUseDefault)
- return false;
-
- pdfium::Optional<int32_t> ret = GetXFANode()->GetDefaultInteger(eAttr);
- if (!ret)
- return false;
+ return {};
- iValue = *ret;
- return true;
+ return GetXFANode()->GetDefaultInteger(eAttr);
}
bool CJX_Node::TryEnum(XFA_Attribute eAttr,