Use Optional<> return in CheckStyleFromCaption().
-- Also order case statements by increasing charcode values.
Change-Id: I54812d0b1807acf1b79e255d2c5c324fd8009b56
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66450
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index a0fc3b0..8157314 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1115,27 +1115,26 @@
pImageDict->SetNewFor<CPDF_String>("Name", name, false);
}
-CheckStyle CheckStyleFromCaption(const WideString& caption,
- CheckStyle default_style) {
+Optional<CheckStyle> CheckStyleFromCaption(const WideString& caption) {
if (caption.IsEmpty())
- return default_style;
+ return pdfium::nullopt;
// Character values are ZapfDingbats encodings of named glyphs.
switch (caption[0]) {
case L'4':
return CheckStyle::kCheck;
- case L'l':
- return CheckStyle::kCircle;
case L'8':
return CheckStyle::kCross;
- case L'u':
- return CheckStyle::kDiamond;
- case L'n':
- return CheckStyle::kSquare;
case L'H':
return CheckStyle::kStar;
+ case L'l':
+ return CheckStyle::kCircle;
+ case L'n':
+ return CheckStyle::kSquare;
+ case L'u':
+ return CheckStyle::kDiamond;
default:
- return default_style;
+ return pdfium::nullopt;
}
}
@@ -1381,9 +1380,8 @@
crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}
- CheckStyle nStyle =
- CheckStyleFromCaption(pControl->GetNormalCaption(),
- /*default_style=*/CheckStyle::kCheck);
+ CheckStyle nStyle = CheckStyleFromCaption(pControl->GetNormalCaption())
+ .value_or(CheckStyle::kCheck);
ByteString csAP_N_ON =
GetRectFillAppStream(rcWindow, crBackground) +
GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop,
@@ -1476,9 +1474,8 @@
crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}
- CheckStyle nStyle =
- CheckStyleFromCaption(pControl->GetNormalCaption(),
- /*default_style=*/CheckStyle::kCircle);
+ CheckStyle nStyle = CheckStyleFromCaption(pControl->GetNormalCaption())
+ .value_or(CheckStyle::kCircle);
ByteString csAP_N_ON;
CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f);