Simplify CPDF_InterForm::GenerateNewResourceName().

It only has one caller, so remove all the checks that will never be true
for this caller. Also make it an anonymous function.

Change-Id: I06e6a04e2f6b8741b6beb83534502a626564b592
Reviewed-on: https://pdfium-review.googlesource.com/37410
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 97d22a2..bacf6fd 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -32,6 +32,42 @@
 
 const int nMaxRecursion = 32;
 
+ByteString GenerateNewFontResourceName(const CPDF_Dictionary* pResDict,
+                                       const ByteString& csPrefix) {
+  static const char kDummyFontName[] = "ZiTi";
+  ByteString csStr = csPrefix;
+  if (csStr.IsEmpty())
+    csStr = kDummyFontName;
+
+  const size_t szCount = csStr.GetLength();
+  size_t m = 0;
+  ByteString csTmp;
+  while (m < strlen(kDummyFontName) && m < szCount)
+    csTmp += csStr[m++];
+  while (m < strlen(kDummyFontName)) {
+    csTmp += '0' + m % 10;
+    m++;
+  }
+
+  const CPDF_Dictionary* pDict = pResDict->GetDictFor("Font");
+  ASSERT(pDict);
+
+  int num = 0;
+  ByteString bsNum;
+  while (true) {
+    ByteString csKey = csTmp + bsNum;
+    if (!pDict->KeyExist(csKey))
+      return csKey;
+    if (m < szCount)
+      csTmp += csStr[m++];
+    else
+      bsNum = ByteString::Format("%d", num++);
+
+    m++;
+  }
+  return csTmp;
+}
+
 void AddFont(CPDF_Dictionary*& pFormDict,
              CPDF_Document* pDocument,
              const CPDF_Font* pFont,
@@ -245,8 +281,7 @@
     *csNameTag = pFont->GetBaseFont();
 
   csNameTag->Remove(' ');
-  *csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
-                                                       csNameTag->c_str());
+  *csNameTag = GenerateNewFontResourceName(pDR, *csNameTag);
   pFonts->SetFor(*csNameTag, pFont->GetFontDict()->MakeReference(pDocument));
 }
 
@@ -573,60 +608,6 @@
   s_bUpdateAP = bUpdateAP;
 }
 
-ByteString CPDF_InterForm::GenerateNewResourceName(
-    const CPDF_Dictionary* pResDict,
-    const char* csType,
-    int iMinLen,
-    const char* csPrefix) {
-  ByteString csStr = csPrefix;
-  ByteString csBType = csType;
-  if (csStr.IsEmpty()) {
-    if (csBType == "ExtGState")
-      csStr = "GS";
-    else if (csBType == "ColorSpace")
-      csStr = "CS";
-    else if (csBType == "Font")
-      csStr = "ZiTi";
-    else
-      csStr = "Res";
-  }
-  ByteString csTmp = csStr;
-  int iCount = csStr.GetLength();
-  int m = 0;
-  if (iMinLen > 0) {
-    csTmp.clear();
-    while (m < iMinLen && m < iCount)
-      csTmp += csStr[m++];
-    while (m < iMinLen) {
-      csTmp += '0' + m % 10;
-      m++;
-    }
-  } else {
-    m = iCount;
-  }
-  if (!pResDict)
-    return csTmp;
-
-  const CPDF_Dictionary* pDict = pResDict->GetDictFor(csType);
-  if (!pDict)
-    return csTmp;
-
-  int num = 0;
-  ByteString bsNum;
-  while (true) {
-    ByteString csKey = csTmp + bsNum;
-    if (!pDict->KeyExist(csKey))
-      return csKey;
-    if (m < iCount)
-      csTmp += csStr[m++];
-    else
-      bsNum = ByteString::Format("%d", num++);
-
-    m++;
-  }
-  return csTmp;
-}
-
 CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument,
                                            ByteString csFontName) {
   if (!pDocument || csFontName.IsEmpty())
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index c5da15d..97d8ac1 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -39,10 +39,6 @@
 
   static void SetUpdateAP(bool bUpdateAP);
   static bool IsUpdateAPEnabled();
-  static ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict,
-                                            const char* csType,
-                                            int iMinLen,
-                                            const char* csPrefix);
   static CPDF_Font* AddStandardFont(CPDF_Document* pDocument,
                                     ByteString csFontName);
   static ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont);