Deduplicate a switch statement in cpdfsdk_appstream.cpp.

Introduce CheckStateFromCaption() helper function.

Change-Id: I6d9d462dc8bc020079d4978ab306185bc9b75d56
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66330
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index b6600d2..89b8d19 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1115,6 +1115,28 @@
   pImageDict->SetNewFor<CPDF_String>("Name", name, false);
 }
 
+CheckStyle CheckStyleFromCaption(const WideString& wsCaption) {
+  if (wsCaption.IsEmpty())
+    return CheckStyle::kCheck;
+
+  // Character values are ZapfDingbats encodings of named glyphs.
+  switch (wsCaption[0]) {
+    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'4':
+    default:
+      return CheckStyle::kCheck;
+  }
+}
+
 }  // namespace
 
 CPDFSDK_AppStream::CPDFSDK_AppStream(CPDFSDK_Widget* widget,
@@ -1357,31 +1379,7 @@
     crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
   }
 
-  CheckStyle nStyle = CheckStyle::kCheck;
-  WideString csWCaption = pControl->GetNormalCaption();
-  if (csWCaption.GetLength() > 0) {
-    switch (csWCaption[0]) {
-      case L'l':
-        nStyle = CheckStyle::kCircle;
-        break;
-      case L'8':
-        nStyle = CheckStyle::kCross;
-        break;
-      case L'u':
-        nStyle = CheckStyle::kDiamond;
-        break;
-      case L'n':
-        nStyle = CheckStyle::kSquare;
-        break;
-      case L'H':
-        nStyle = CheckStyle::kStar;
-        break;
-      case L'4':
-      default:
-        nStyle = CheckStyle::kCheck;
-    }
-  }
-
+  CheckStyle nStyle = CheckStyleFromCaption(pControl->GetNormalCaption());
   ByteString csAP_N_ON =
       GetRectFillAppStream(rcWindow, crBackground) +
       GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop,
@@ -1474,30 +1472,7 @@
     crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
   }
 
-  CheckStyle nStyle = CheckStyle::kCircle;
-  WideString csWCaption = pControl->GetNormalCaption();
-  if (csWCaption.GetLength() > 0) {
-    switch (csWCaption[0]) {
-      case L'8':
-        nStyle = CheckStyle::kCross;
-        break;
-      case L'u':
-        nStyle = CheckStyle::kDiamond;
-        break;
-      case L'n':
-        nStyle = CheckStyle::kSquare;
-        break;
-      case L'H':
-        nStyle = CheckStyle::kStar;
-        break;
-      case L'4':
-        nStyle = CheckStyle::kCheck;
-        break;
-      case L'l':
-      default:
-        nStyle = CheckStyle::kCircle;
-    }
-  }
+  CheckStyle nStyle = CheckStyleFromCaption(pControl->GetNormalCaption());
 
   ByteString csAP_N_ON;
   CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f);