summaryrefslogtreecommitdiff
path: root/fxjs/cjx_node.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 14:19:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 14:19:07 +0000
commit8873a4dffed0ae3ccd961ada58c588f92b210bf2 (patch)
tree86472d2a7769467cabbcb9f1fdc71129b97d0c7d /fxjs/cjx_node.cpp
parent9d608ff14177cd665f6b2ead639415bda935fbe2 (diff)
downloadpdfium-8873a4dffed0ae3ccd961ada58c588f92b210bf2.tar.xz
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 <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjx_node.cpp')
-rw-r--r--fxjs/cjx_node.cpp27
1 files changed, 10 insertions, 17 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<WideString> 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<bool> 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<int32_t> 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<bool> 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<bool> 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) {