Make CFX_UTF8Decoder easier to use.

Instead of making the caller feed it one byte of input at a time via
Input(), just take all the input as a ByteStringView in the ctor. Then
Input() becomes a private ProcessByte() method.

Change-Id: I28053cd083663b7d9ced8f268da33ff47c718a94
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/102250
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/cfx_utf8decoder.cpp b/core/fxcrt/cfx_utf8decoder.cpp
index cfead8a..e834815 100644
--- a/core/fxcrt/cfx_utf8decoder.cpp
+++ b/core/fxcrt/cfx_utf8decoder.cpp
@@ -8,7 +8,11 @@
 
 #include <utility>
 
-CFX_UTF8Decoder::CFX_UTF8Decoder() = default;
+CFX_UTF8Decoder::CFX_UTF8Decoder(ByteStringView input) {
+  for (char c : input) {
+    ProcessByte(c);
+  }
+}
 
 CFX_UTF8Decoder::~CFX_UTF8Decoder() = default;
 
@@ -20,7 +24,7 @@
   m_Buffer += static_cast<wchar_t>(ch);
 }
 
-void CFX_UTF8Decoder::Input(uint8_t byte) {
+void CFX_UTF8Decoder::ProcessByte(uint8_t byte) {
   if (byte < 0x80) {
     m_PendingBytes = 0;
     AppendCodePoint(byte);
diff --git a/core/fxcrt/cfx_utf8decoder.h b/core/fxcrt/cfx_utf8decoder.h
index 9e5ec55..35b5671 100644
--- a/core/fxcrt/cfx_utf8decoder.h
+++ b/core/fxcrt/cfx_utf8decoder.h
@@ -7,17 +7,18 @@
 #ifndef CORE_FXCRT_CFX_UTF8DECODER_H_
 #define CORE_FXCRT_CFX_UTF8DECODER_H_
 
+#include "core/fxcrt/string_view_template.h"
 #include "core/fxcrt/widestring.h"
 
 class CFX_UTF8Decoder {
  public:
-  CFX_UTF8Decoder();
+  explicit CFX_UTF8Decoder(ByteStringView input);
   ~CFX_UTF8Decoder();
 
-  void Input(uint8_t byte);
   WideString TakeResult();
 
  private:
+  void ProcessByte(uint8_t byte);
   void AppendCodePoint(uint32_t ch);
 
   int m_PendingBytes = 0;
diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp
index e661363..76773a8 100644
--- a/core/fxcrt/fx_string.cpp
+++ b/core/fxcrt/fx_string.cpp
@@ -24,13 +24,7 @@
 }
 
 WideString FX_UTF8Decode(ByteStringView bsStr) {
-  if (bsStr.IsEmpty())
-    return WideString();
-
-  CFX_UTF8Decoder decoder;
-  for (size_t i = 0; i < bsStr.GetLength(); i++)
-    decoder.Input(bsStr[i]);
-
+  CFX_UTF8Decoder decoder(bsStr);
   return decoder.TakeResult();
 }