Convert ByteString::{Format|FormatV} to static methods

This CL moves the Format and FormatV methods of ByteString to be static.

Bug: pdfium:934
Change-Id: I9c30455a789aff9f619b9d5bf89c0712644f2d9a
Reviewed-on: https://pdfium-review.googlesource.com/18650
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 590229b..db5bd68 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -556,15 +556,15 @@
         j++;
 
       if (i == 1)
-        str.Format("0 %d\r\n0000000000 65535 f\r\n", j);
+        str = ByteString::Format("0 %d\r\n0000000000 65535 f\r\n", j);
       else
-        str.Format("%d %d\r\n", i, j - i);
+        str = ByteString::Format("%d %d\r\n", i, j - i);
 
       if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
         return -1;
 
       while (i < j) {
-        str.Format("%010d 00000 n\r\n", m_ObjectOffsets[i++]);
+        str = ByteString::Format("%010d 00000 n\r\n", m_ObjectOffsets[i++]);
         if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
           return -1;
       }
@@ -590,16 +590,16 @@
       }
       objnum = m_NewObjNumArray[i];
       if (objnum == 1)
-        str.Format("0 %d\r\n0000000000 65535 f\r\n", j - i + 1);
+        str = ByteString::Format("0 %d\r\n0000000000 65535 f\r\n", j - i + 1);
       else
-        str.Format("%d %d\r\n", objnum, j - i);
+        str = ByteString::Format("%d %d\r\n", objnum, j - i);
 
       if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
         return -1;
 
       while (i < j) {
         objnum = m_NewObjNumArray[i++];
-        str.Format("%010d 00000 n\r\n", m_ObjectOffsets[objnum]);
+        str = ByteString::Format("%010d 00000 n\r\n", m_ObjectOffsets[objnum]);
         if (!m_Archive->WriteBlock(str.c_str(), str.GetLength()))
           return -1;
       }
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 593680e..8a08a84 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -138,10 +138,10 @@
   ByteString name;
   int idnum = 1;
   while (1) {
-    name.Format("FX%c%d", bsType[0], idnum);
-    if (!pResList->KeyExist(name)) {
+    name = ByteString::Format("FX%c%d", bsType[0], idnum);
+    if (!pResList->KeyExist(name))
       break;
-    }
+
     idnum++;
   }
   pResList->SetNewFor<CPDF_Reference>(name, m_pDocument.Get(),
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index 7d4067b..5e24c5f 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -101,10 +101,8 @@
   ByteString csOn = GetOnStateName();
   if (GetType() == CPDF_FormField::RadioButton ||
       GetType() == CPDF_FormField::CheckBox) {
-    if (ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt"))) {
-      int iIndex = m_pField->GetControlIndex(this);
-      csOn.Format("%d", iIndex);
-    }
+    if (ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt")))
+      csOn = ByteString::Format("%d", m_pField->GetControlIndex(this));
   }
   if (csOn.IsEmpty())
     csOn = "Yes";
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 637cb9e..395b5c5 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -749,9 +749,7 @@
         m_pDict->SetNewFor<CPDF_Name>("V", "Off");
     }
   } else if (bChecked) {
-    ByteString csIndex;
-    csIndex.Format("%d", iControlIndex);
-    m_pDict->SetNewFor<CPDF_Name>("V", csIndex);
+    m_pDict->SetNewFor<CPDF_Name>("V", ByteString::Format("%d", iControlIndex));
   }
   if (bNotify && m_pForm->GetFormNotify())
     m_pForm->GetFormNotify()->AfterCheckedStatusChange(this);
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 50db639..e42095c 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -717,7 +717,7 @@
     if (m < iCount)
       csTmp += csStr[m++];
     else
-      bsNum.Format("%d", num++);
+      bsNum = ByteString::Format("%d", num++);
 
     m++;
   }
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index c7b551f..c0f9927 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -44,25 +44,25 @@
                             int32_t nFontIndex,
                             uint16_t Word,
                             uint16_t SubWord) {
-  ByteString sWord;
-  if (SubWord > 0) {
-    sWord.Format("%c", SubWord);
-    return sWord;
-  }
+  if (SubWord > 0)
+    return ByteString::Format("%c", SubWord);
 
   if (!pFontMap)
-    return sWord;
+    return "";
 
-  if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
-    if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
-        pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
-      sWord.Format("%c", Word);
-    } else {
-      uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
-      if (dwCharCode != CPDF_Font::kInvalidCharCode)
-        pPDFFont->AppendChar(&sWord, dwCharCode);
-    }
+  CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex);
+  if (!pPDFFont)
+    return "";
+
+  if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
+      pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
+    return ByteString::Format("%c", Word);
   }
+
+  ByteString sWord;
+  uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
+  if (dwCharCode != CPDF_Font::kInvalidCharCode)
+    pPDFFont->AppendChar(&sWord, dwCharCode);
   return sWord;
 }
 
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index ad3814b..e868678 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -91,6 +91,57 @@
 static_assert(sizeof(ByteString) <= sizeof(char*),
               "Strings must not require more space than pointers");
 
+#define FORCE_ANSI 0x10000
+#define FORCE_UNICODE 0x20000
+#define FORCE_INT64 0x40000
+
+// static
+ByteString ByteString::FormatInteger(int i) {
+  char buf[32];
+  FXSYS_snprintf(buf, 32, "%d", i);
+  return ByteString(buf);
+}
+
+// static
+ByteString ByteString::FormatFloat(float d) {
+  char buf[32];
+  return ByteString(buf, FX_ftoa(d, buf));
+}
+
+// static
+ByteString ByteString::FormatV(const char* pFormat, va_list argList) {
+  va_list argListCopy;
+  va_copy(argListCopy, argList);
+  int nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy);
+  va_end(argListCopy);
+
+  if (nMaxLen <= 0)
+    return "";
+
+  ByteString ret;
+  char* buf = ret.GetBuffer(nMaxLen);
+  if (buf) {
+    // In the following two calls, there's always space in the buffer for
+    // a terminating NUL that's not included in nMaxLen.
+    memset(buf, 0, nMaxLen + 1);
+    va_copy(argListCopy, argList);
+    vsnprintf(buf, nMaxLen + 1, pFormat, argListCopy);
+    va_end(argListCopy);
+    ret.ReleaseBuffer(ret.GetStringLength());
+  }
+  return ret;
+}
+
+// static
+ByteString ByteString::Format(const char* pFormat, ...) {
+  va_list argList;
+  va_start(argList, pFormat);
+  ByteString ret = FormatV(pFormat, argList);
+  va_end(argList);
+
+  return ret;
+}
+
 ByteString::ByteString(const char* pStr, size_t nLen) {
   if (nLen)
     m_pData.Reset(StringData::Create(pStr, nLen));
@@ -485,42 +536,6 @@
   dest.m_pData.Swap(pNewData);
 }
 
-#define FORCE_ANSI 0x10000
-#define FORCE_UNICODE 0x20000
-#define FORCE_INT64 0x40000
-
-ByteString ByteString::FormatInteger(int i) {
-  char buf[32];
-  FXSYS_snprintf(buf, 32, "%d", i);
-  return ByteString(buf);
-}
-
-void ByteString::FormatV(const char* pFormat, va_list argList) {
-  va_list argListCopy;
-  va_copy(argListCopy, argList);
-  int nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy);
-  va_end(argListCopy);
-  if (nMaxLen > 0) {
-    GetBuffer(nMaxLen);
-    if (m_pData) {
-      // In the following two calls, there's always space in the buffer for
-      // a terminating NUL that's not included in nMaxLen.
-      memset(m_pData->m_String, 0, nMaxLen + 1);
-      va_copy(argListCopy, argList);
-      vsnprintf(m_pData->m_String, nMaxLen + 1, pFormat, argListCopy);
-      va_end(argListCopy);
-      ReleaseBuffer(GetStringLength());
-    }
-  }
-}
-
-void ByteString::Format(const char* pFormat, ...) {
-  va_list argList;
-  va_start(argList, pFormat);
-  FormatV(pFormat, argList);
-  va_end(argList);
-}
-
 void ByteString::SetAt(size_t index, char c) {
   ASSERT(IsValidIndex(index));
   ReallocBeforeWrite(m_pData->m_nDataLength);
@@ -783,11 +798,6 @@
   TrimLeft("\x09\x0a\x0b\x0c\x0d\x20");
 }
 
-ByteString ByteString::FormatFloat(float d) {
-  char buf[32];
-  return ByteString(buf, FX_ftoa(d, buf));
-}
-
 std::ostream& operator<<(std::ostream& os, const ByteString& str) {
   return os.write(str.c_str(), str.GetLength());
 }
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index f534b08..1acece3 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -32,6 +32,11 @@
   using const_iterator = const CharType*;
   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
+  static ByteString FormatInteger(int i);
+  static ByteString FormatFloat(float f);
+  static ByteString Format(const char* lpszFormat, ...);
+  static ByteString FormatV(const char* lpszFormat, va_list argList);
+
   ByteString();
   ByteString(const ByteString& other);
   ByteString(ByteString&& other) noexcept;
@@ -138,9 +143,6 @@
   size_t InsertAtBack(char ch) { return Insert(GetLength(), ch); }
   size_t Delete(size_t index, size_t count = 1);
 
-  void Format(const char* lpszFormat, ...);
-  void FormatV(const char* lpszFormat, va_list argList);
-
   void Reserve(size_t len);
   char* GetBuffer(size_t len);
   void ReleaseBuffer(size_t len);
@@ -181,9 +183,6 @@
 
   uint32_t GetID() const { return AsStringView().GetID(); }
 
-  static ByteString FormatInteger(int i);
-  static ByteString FormatFloat(float f);
-
  protected:
   using StringData = StringDataTemplate<char>;
 
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp
index 4668fe1..08c0e92 100644
--- a/core/fxcrt/bytestring_unittest.cpp
+++ b/core/fxcrt/bytestring_unittest.cpp
@@ -1448,67 +1448,19 @@
 }
 
 TEST(ByteString, FormatWidth) {
-  {
-    ByteString str;
-    str.Format("%5d", 1);
-    EXPECT_EQ("    1", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%d", 1);
-    EXPECT_EQ("1", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%*d", 5, 1);
-    EXPECT_EQ("    1", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%-1d", 1);
-    EXPECT_EQ("1", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%0d", 1);
-    EXPECT_EQ("1", str);
-  }
+  EXPECT_EQ("    1", ByteString::Format("%5d", 1));
+  EXPECT_EQ("1", ByteString::Format("%d", 1));
+  EXPECT_EQ("    1", ByteString::Format("%*d", 5, 1));
+  EXPECT_EQ("1", ByteString::Format("%-1d", 1));
+  EXPECT_EQ("1", ByteString::Format("%0d", 1));
 }
 
 TEST(ByteString, FormatPrecision) {
-  {
-    ByteString str;
-    str.Format("%.2f", 1.12345);
-    EXPECT_EQ("1.12", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%.*f", 3, 1.12345);
-    EXPECT_EQ("1.123", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%f", 1.12345);
-    EXPECT_EQ("1.123450", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%-1f", 1.12345);
-    EXPECT_EQ("1.123450", str);
-  }
-
-  {
-    ByteString str;
-    str.Format("%0f", 1.12345);
-    EXPECT_EQ("1.123450", str);
-  }
+  EXPECT_EQ("1.12", ByteString::Format("%.2f", 1.12345));
+  EXPECT_EQ("1.123", ByteString::Format("%.*f", 3, 1.12345));
+  EXPECT_EQ("1.123450", ByteString::Format("%f", 1.12345));
+  EXPECT_EQ("1.123450", ByteString::Format("%-1f", 1.12345));
+  EXPECT_EQ("1.123450", ByteString::Format("%0f", 1.12345));
 }
 
 TEST(ByteString, Empty) {
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp
index f68598e..e12f341 100644
--- a/core/fxge/cfx_fontmgr.cpp
+++ b/core/fxge/cfx_fontmgr.cpp
@@ -57,9 +57,7 @@
 }
 
 ByteString KeyNameFromSize(int ttc_size, uint32_t checksum) {
-  ByteString key;
-  key.Format("%d:%d", ttc_size, checksum);
-  return key;
+  return ByteString::Format("%d:%d", ttc_size, checksum);
 }
 
 int GetTTCIndex(const uint8_t* pFontData,
diff --git a/fpdfsdk/cpdfsdk_datetime.cpp b/fpdfsdk/cpdfsdk_datetime.cpp
index ce22cae..332ae8e 100644
--- a/fpdfsdk/cpdfsdk_datetime.cpp
+++ b/fpdfsdk/cpdfsdk_datetime.cpp
@@ -264,16 +264,11 @@
 }
 
 ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
-  ByteString str1;
-  str1.Format("%04d-%02u-%02u %02u:%02u:%02u ", m_year, m_month, m_day, m_hour,
-              m_minute, m_second);
-  if (m_tzHour < 0)
-    str1 += "-";
-  else
-    str1 += "+";
-  ByteString str2;
-  str2.Format("%02d:%02u", std::abs(static_cast<int>(m_tzHour)), m_tzMinute);
-  return str1 + str2;
+  return ByteString::Format("%04d-%02u-%02u %02u:%02u:%02u ", m_year, m_month,
+                            m_day, m_hour, m_minute, m_second) +
+         (m_tzHour < 0 ? "-" : "+") +
+         ByteString::Format("%02d:%02u", std::abs(static_cast<int>(m_tzHour)),
+                            m_tzMinute);
 }
 
 ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 35d3617..07fbd7c 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -173,8 +173,8 @@
   CPDF_Stream* pNewContents = pDocument->NewIndirect<CPDF_Stream>(
       nullptr, 0,
       pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool()));
-  ByteString sStream;
-  sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
+  ByteString sStream =
+      ByteString::Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
   pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
   return pNewContents->GetObjNum();
 }
@@ -301,10 +301,9 @@
   ByteString key;
   int nStreams = pdfium::CollectionSize<int>(ObjectArray);
   if (nStreams > 0) {
-    ByteString sKey;
     int i = 0;
     while (i < INT_MAX) {
-      sKey.Format("FFT%d", i);
+      ByteString sKey = ByteString::Format("FFT%d", i);
       if (!pPageXObject->KeyExist(sKey)) {
         key = sKey;
         break;
@@ -391,8 +390,7 @@
     if (!pXObject)
       pXObject = pNewXORes->SetNewFor<CPDF_Dictionary>("XObject");
 
-    ByteString sFormName;
-    sFormName.Format("F%d", i);
+    ByteString sFormName = ByteString::Format("F%d", i);
     pXObject->SetNewFor<CPDF_Reference>(sFormName, pDocument,
                                         pObj->GetObjNum());
 
@@ -401,10 +399,8 @@
     ByteString sStream(pAcc->GetData(), pAcc->GetSize());
     CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix");
     CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
-    ByteString sTemp;
-    sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
-                 sFormName.c_str());
-    sStream += sTemp;
+    sStream += ByteString::Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d,
+                                  m.e, m.f, sFormName.c_str());
     pNewXObject->SetDataAndRemoveFilter(sStream.raw_str(), sStream.GetLength());
   }
   pPageDict->RemoveFor("Annots");
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index dcf19f2..b607dff 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -114,15 +114,11 @@
   textBuf << "q ";
   CFX_FloatRect rect = CFXFloatRectFromFSRECTF(*clipRect);
   rect.Normalize();
-  ByteString bsClipping;
-  bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom,
-                    rect.Width(), rect.Height());
-  textBuf << bsClipping;
 
-  ByteString bsMatix;
-  bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c,
-                 matrix->d, matrix->e, matrix->f);
-  textBuf << bsMatix;
+  textBuf << ByteString::Format("%f %f %f %f re W* n ", rect.left, rect.bottom,
+                                rect.Width(), rect.Height());
+  textBuf << ByteString::Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,
+                                matrix->c, matrix->d, matrix->e, matrix->f);
 
   CPDF_Dictionary* pPageDict = pPage->m_pFormDict.Get();
   CPDF_Object* pContentObj = GetPageContent(pPageDict);
diff --git a/fpdfsdk/fpdfattachment.cpp b/fpdfsdk/fpdfattachment.cpp
index 7402114..8b3c8fe 100644
--- a/fpdfsdk/fpdfattachment.cpp
+++ b/fpdfsdk/fpdfattachment.cpp
@@ -232,11 +232,13 @@
   // Set the creation date of the new attachment in the dictionary.
   CFX_DateTime dateTime;
   dateTime.Now();
-  ByteString bsDateTime;
-  bsDateTime.Format("D:%d%02d%02d%02d%02d%02d", dateTime.GetYear(),
-                    dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(),
-                    dateTime.GetMinute(), dateTime.GetSecond());
-  pParamsDict->SetNewFor<CPDF_String>("CreationDate", bsDateTime, false);
+  pParamsDict->SetNewFor<CPDF_String>(
+      "CreationDate",
+      ByteString::Format("D:%d%02d%02d%02d%02d%02d", dateTime.GetYear(),
+                         dateTime.GetMonth(), dateTime.GetDay(),
+                         dateTime.GetHour(), dateTime.GetMinute(),
+                         dateTime.GetSecond()),
+      false);
 
   // Set the checksum of the new attachment in the dictionary.
   pParamsDict->SetNewFor<CPDF_String>(
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index db726b7..a032bf6 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -105,9 +105,9 @@
     if (time(&currentTime) != -1) {
       tm* pTM = localtime(&currentTime);
       if (pTM) {
-        DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
-                       pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min,
-                       pTM->tm_sec);
+        DateStr = ByteString::Format(
+            "D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, pTM->tm_mon + 1,
+            pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec);
       }
     }
   }
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 374fe56..bc6c7db 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -434,9 +434,8 @@
     return;
 
   RetainPtr<IFX_SeekableStream> fileWrite = MakeSeekableStream(pFileHandler);
-  ByteString content;
   if (fileType == FXFA_SAVEAS_XML) {
-    content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+    ByteString content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
     fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(),
                           content.GetLength());
     CXFA_FFDoc* ffdoc = m_pContext->GetXFADocView()->GetDoc();
@@ -492,7 +491,7 @@
         ByteString bPath = wPath.UTF8Encode();
         const char* szFormat =
             "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
-        content.Format(szFormat, bPath.c_str());
+        ByteString content = ByteString::Format(szFormat, bPath.c_str());
         fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(),
                               content.GetLength());
       }
diff --git a/fpdfsdk/pwl/cpwl_font_map.cpp b/fpdfsdk/pwl/cpwl_font_map.cpp
index 522b6ef..4a2ac4b 100644
--- a/fpdfsdk/pwl/cpwl_font_map.cpp
+++ b/fpdfsdk/pwl/cpwl_font_map.cpp
@@ -260,9 +260,7 @@
 
 ByteString CPWL_FontMap::EncodeFontAlias(const ByteString& sFontName,
                                          int32_t nCharset) {
-  ByteString sPostfix;
-  sPostfix.Format("_%02X", nCharset);
-  return EncodeFontAlias(sFontName) + sPostfix;
+  return EncodeFontAlias(sFontName) + ByteString::Format("_%02X", nCharset);
 }
 
 ByteString CPWL_FontMap::EncodeFontAlias(const ByteString& sFontName) {
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp
index 8f4334f..b2e747b 100644
--- a/fxjs/cfxjse_class.cpp
+++ b/fxjs/cfxjse_class.cpp
@@ -108,8 +108,7 @@
     return;
 
   if (info.This() == info.Holder() && lpClass->name) {
-    ByteString szStringVal;
-    szStringVal.Format("[object %s]", lpClass->name);
+    ByteString szStringVal = ByteString::Format("[object %s]", lpClass->name);
     info.GetReturnValue().Set(v8::String::NewFromUtf8(
         info.GetIsolate(), szStringVal.c_str(), v8::String::kNormalString,
         szStringVal.GetLength()));
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index dfd3816..f3c4ebe 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -1114,16 +1114,10 @@
   time(&currentTime);
   struct tm* pTmStruct = gmtime(&currentTime);
 
-  ByteString bufferYear;
-  ByteString bufferMon;
-  ByteString bufferDay;
-  bufferYear.Format("%d", pTmStruct->tm_year + 1900);
-  bufferMon.Format("%02d", pTmStruct->tm_mon + 1);
-  bufferDay.Format("%02d", pTmStruct->tm_mday);
-
-  ByteString bufferCurrent = bufferYear + bufferMon + bufferDay;
-  args.GetReturnValue()->SetInteger(
-      DateString2Num(bufferCurrent.AsStringView()));
+  args.GetReturnValue()->SetInteger(DateString2Num(
+      ByteString::Format("%d%02d%02d", pTmStruct->tm_year + 1900,
+                         pTmStruct->tm_mon + 1, pTmStruct->tm_mday)
+          .AsStringView()));
 }
 
 // static
@@ -1489,11 +1483,10 @@
     }
   }
 
-  ByteString szIsoDateString;
-  szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
-  ByteString szLocalDateString =
-      IsoDate2Local(pThis, szIsoDateString.AsStringView(),
-                    formatString.AsStringView(), localString.AsStringView());
+  ByteString szLocalDateString = IsoDate2Local(
+      pThis,
+      ByteString::Format("%d%02d%02d", iYear + i, iMonth, iDay).AsStringView(),
+      formatString.AsStringView(), localString.AsStringView());
   args.GetReturnValue()->SetString(szLocalDateString.AsStringView());
 }
 
@@ -2019,9 +2012,8 @@
                                      wsFormat, pLocale, pMgr)
                         .GetDate();
 
-  ByteString strIsoDate;
-  strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay());
-  return strIsoDate;
+  return ByteString::Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(),
+                            dt.GetDay());
 }
 
 // static
@@ -2213,9 +2205,10 @@
     iSec += iZoneSec;
   }
 
-  ByteString strIsoTime;
-  strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec);
-  return IsoTime2Local(pThis, strIsoTime.AsStringView(), szFormat, szLocale);
+  return IsoTime2Local(
+      pThis,
+      ByteString::Format("%02d:%02d:%02d", iHour, iMin, iSec).AsStringView(),
+      szFormat, szLocale);
 }
 
 // static
@@ -4232,14 +4225,13 @@
         0, static_cast<int32_t>(ValueToFloat(pThis, precisionValue.get())));
   }
 
-  ByteString numberString;
   ByteString formatStr = "%";
   if (iPrecision) {
     formatStr += ".";
     formatStr += ByteString::FormatInteger(iPrecision);
   }
   formatStr += "f";
-  numberString.Format(formatStr.c_str(), fNumber);
+  ByteString numberString = ByteString::Format(formatStr.c_str(), fNumber);
 
   const char* pData = numberString.c_str();
   int32_t iLength = numberString.GetLength();
@@ -4505,11 +4497,8 @@
     return;
   }
 
-  ByteString numberString;
-  numberString.Format("%.2f", fNumber);
-
   args.GetReturnValue()->SetString(
-      WordUS(numberString, iIdentifier).AsStringView());
+      WordUS(ByteString::Format("%.2f", fNumber), iIdentifier).AsStringView());
 }
 
 // static
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index b89101c..07b96b8 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -1761,15 +1761,12 @@
     return;
   }
 
-  FX_ARGB color = fontData.GetColor();
   int32_t a;
   int32_t r;
   int32_t g;
   int32_t b;
-  std::tie(a, r, g, b) = ArgbDecode(color);
-  ByteString bsColor;
-  bsColor.Format("%d,%d,%d", r, g, b);
-  pValue->SetString(bsColor.AsStringView());
+  std::tie(a, r, g, b) = ArgbDecode(fontData.GetColor());
+  pValue->SetString(ByteString::Format("%d,%d,%d", r, g, b).AsStringView());
 }
 
 void CJX_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 2b3f54b..4d34ac8 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -78,8 +78,7 @@
     CPDF_Font** pPDFFont,
     bool bStrictMatch) {
   uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false);
-  ByteString strKey;
-  strKey.Format("%u%u", dwHashCode, dwFontStyles);
+  ByteString strKey = ByteString::Format("%u%u", dwHashCode, dwFontStyles);
   auto it = m_FontMap.find(strKey);
   if (it != m_FontMap.end())
     return it->second;
diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp
index d144bd2..0956806 100644
--- a/xfa/fxfa/cxfa_fontmgr.cpp
+++ b/xfa/fxfa/cxfa_fontmgr.cpp
@@ -28,8 +28,7 @@
     const WideStringView& wsFontFamily,
     uint32_t dwFontStyles) {
   uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false);
-  ByteString bsKey;
-  bsKey.Format("%u%u%u", dwHash, dwFontStyles, 0xFFFF);
+  ByteString bsKey = ByteString::Format("%u%u%u", dwHash, dwFontStyles, 0xFFFF);
   auto iter = m_FontMap.find(bsKey);
   if (iter != m_FontMap.end())
     return iter->second;