From 0bf9aef229ae2c4f2f16ab753d6d2e9e6d718a44 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Nov 2017 13:44:38 +0000 Subject: Convert TryInteger to return an optional This Cl changes CJX_Node::TryInteger to return a pdfium::Optional instead of a boolean with an out param. Change-Id: I4675e08d3b132041f7d87e4639efa1d555089dc2 Reviewed-on: https://pdfium-review.googlesource.com/18511 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_occurdata.cpp | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'xfa/fxfa/parser/cxfa_occurdata.cpp') 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 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 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 init = + m_pNode->JSNode()->TryInteger(XFA_Attribute::Initial, false); + iInit = init && *init >= iMin ? *init : iMin; + return true; } -- cgit v1.2.3