From 8873a4dffed0ae3ccd961ada58c588f92b210bf2 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Nov 2017 14:19:07 +0000 Subject: Convert TryBoolean to return a pdfium::Optional This CL changes CJX_Node::TryBoolean to return a pdfium::Optional instead of a bool with an out parameter. Change-Id: Iceeaaaa5bda62f34e66161834e0209c2169f7f15 Reviewed-on: https://pdfium-review.googlesource.com/18530 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cjx_node.cpp | 27 ++++++++++----------------- fxjs/cjx_node.h | 2 +- xfa/fxfa/parser/cxfa_widgetdata.cpp | 16 ++++++++-------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 7ebf5da25b..e207ae488d 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -288,10 +288,10 @@ pdfium::Optional CJX_Node::TryAttribute(XFA_Attribute eAttr, return TryCData(pAttr->eName, bUseDefault); case XFA_AttributeType::Boolean: { - bool bValue; - if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) + pdfium::Optional value = TryBoolean(pAttr->eName, bUseDefault); + if (!value) return {}; - return {bValue ? L"1" : L"0"}; + return {*value ? L"1" : L"0"}; } case XFA_AttributeType::Integer: { pdfium::Optional iValue = TryInteger(pAttr->eName, bUseDefault); @@ -2995,22 +2995,16 @@ void CJX_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) {} -bool CJX_Node::TryBoolean(XFA_Attribute eAttr, bool& bValue, bool bUseDefault) { +pdfium::Optional CJX_Node::TryBoolean(XFA_Attribute eAttr, + bool bUseDefault) { void* pValue = nullptr; void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr); - if (GetMapModuleValue(pKey, pValue)) { - bValue = !!pValue; - return true; - } + if (GetMapModuleValue(pKey, pValue)) + return {!!pValue}; if (!bUseDefault) - return false; - - pdfium::Optional ret = GetXFANode()->GetDefaultBoolean(eAttr); - if (!ret) - return false; + return {}; - bValue = *ret; - return true; + return GetXFANode()->GetDefaultBoolean(eAttr); } bool CJX_Node::SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify) { @@ -3019,8 +3013,7 @@ bool CJX_Node::SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify) { } bool CJX_Node::GetBoolean(XFA_Attribute eAttr) { - bool bValue; - return TryBoolean(eAttr, bValue, true) ? bValue : false; + return TryBoolean(eAttr, true).value_or(false); } bool CJX_Node::SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify) { diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h index 81af0dfe73..8cf167938c 100644 --- a/fxjs/cjx_node.h +++ b/fxjs/cjx_node.h @@ -88,7 +88,7 @@ class CJX_Node : public CJX_Object { bool SetEnum(XFA_Attribute eAttr, XFA_ATTRIBUTEENUM eValue, bool bNotify); XFA_ATTRIBUTEENUM GetEnum(XFA_Attribute eAttr); - bool TryBoolean(XFA_Attribute eAttr, bool& bValue, bool bUseDefault); + pdfium::Optional TryBoolean(XFA_Attribute eAttr, bool bUseDefault); bool SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify); bool GetBoolean(XFA_Attribute eAttr); diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index 9613383879..5dd680ab8c 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -1226,10 +1226,10 @@ bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) { } bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) { - bool bPrintCheckDigit; - if (GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, - bPrintCheckDigit, true)) { - *val = bPrintCheckDigit; + pdfium::Optional printCheckDigit = + GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, true); + if (printCheckDigit) { + *val = *printCheckDigit; return true; } return false; @@ -1264,12 +1264,12 @@ bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t* val) { } bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool* val) { - bool bTruncate; - if (!GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, bTruncate, - true)) + pdfium::Optional truncate = + GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true); + if (!truncate) return false; - *val = bTruncate; + *val = *truncate; return true; } -- cgit v1.2.3