[code health] Prefer Optional<>::value() to operator*()
Improves readability especially when the underlying type has its own
operator*() method. Rely on built-in operator==() between optional and
underlying type to avoid some calls to value(), but stop short of doing
the same for `>` and `<' comparisons.
Change-Id: I207c79c04e3f4013f07a423decb250a826261cb8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81352
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_stitchfunc.cpp b/core/fpdfapi/page/cpdf_stitchfunc.cpp
index 3e903b7..4f55048 100644
--- a/core/fpdfapi/page/cpdf_stitchfunc.cpp
+++ b/core/fpdfapi/page/cpdf_stitchfunc.cpp
@@ -85,15 +85,14 @@
return false;
if (nOutputs.has_value()) {
- if (nFuncOutputs != *nOutputs)
+ if (nOutputs != nFuncOutputs)
return false;
} else {
nOutputs = nFuncOutputs;
}
-
m_pSubFunctions.push_back(std::move(pFunc));
}
- m_nOutputs = *nOutputs;
+ m_nOutputs = nOutputs.value();
}
m_bounds.reserve(nSubs + 1);
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index a3ea904..a935de2 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -497,8 +497,8 @@
if (!header_offset.has_value())
return kDataError;
- m_parser.m_pSyntax =
- std::make_unique<CPDF_SyntaxParser>(GetValidator(), *header_offset);
+ m_parser.m_pSyntax = std::make_unique<CPDF_SyntaxParser>(
+ GetValidator(), header_offset.value());
m_pLinearized = m_parser.ParseLinearizedHeader();
if (GetValidator()->has_read_problems())
return kDataNotAvailable;
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 03c9bcd..03b70a8 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -121,10 +121,11 @@
const Optional<FX_FILESIZE> header_offset = GetHeaderOffset(validator);
if (!header_offset.has_value())
return false;
- if (validator->GetSize() < *header_offset + kPDFHeaderSize)
+ if (validator->GetSize() < header_offset.value() + kPDFHeaderSize)
return false;
- m_pSyntax = std::make_unique<CPDF_SyntaxParser>(validator, *header_offset);
+ m_pSyntax =
+ std::make_unique<CPDF_SyntaxParser>(validator, header_offset.value());
return ParseFileVersion();
}
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index f3e8403..699d439 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -206,7 +206,7 @@
if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
CPDF_Dictionary* pFonts = pDict->GetDictFor("Font");
if (ValidateFontResourceDict(pFonts)) {
- CPDF_Dictionary* pElement = pFonts->GetDictFor(*csFontNameTag);
+ CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag.value());
if (pElement) {
auto* pData = CPDF_DocPageData::FromDocument(m_pForm->GetDocument());
RetainPtr<CPDF_Font> pFont = pData->GetFont(pElement);
@@ -215,7 +215,7 @@
}
}
}
- RetainPtr<CPDF_Font> pFormFont = m_pForm->GetFormFont(*csFontNameTag);
+ RetainPtr<CPDF_Font> pFormFont = m_pForm->GetFormFont(csFontNameTag.value());
if (pFormFont)
return pFormFont;
@@ -229,7 +229,7 @@
if (!ValidateFontResourceDict(pFonts))
return nullptr;
- CPDF_Dictionary* pElement = pFonts->GetDictFor(*csFontNameTag);
+ CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag.value());
if (!pElement)
return nullptr;
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 9401070..5e22bdd 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -860,7 +860,7 @@
if (!font_name.has_value())
return;
- CPDF_Dictionary* pFontDict = pFont->GetDictFor(*font_name);
+ CPDF_Dictionary* pFontDict = pFont->GetDictFor(font_name.value());
if (!pFontDict)
return;
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index 2c3dd64..0b06dcc 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -941,7 +941,7 @@
if (!font.has_value())
return;
- ByteString font_name = *font;
+ ByteString font_name = font.value();
CFX_Color crText = fpdfdoc::CFXColorFromString(DA);
CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR");
if (!pDRDict)
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index e92efa8..afaafee 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -624,7 +624,7 @@
m_TextBuf.AppendChar(unicode);
if (!formMatrix.IsIdentity())
pGenerateChar->m_Matrix = formMatrix;
- m_CharList.push_back(*pGenerateChar);
+ m_CharList.push_back(pGenerateChar.value());
}
void CPDF_TextPage::ProcessObject() {
@@ -986,7 +986,7 @@
if (!form_matrix.IsIdentity())
pGenerateChar->m_Matrix = form_matrix;
m_TempTextBuf.AppendChar(L' ');
- m_TempCharList.push_back(*pGenerateChar);
+ m_TempCharList.push_back(pGenerateChar.value());
}
break;
}
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index f31f991..c39f2bb 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -141,7 +141,7 @@
size_t pos = 0;
while (pos < word->GetLength()) {
WideString curStr = word->Substr(pos, 1);
- wchar_t curChar = (*word)[pos];
+ wchar_t curChar = word.value()[pos];
if (IsIgnoreSpaceCharacter(curChar)) {
if (pos > 0 && curChar == 0x2019) {
pos++;
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 8327dc3..ee148fd 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -307,9 +307,9 @@
Optional<WideString> ret =
TryVSWPrintf(static_cast<size_t>(maxLen), format, argListCopy);
va_end(argListCopy);
-
if (ret.has_value())
- return *ret;
+ return ret.value();
+
maxLen *= 2;
}
return WideString();
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index e8c8b48..2c3c198 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1208,7 +1208,7 @@
ByteString csNameTag;
Optional<ByteString> font = da.GetFont(&fFontSize);
if (font.has_value())
- csNameTag = *font;
+ csNameTag = font.value();
else
fFontSize = 12.0f;
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index fb35ad8..571d2a4 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -1012,7 +1012,7 @@
if (!bsVal.has_value())
return 0;
- return NulTerminateMaybeCopyAndReturnLength(*bsVal, buffer, length);
+ return NulTerminateMaybeCopyAndReturnLength(bsVal.value(), buffer, length);
}
FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV
diff --git a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
index d24acee..1bc8cd1 100644
--- a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
@@ -72,7 +72,7 @@
if (!code.has_value())
return false;
- context->writeCodeword(*code);
+ context->writeCodeword(code.value());
context->m_pos += 2;
return true;
}
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 27c9b65..0b68642 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -458,7 +458,7 @@
if (!maskPattern.has_value())
return false;
- qrCode->SetMaskPattern(*maskPattern);
+ qrCode->SetMaskPattern(maskPattern.value());
if (!CBC_QRCoderMatrixUtil::BuildMatrix(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(),
qrCode->GetMaskPattern(), matrix.get())) {
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 930b1aa..0281d4d 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -1598,7 +1598,7 @@
Optional<WideString> ret =
pXFANode->JSObject()->TryAttribute(XFA_Attribute::Name, false);
if (ret.has_value())
- wsName = *ret;
+ wsName = ret.value();
}
if (wsName.IsEmpty())
wsName = L"#" + WideString::FromASCII(pNode->GetClassName());
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 0ee7daa..ba55a68 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -210,7 +210,8 @@
Optional<XFA_AttributeValue> item =
XFA_GetAttributeValueByName(wsValue.AsStringView());
SetEnum(eAttr,
- item.has_value() ? *item : *(GetXFANode()->GetDefaultEnum(eAttr)),
+ item.has_value() ? item.value()
+ : GetXFANode()->GetDefaultEnum(eAttr).value(),
bNotify);
break;
}
@@ -266,7 +267,7 @@
Optional<XFA_AttributeValue> value = TryEnum(eAttr, bUseDefault);
if (!value.has_value())
return pdfium::nullopt;
- return WideString::FromASCII(XFA_AttributeValueToName(*value));
+ return WideString::FromASCII(XFA_AttributeValueToName(value.value()));
}
case XFA_AttributeType::CData:
return TryCData(eAttr, bUseDefault);
@@ -275,13 +276,13 @@
Optional<bool> value = TryBoolean(eAttr, bUseDefault);
if (!value.has_value())
return pdfium::nullopt;
- return WideString(*value ? L"1" : L"0");
+ return WideString(value.value() ? L"1" : L"0");
}
case XFA_AttributeType::Integer: {
Optional<int32_t> iValue = TryInteger(eAttr, bUseDefault);
if (!iValue.has_value())
return pdfium::nullopt;
- return WideString::Format(L"%d", *iValue);
+ return WideString::Format(L"%d", iValue.value());
}
case XFA_AttributeType::Measure: {
Optional<CXFA_Measurement> value = TryMeasure(eAttr, bUseDefault);
@@ -614,7 +615,7 @@
Optional<WideString> ret =
TryAttribute(XFA_Attribute::ContentType, false);
if (ret.has_value())
- wsContentType = *ret;
+ wsContentType = ret.value();
if (wsContentType.EqualsASCII("text/html")) {
wsContentType.clear();
SetAttributeByEnum(XFA_Attribute::ContentType, wsContentType, false);
diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp
index a4b4343..67329c5 100644
--- a/xfa/fxfa/cxfa_ffbarcode.cpp
+++ b/xfa/fxfa/cxfa_ffbarcode.cpp
@@ -197,55 +197,55 @@
Optional<WideString> encoding_string = barcode_->GetCharEncoding();
if (encoding_string.has_value()) {
Optional<BC_CHAR_ENCODING> encoding =
- CharEncodingFromString(*encoding_string);
+ CharEncodingFromString(encoding_string.value());
if (encoding.has_value())
- pBarCodeWidget->SetCharEncoding(*encoding);
+ pBarCodeWidget->SetCharEncoding(encoding.value());
}
Optional<bool> calcChecksum = barcode_->GetChecksum();
if (calcChecksum.has_value())
- pBarCodeWidget->SetCalChecksum(*calcChecksum);
+ pBarCodeWidget->SetCalChecksum(calcChecksum.value());
Optional<int32_t> dataLen = barcode_->GetDataLength();
if (dataLen.has_value())
- pBarCodeWidget->SetDataLength(*dataLen);
+ pBarCodeWidget->SetDataLength(dataLen.value());
Optional<char> startChar = barcode_->GetStartChar();
if (startChar.has_value())
- pBarCodeWidget->SetStartChar(*startChar);
+ pBarCodeWidget->SetStartChar(startChar.value());
Optional<char> endChar = barcode_->GetEndChar();
if (endChar.has_value())
- pBarCodeWidget->SetEndChar(*endChar);
+ pBarCodeWidget->SetEndChar(endChar.value());
Optional<int32_t> ecLevel = barcode_->GetECLevel();
if (ecLevel.has_value())
- pBarCodeWidget->SetErrorCorrectionLevel(*ecLevel);
+ pBarCodeWidget->SetErrorCorrectionLevel(ecLevel.value());
Optional<int32_t> width = barcode_->GetModuleWidth();
if (width.has_value())
- pBarCodeWidget->SetModuleWidth(*width);
+ pBarCodeWidget->SetModuleWidth(width.value());
Optional<int32_t> height = barcode_->GetModuleHeight();
if (height.has_value())
- pBarCodeWidget->SetModuleHeight(*height);
+ pBarCodeWidget->SetModuleHeight(height.value());
Optional<bool> printCheck = barcode_->GetPrintChecksum();
if (printCheck.has_value())
- pBarCodeWidget->SetPrintChecksum(*printCheck);
+ pBarCodeWidget->SetPrintChecksum(printCheck.value());
Optional<XFA_AttributeValue> text_attr = barcode_->GetTextLocation();
if (text_attr.has_value()) {
- Optional<BC_TEXT_LOC> textLoc = TextLocFromAttribute(*text_attr);
+ Optional<BC_TEXT_LOC> textLoc = TextLocFromAttribute(text_attr.value());
if (textLoc.has_value())
- pBarCodeWidget->SetTextLocation(*textLoc);
+ pBarCodeWidget->SetTextLocation(textLoc.value());
}
// Truncated is currently not a supported flag.
Optional<int8_t> ratio = barcode_->GetWideNarrowRatio();
if (ratio.has_value())
- pBarCodeWidget->SetWideNarrowRatio(*ratio);
+ pBarCodeWidget->SetWideNarrowRatio(ratio.value());
if (info->eName == BarcodeType::code3Of9 ||
info->eName == BarcodeType::ean8 || info->eName == BarcodeType::ean13 ||
diff --git a/xfa/fxfa/cxfa_ffdatetimeedit.cpp b/xfa/fxfa/cxfa_ffdatetimeedit.cpp
index 0cd34ee..f3f05be 100644
--- a/xfa/fxfa/cxfa_ffdatetimeedit.cpp
+++ b/xfa/fxfa/cxfa_ffdatetimeedit.cpp
@@ -93,9 +93,9 @@
uint32_t dwEditStyles = 0;
Optional<int32_t> numCells = m_pNode->GetNumberOfCells();
- if (numCells.has_value() && *numCells > 0) {
+ if (numCells.has_value() && numCells.value() > 0) {
dwEditStyles |= FWL_STYLEEXT_EDT_CombText;
- pPicker->SetEditLimit(*numCells);
+ pPicker->SetEditLimit(numCells.value());
}
if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive())
dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;
diff --git a/xfa/fxfa/cxfa_ffnumericedit.cpp b/xfa/fxfa/cxfa_ffnumericedit.cpp
index 2067ffa..1af3cdc 100644
--- a/xfa/fxfa/cxfa_ffnumericedit.cpp
+++ b/xfa/fxfa/cxfa_ffnumericedit.cpp
@@ -56,9 +56,9 @@
dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
Optional<int32_t> numCells = m_pNode->GetNumberOfCells();
- if (numCells.has_value() && *numCells > 0) {
+ if (numCells.has_value() && numCells.value() > 0) {
dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
- pWidget->SetLimit(*numCells);
+ pWidget->SetLimit(numCells.value());
}
dwExtendedStyle |= GetAlignment();
if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive())
diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp
index 6d357c6..131bf6c 100644
--- a/xfa/fxfa/cxfa_ffpageview.cpp
+++ b/xfa/fxfa/cxfa_ffpageview.cpp
@@ -432,7 +432,7 @@
Optional<WideString> traverseWidgetName =
pTraverse->JSObject()->TryAttribute(XFA_Attribute::Ref, true);
if (traverseWidgetName.has_value())
- return FindWidgetByName(*traverseWidgetName, pWidget);
+ return FindWidgetByName(traverseWidgetName.value(), pWidget);
}
}
return nullptr;
diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp
index 5c0b665..4f86541 100644
--- a/xfa/fxfa/cxfa_fftextedit.cpp
+++ b/xfa/fxfa/cxfa_fftextedit.cpp
@@ -105,12 +105,12 @@
Optional<int32_t> numCells = m_pNode->GetNumberOfCells();
if (!numCells.has_value()) {
pWidget->SetLimit(iMaxChars);
- } else if (*numCells == 0) {
+ } else if (numCells == 0) {
dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1);
} else {
dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
- pWidget->SetLimit(*numCells);
+ pWidget->SetLimit(numCells.value());
}
dwExtendedStyle |= GetAlignment();
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index c760d47..71e638a 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -813,7 +813,7 @@
Optional<WideString> obj =
m_pTextParser->GetEmbeddedObj(m_pTextProvider, pXMLNode);
if (obj.has_value())
- wsText = *obj;
+ wsText = obj.value();
}
}
diff --git a/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp
index db1618c..8f0d030 100644
--- a/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp
@@ -341,7 +341,7 @@
Optional<XFA_AttributeValue> layoutMode =
pFormNode->JSObject()->TryEnum(XFA_Attribute::Layout, false);
if (layoutMode.has_value())
- return *layoutMode;
+ return layoutMode.value();
CXFA_Node* pParentNode = pFormNode->GetParent();
if (pParentNode && pParentNode->GetElementType() == XFA_Element::Form) {
@@ -369,11 +369,9 @@
Optional<XFA_AttributeValue> previous =
pKeep->JSObject()->TryEnum(eKeepType, false);
- if (previous.has_value()) {
- if (*previous == XFA_AttributeValue::ContentArea ||
- *previous == XFA_AttributeValue::PageArea) {
- return true;
- }
+ if (previous == XFA_AttributeValue::ContentArea ||
+ previous == XFA_AttributeValue::PageArea) {
+ return true;
}
}
@@ -387,10 +385,8 @@
Optional<XFA_AttributeValue> next =
pKeep->JSObject()->TryEnum(eKeepType, false);
- if (!next.has_value())
- return false;
- if (*next == XFA_AttributeValue::ContentArea ||
- *next == XFA_AttributeValue::PageArea) {
+ if (next == XFA_AttributeValue::ContentArea ||
+ next == XFA_AttributeValue::PageArea) {
return true;
}
return false;
diff --git a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
index f207e8c..1525abb 100644
--- a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
@@ -1157,7 +1157,7 @@
Optional<int32_t> ret =
pOccurNode->JSObject()->TryInteger(XFA_Attribute::Max, false);
if (ret.has_value())
- iMax = *ret;
+ iMax = ret.value();
}
if (iMax >= 0 && iMax <= iPageSetCount)
return false;
@@ -1325,11 +1325,11 @@
Optional<XFA_AttributeValue> ret =
pPageArea->JSObject()->TryEnum(XFA_Attribute::OddOrEven, true);
- if (!ret.has_value() || *ret == XFA_AttributeValue::Any)
+ if (!ret.has_value() || ret == XFA_AttributeValue::Any)
return true;
int32_t iPageLast = GetPageCount() % 2;
- return *ret == XFA_AttributeValue::Odd ? iPageLast == 0 : iPageLast == 1;
+ return ret == XFA_AttributeValue::Odd ? iPageLast == 0 : iPageLast == 1;
}
CXFA_Node* CXFA_ViewLayoutProcessor::GetNextAvailPageArea(
@@ -1355,7 +1355,7 @@
Optional<int32_t> ret =
pOccurNode->JSObject()->TryInteger(XFA_Attribute::Max, false);
if (ret.has_value())
- iMax = *ret;
+ iMax = ret.value();
}
if ((iMax < 0 || m_nCurPageCount < iMax)) {
if (!bQuery) {
@@ -1462,7 +1462,7 @@
if (pOccurNode) {
ret = pOccurNode->JSObject()->TryInteger(XFA_Attribute::Min, false);
if (ret.has_value())
- iMin = *ret;
+ iMin = ret.value();
}
if (!ret.has_value() && !bTargetPageArea)
@@ -1502,10 +1502,10 @@
Optional<int32_t> iMin =
pOccurNode->JSObject()->TryInteger(XFA_Attribute::Min, false);
- if (!iMin.has_value() || iCurSetCount >= *iMin)
+ if (!iMin.has_value() || iCurSetCount >= iMin.value())
return;
- for (int32_t i = 0; i < *iMin - iCurSetCount; i++) {
+ for (int32_t i = 0; i < iMin.value() - iCurSetCount; i++) {
for (CXFA_Node* node = pPageSet->GetFirstChild(); node;
node = node->GetNextSibling()) {
if (node->GetElementType() == XFA_Element::PageArea)
@@ -1514,7 +1514,7 @@
CreateMinPageSetRecord(node, true);
}
}
- m_pPageSetMap[pPageSet] = *iMin;
+ m_pPageSetMap[pPageSet] = iMin.value();
}
void CXFA_ViewLayoutProcessor::CreateNextMinRecord(CXFA_Node* pRecordNode) {
@@ -1569,7 +1569,7 @@
if (pOccurNode) {
ret = pOccurNode->JSObject()->TryInteger(XFA_Attribute::Max, false);
if (ret.has_value())
- iMax = *ret;
+ iMax = ret.value();
}
if (ret.has_value()) {
if (m_nCurPageCount == iMax) {
diff --git a/xfa/fxfa/parser/cxfa_barcode.cpp b/xfa/fxfa/parser/cxfa_barcode.cpp
index 4fc004c..bfa295d 100644
--- a/xfa/fxfa/parser/cxfa_barcode.cpp
+++ b/xfa/fxfa/parser/cxfa_barcode.cpp
@@ -74,7 +74,7 @@
if (!checksum.has_value())
return pdfium::nullopt;
- switch (*checksum) {
+ switch (checksum.value()) {
case XFA_AttributeValue::None:
return {false};
case XFA_AttributeValue::Auto:
@@ -103,7 +103,7 @@
if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
return pdfium::nullopt;
- return static_cast<char>((*wsStartEndChar)[0]);
+ return static_cast<char>(wsStartEndChar.value()[0]);
}
Optional<char> CXFA_Barcode::GetEndChar() {
@@ -112,7 +112,7 @@
if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
return pdfium::nullopt;
- return static_cast<char>((*wsStartEndChar)[0]);
+ return static_cast<char>(wsStartEndChar.value()[0]);
}
Optional<int32_t> CXFA_Barcode::GetECLevel() {
@@ -164,12 +164,13 @@
return static_cast<int8_t>(FXSYS_wtoi(wsWideNarrowRatio->c_str()));
int32_t fB = FXSYS_wtoi(
- wsWideNarrowRatio->Last(wsWideNarrowRatio->GetLength() - (*ptPos + 1))
+ wsWideNarrowRatio
+ ->Last(wsWideNarrowRatio->GetLength() - (ptPos.value() + 1))
.c_str());
if (!fB)
return 0;
- int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->First(*ptPos).c_str());
+ int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->First(ptPos.value()).c_str());
float result = static_cast<float>(fA) / static_cast<float>(fB);
return static_cast<int8_t>(result);
}
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 99008b2..aab083c 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -1348,7 +1348,7 @@
pDatasetsNode->JSObject()->TryNamespace();
if (!datasetsURI.has_value())
continue;
- if (*namespaceURI == *datasetsURI)
+ if (namespaceURI.value() == datasetsURI.value())
return pDatasetsChild;
}
return nullptr;
@@ -1692,7 +1692,7 @@
pChildNode->JSObject()->TryNamespace();
if (!namespaceURI.has_value())
continue;
- if (*namespaceURI == wsDatasetsURI)
+ if (namespaceURI == wsDatasetsURI)
pDataRoot = pChildNode;
}
if (pDataRoot && pDDRoot)
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 9fb983c..712c7ef 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1453,7 +1453,7 @@
if (pKeep) {
Optional<XFA_AttributeValue> intact = GetIntactFromKeep(pKeep, eLayoutType);
if (intact.has_value())
- return *intact;
+ return intact.value();
}
switch (GetElementType()) {
@@ -2022,14 +2022,14 @@
Optional<void*> value = GetDefaultValue(attr, XFA_AttributeType::Boolean);
if (!value.has_value())
return pdfium::nullopt;
- return !!*value;
+ return !!value.value();
}
Optional<int32_t> CXFA_Node::GetDefaultInteger(XFA_Attribute attr) const {
Optional<void*> value = GetDefaultValue(attr, XFA_AttributeType::Integer);
if (!value.has_value())
return pdfium::nullopt;
- return static_cast<int32_t>(reinterpret_cast<uintptr_t>(*value));
+ return static_cast<int32_t>(reinterpret_cast<uintptr_t>(value.value()));
}
Optional<CXFA_Measurement> CXFA_Node::GetDefaultMeasurement(
@@ -2038,7 +2038,7 @@
if (!value.has_value())
return pdfium::nullopt;
- WideString str = WideString(static_cast<const wchar_t*>(*value));
+ WideString str = WideString(static_cast<const wchar_t*>(value.value()));
return CXFA_Measurement(str.AsStringView());
}
@@ -2047,7 +2047,7 @@
if (!value.has_value())
return pdfium::nullopt;
- return WideString(static_cast<const wchar_t*>(*value));
+ return WideString(static_cast<const wchar_t*>(value.value()));
}
Optional<XFA_AttributeValue> CXFA_Node::GetDefaultEnum(
@@ -2055,7 +2055,8 @@
Optional<void*> value = GetDefaultValue(attr, XFA_AttributeType::Enum);
if (!value.has_value())
return pdfium::nullopt;
- return static_cast<XFA_AttributeValue>(reinterpret_cast<uintptr_t>(*value));
+ return static_cast<XFA_AttributeValue>(
+ reinterpret_cast<uintptr_t>(value.value()));
}
Optional<void*> CXFA_Node::GetDefaultValue(XFA_Attribute attr,
@@ -2229,7 +2230,7 @@
int32_t CXFA_Node::GetRotate() const {
Optional<int32_t> degrees =
JSObject()->TryInteger(XFA_Attribute::Rotate, false);
- return degrees.has_value() ? XFA_MapRotation(*degrees) / 90 * 90 : 0;
+ return degrees.has_value() ? XFA_MapRotation(degrees.value()) / 90 * 90 : 0;
}
CXFA_Border* CXFA_Node::GetBorderIfExists() const {
@@ -2341,8 +2342,8 @@
Optional<XFA_AttributeValue> value =
pKeep->JSObject()->TryEnum(XFA_Attribute::Previous, false);
- if (value.has_value() && (*value == XFA_AttributeValue::ContentArea ||
- *value == XFA_AttributeValue::PageArea)) {
+ if (value == XFA_AttributeValue::ContentArea ||
+ value == XFA_AttributeValue::PageArea) {
return XFA_AttributeValue::ContentArea;
}
@@ -2353,13 +2354,11 @@
Optional<XFA_AttributeValue> ret =
pNode->JSObject()->TryEnum(XFA_Attribute::Next, false);
- if (!ret.has_value())
- return intact;
-
- return (*ret == XFA_AttributeValue::ContentArea ||
- *ret == XFA_AttributeValue::PageArea)
- ? XFA_AttributeValue::ContentArea
- : intact;
+ if (ret == XFA_AttributeValue::ContentArea ||
+ ret == XFA_AttributeValue::PageArea) {
+ return XFA_AttributeValue::ContentArea;
+ }
+ return intact;
}
Optional<float> CXFA_Node::TryWidth() {
@@ -3242,28 +3241,28 @@
Optional<float> width = TryWidth();
if (width.has_value()) {
- pSize->width = *width;
+ pSize->width = width.value();
} else {
Optional<float> min = TryMinWidth();
if (min.has_value())
- pSize->width = std::max(pSize->width, *min);
+ pSize->width = std::max(pSize->width, min.value());
Optional<float> max = TryMaxWidth();
- if (max.has_value() && *max > 0)
- pSize->width = std::min(pSize->width, *max);
+ if (max.has_value() && max.value() > 0)
+ pSize->width = std::min(pSize->width, max.value());
}
Optional<float> height = TryHeight();
if (height.has_value()) {
- pSize->height = *height;
+ pSize->height = height.value();
} else {
Optional<float> min = TryMinHeight();
if (min.has_value())
- pSize->height = std::max(pSize->height, *min);
+ pSize->height = std::max(pSize->height, min.value());
Optional<float> max = TryMaxHeight();
- if (max.has_value() && *max > 0)
- pSize->height = std::min(pSize->height, *max);
+ if (max.has_value() && max.value() > 0)
+ pSize->height = std::min(pSize->height, max.value());
}
return true;
}
@@ -3372,7 +3371,7 @@
CFX_RectF rtFit;
Optional<float> width = TryWidth();
if (width.has_value()) {
- rtFit.width = *width;
+ rtFit.width = width.value();
GetWidthWithoutMargin(rtFit.width);
} else {
rtFit.width = rtImage.width;
@@ -3380,7 +3379,7 @@
Optional<float> height = TryHeight();
if (height.has_value()) {
- rtFit.height = *height;
+ rtFit.height = height.value();
GetHeightWithoutMargin(rtFit.height);
} else {
rtFit.height = rtImage.height;
@@ -3446,11 +3445,11 @@
Optional<float> min = TryMinWidth();
if (min.has_value())
- fWidthCalc = std::max(fWidthCalc, *min);
+ fWidthCalc = std::max(fWidthCalc, min.value());
Optional<float> max = TryMaxWidth();
- if (max.has_value() && *max > 0)
- fWidthCalc = std::min(fWidthCalc, *max);
+ if (max.has_value() && max.value() > 0)
+ fWidthCalc = std::min(fWidthCalc, max.value());
return fWidthCalc;
}
@@ -3469,11 +3468,11 @@
Optional<float> min = TryMinHeight();
if (min.has_value())
- fHeightCalc = std::max(fHeightCalc, *min);
+ fHeightCalc = std::max(fHeightCalc, min.value());
Optional<float> max = TryMaxHeight();
- if (max.has_value() && *max > 0)
- fHeightCalc = std::min(fHeightCalc, *max);
+ if (max.has_value() && max.value() > 0)
+ fHeightCalc = std::min(fHeightCalc, max.value());
return fHeightCalc;
}
@@ -3503,7 +3502,7 @@
if (*pCalcWidth > 0 && *pCalcHeight < 0) {
Optional<float> height = TryHeight();
if (height.has_value()) {
- *pCalcHeight = *height;
+ *pCalcHeight = height.value();
} else {
CFX_SizeF size = CalculateAccWidthAndHeight(doc, *pCalcWidth);
*pCalcWidth = size.width;
@@ -3517,10 +3516,10 @@
Optional<float> height;
Optional<float> width = TryWidth();
if (width.has_value()) {
- fWidth = *width;
+ fWidth = width.value();
height = TryHeight();
if (height.has_value())
- *pCalcHeight = *height;
+ *pCalcHeight = height.value();
}
if (!width.has_value() || !height.has_value()) {
CFX_SizeF size = CalculateAccWidthAndHeight(doc, fWidth);
@@ -3855,8 +3854,8 @@
if (*pCalcWidth < 0 && *pCalcHeight < 0) {
Optional<float> width = TryWidth();
if (width.has_value()) {
- pTextLayout->StartLayout(GetWidthWithoutMargin(*width));
- *pCalcWidth = *width;
+ pTextLayout->StartLayout(GetWidthWithoutMargin(width.value()));
+ *pCalcWidth = width.value();
} else {
float fMaxWidth = CalculateWidgetAutoWidth(pTextLayout->StartLayout(-1));
pTextLayout->StartLayout(GetWidthWithoutMargin(fMaxWidth));
@@ -3987,7 +3986,7 @@
int32_t i = 0;
while (pText) {
Optional<WideString> wsContent = pText->JSObject()->TryContent(false, true);
- if (wsContent.has_value() && *wsContent == wsValue)
+ if (wsContent == wsValue)
return static_cast<XFA_CheckState>(i);
i++;
@@ -4722,7 +4721,7 @@
Optional<WideString> picture =
pPicture->JSObject()->TryContent(false, true);
if (picture.has_value())
- return *picture;
+ return picture.value();
}
}
@@ -4757,7 +4756,7 @@
Optional<WideString> picture =
pPicture->JSObject()->TryContent(false, true);
if (picture.has_value())
- return *picture;
+ return picture.value();
}
}
diff --git a/xfa/fxfa/parser/cxfa_occur.cpp b/xfa/fxfa/parser/cxfa_occur.cpp
index a9281bc..d07f8c3 100644
--- a/xfa/fxfa/parser/cxfa_occur.cpp
+++ b/xfa/fxfa/parser/cxfa_occur.cpp
@@ -42,12 +42,12 @@
int32_t CXFA_Occur::GetMax() {
Optional<int32_t> max = JSObject()->TryInteger(XFA_Attribute::Max, true);
- return max.has_value() ? *max : GetMin();
+ return max.has_value() ? max.value() : GetMin();
}
int32_t CXFA_Occur::GetMin() {
Optional<int32_t> min = JSObject()->TryInteger(XFA_Attribute::Min, true);
- return min.has_value() && *min >= 0 ? *min : 1;
+ return min.has_value() && min.value() >= 0 ? min.value() : 1;
}
std::tuple<int32_t, int32_t, int32_t> CXFA_Occur::GetOccurInfo() {
@@ -56,7 +56,8 @@
Optional<int32_t> init =
JSObject()->TryInteger(XFA_Attribute::Initial, false);
- return {iMin, iMax, init.has_value() && *init >= iMin ? *init : iMin};
+ return {iMin, iMax,
+ init.has_value() && init.value() >= iMin ? init.value() : iMin};
}
void CXFA_Occur::SetMax(int32_t iMax) {
diff --git a/xfa/fxfa/parser/cxfa_validate.cpp b/xfa/fxfa/parser/cxfa_validate.cpp
index 44e8cd8..4b65bbc 100644
--- a/xfa/fxfa/parser/cxfa_validate.cpp
+++ b/xfa/fxfa/parser/cxfa_validate.cpp
@@ -64,9 +64,9 @@
void CXFA_Validate::SetNullTest(const WideString& wsValue) {
Optional<XFA_AttributeValue> item =
XFA_GetAttributeValueByName(wsValue.AsStringView());
- JSObject()->SetEnum(XFA_Attribute::NullTest,
- item.has_value() ? *item : XFA_AttributeValue::Disabled,
- false);
+ JSObject()->SetEnum(
+ XFA_Attribute::NullTest,
+ item.has_value() ? item.value() : XFA_AttributeValue::Disabled, false);
}
XFA_AttributeValue CXFA_Validate::GetNullTest() {
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 580b333..b0ea770 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -148,7 +148,7 @@
wsOutput += L" ";
wsOutput += wsName;
wsOutput += L"=\"";
- wsOutput += ExportEncodeAttribute(*value);
+ wsOutput += ExportEncodeAttribute(value.value());
wsOutput += L"\"";
}
@@ -366,7 +366,8 @@
return WideString();
XFA_VERSION eVersion =
- pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(*templateNS);
+ pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(
+ templateNS.value());
if (eVersion == XFA_VERSION_UNKNOWN)
eVersion = XFA_VERSION_DEFAULT;