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 /xfa/fxfa/parser/cxfa_occurdata.cpp | |
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 'xfa/fxfa/parser/cxfa_occurdata.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_occurdata.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/xfa/fxfa/parser/cxfa_occurdata.cpp b/xfa/fxfa/parser/cxfa_occurdata.cpp index 1f20e3c0e9..4538919d10 100644 --- a/xfa/fxfa/parser/cxfa_occurdata.cpp +++ b/xfa/fxfa/parser/cxfa_occurdata.cpp @@ -11,22 +11,21 @@ CXFA_OccurData::CXFA_OccurData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} int32_t CXFA_OccurData::GetMax() { - int32_t iMax = 1; - if (m_pNode) { - if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, true)) - iMax = GetMin(); - } - return iMax; + if (!m_pNode) + return 1; + + pdfium::Optional<int32_t> max = + m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, true); + return max ? *max : GetMin(); } int32_t CXFA_OccurData::GetMin() { - int32_t iMin = 1; - if (m_pNode) { - if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, true) || - iMin < 0) - iMin = 1; - } - return iMin; + if (!m_pNode) + return 1; + + pdfium::Optional<int32_t> min = + m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, true); + return min && *min >= 0 ? *min : 1; } bool CXFA_OccurData::GetOccurInfo(int32_t& iMin, @@ -34,19 +33,14 @@ bool CXFA_OccurData::GetOccurInfo(int32_t& iMin, int32_t& iInit) { if (!m_pNode) return false; - if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Min, iMin, false) || - iMin < 0) - iMin = 1; - if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Max, iMax, false)) { - if (iMin == 0) - iMax = 1; - else - iMax = iMin; - } - if (!m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, iInit, false) || - iInit < iMin) { - iInit = iMin; - } + + iMin = GetMin(); + iMax = GetMax(); + + pdfium::Optional<int32_t> init = + m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, false); + iInit = init && *init >= iMin ? *init : iMin; + return true; } |