diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-16 13:44:38 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-16 13:44:38 +0000 |
commit | 0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44 (patch) | |
tree | 2ed1f71183096853a7d552276047a67b473a9721 /fxjs | |
parent | b066704a22ba4f242567f508c12bf2545cbed9e1 (diff) | |
download | pdfium-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')
-rw-r--r-- | fxjs/cjx_node.cpp | 29 | ||||
-rw-r--r-- | fxjs/cjx_node.h | 2 |
2 files changed, 11 insertions, 20 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, diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h index 2e9360d451..6c95673d25 100644 --- a/fxjs/cjx_node.h +++ b/fxjs/cjx_node.h @@ -69,7 +69,7 @@ class CJX_Node : public CJX_Object { bool bSyncData); WideString GetContent(bool bScriptModify); - bool TryInteger(XFA_Attribute eAttr, int32_t& iValue, bool bUseDefault); + pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault); bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify); int32_t GetInteger(XFA_Attribute eAttr); |