diff options
author | tsepez <tsepez@chromium.org> | 2016-12-07 16:01:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-07 16:01:54 -0800 |
commit | 248cb27e64b3a25230f53fc2f4ab9d483facc5f9 (patch) | |
tree | 50ba031ed7f77e20fa6a07c70d047f11d038c00c /xfa | |
parent | a9d29df6a774737a661d0f37f6b8aa5cba179c06 (diff) | |
download | pdfium-248cb27e64b3a25230f53fc2f4ab9d483facc5f9.tar.xz |
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
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fgas/localization/fgas_localeimp.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_localevalue.cpp | 74 |
2 files changed, 31 insertions, 48 deletions
diff --git a/xfa/fgas/localization/fgas_localeimp.h b/xfa/fgas/localization/fgas_localeimp.h index 66f1767c5c..7389158798 100644 --- a/xfa/fgas/localization/fgas_localeimp.h +++ b/xfa/fgas/localization/fgas_localeimp.h @@ -14,8 +14,7 @@ class CFX_LCNumeric; 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 @@ class CFX_FormatString { 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 b662121230..c060fe8166 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 @@ static FX_LOCALECATEGORY XFA_ValugeCategory(FX_LOCALECATEGORY eCategory, } 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 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, 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 @@ bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, 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 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, 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 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, 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 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, 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, |