Remove CFX_FormatString::Release()

Avoid the |delete this| anti-pattern.
Remove some checks which don't avoid other segvs anyways.

Review-Url: https://codereview.chromium.org/2557173002
diff --git a/xfa/fgas/localization/fgas_localeimp.h b/xfa/fgas/localization/fgas_localeimp.h
index 66f1767..7389158 100644
--- a/xfa/fgas/localization/fgas_localeimp.h
+++ b/xfa/fgas/localization/fgas_localeimp.h
@@ -14,8 +14,7 @@
 class CFX_FormatString {
  public:
   CFX_FormatString(IFX_LocaleMgr* pLocaleMgr, bool bUseLCID);
-
-  void Release() { delete this; }
+  ~CFX_FormatString();
 
   void SplitFormatString(const CFX_WideString& wsFormatString,
                          CFX_WideStringArray& wsPatterns);
@@ -62,8 +61,6 @@
   bool FormatNull(const CFX_WideString& wsPattern, CFX_WideString& wsOutput);
 
  protected:
-  ~CFX_FormatString();
-
   IFX_Locale* GetTextFormat(const CFX_WideString& wsPattern,
                             const CFX_WideStringC& wsCategory,
                             CFX_WideString& wsPurgePattern);
diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp
index b662121..c060fe8 100644
--- a/xfa/fxfa/parser/xfa_localevalue.cpp
+++ b/xfa/fxfa/parser/xfa_localevalue.cpp
@@ -7,6 +7,7 @@
 #include "xfa/fxfa/parser/xfa_localevalue.h"
 
 #include "core/fxcrt/fx_ext.h"
+#include "third_party/base/ptr_util.h"
 #include "xfa/fgas/localization/fgas_localeimp.h"
 #include "xfa/fxfa/parser/cxfa_document.h"
 #include "xfa/fxfa/parser/xfa_localemgr.h"
@@ -93,21 +94,20 @@
   }
   return eCategory;
 }
+
 bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
                                      const CFX_WideString& wsPattern,
                                      IFX_Locale* pLocale,
                                      CFX_WideString* pMatchFormat) {
   CFX_WideString wsOutput;
   IFX_Locale* locale = m_pLocaleMgr->GetDefLocale();
-  if (pLocale) {
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(pLocale);
-  }
-  CFX_FormatString* pFormat = nullptr;
-  if (m_pLocaleMgr)
-    pFormat = new CFX_FormatString(m_pLocaleMgr, false);
 
+  auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
   CFX_WideStringArray wsPatterns;
   pFormat->SplitFormatString(wsPattern, wsPatterns);
+
   bool bRet = false;
   int32_t iCount = wsPatterns.GetSize();
   int32_t i = 0;
@@ -181,15 +181,15 @@
         break;
     }
   }
-  if (bRet && pMatchFormat) {
+  if (bRet && pMatchFormat)
     *pMatchFormat = wsPatterns[i - 1];
-  }
-  pFormat->Release();
-  if (pLocale) {
+
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(locale);
-  }
+
   return bRet;
 }
+
 CFX_WideString CXFA_LocaleValue::GetValue() const {
   return m_wsValue;
 }
@@ -458,44 +458,34 @@
   m_dwType = XFA_VT_DATETIME;
   return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale);
 }
+
 bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult,
                                       const CFX_WideString& wsFormat,
                                       IFX_Locale* pLocale,
                                       XFA_VALUEPICTURE eValueType) const {
-  wsResult.clear();
-  bool bRet = false;
-
-  CFX_FormatString* pFormat = nullptr;
-  if (m_pLocaleMgr)
-    pFormat = new CFX_FormatString(m_pLocaleMgr, false);
-
+  auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
   CFX_WideStringArray wsPatterns;
   pFormat->SplitFormatString(wsFormat, wsPatterns);
+  wsResult.clear();
   int32_t iCount = wsPatterns.GetSize();
   for (int32_t i = 0; i < iCount; i++) {
-    bRet = FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType);
-    if (bRet) {
-      break;
-    }
+    if (FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType))
+      return true;
   }
-  pFormat->Release();
-  return bRet;
+  return false;
 }
+
 bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult,
                                            const CFX_WideString& wsFormat,
                                            IFX_Locale* pLocale,
                                            XFA_VALUEPICTURE eValueType) const {
   IFX_Locale* locale = m_pLocaleMgr->GetDefLocale();
-  if (pLocale) {
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(pLocale);
-  }
+
   wsResult.clear();
   bool bRet = false;
-
-  CFX_FormatString* pFormat = nullptr;
-  if (m_pLocaleMgr)
-    pFormat = new CFX_FormatString(m_pLocaleMgr, false);
-
+  auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
   FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat);
   eCategory = XFA_ValugeCategory(eCategory, m_dwType);
   switch (eCategory) {
@@ -531,16 +521,16 @@
       wsResult = m_wsValue;
       bRet = true;
   }
-  pFormat->Release();
   if (!bRet && (eCategory != FX_LOCALECATEGORY_Num ||
                 eValueType != XFA_VALUEPICTURE_Display)) {
     wsResult = m_wsValue;
   }
-  if (pLocale) {
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(locale);
-  }
+
   return bRet;
 }
+
 static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime,
                                    CFX_WideString& wsDate,
                                    CFX_WideString& wsTime) {
@@ -799,14 +789,10 @@
                                          const CFX_WideString& wsPattern,
                                          IFX_Locale* pLocale) {
   IFX_Locale* locale = m_pLocaleMgr->GetDefLocale();
-  if (pLocale) {
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(pLocale);
-  }
 
-  CFX_FormatString* pFormat = nullptr;
-  if (m_pLocaleMgr)
-    pFormat = new CFX_FormatString(m_pLocaleMgr, false);
-
+  auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false);
   CFX_WideStringArray wsPatterns;
   pFormat->SplitFormatString(wsPattern, wsPatterns);
   bool bRet = false;
@@ -875,15 +861,15 @@
         break;
     }
   }
-  if (!bRet) {
+  if (!bRet)
     m_wsValue = wsValue;
-  }
-  pFormat->Release();
-  if (pLocale) {
+
+  if (pLocale)
     m_pLocaleMgr->SetDefLocale(locale);
-  }
+
   return bRet;
 }
+
 void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat,
                                          int32_t nIntLen,
                                          int32_t nDecLen,