diff options
author | weili <weili@chromium.org> | 2016-08-10 14:50:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 14:50:48 -0700 |
commit | b4d1b576bccb5ca6cebe29288af014bd0f512af1 (patch) | |
tree | 2d60839a8323eb6780c782aba4ae1123243c7355 /xfa/fxfa/parser | |
parent | 1194561d5d83869edecf6a1f402122a59955f0b7 (diff) | |
download | pdfium-b4d1b576bccb5ca6cebe29288af014bd0f512af1.tar.xz |
Use smart pointers for class owned pointers in xfa/fxfa
Use smart pointers instead of raw pointer to make memory management
easier for classes mainly under xfa/fxfa.
Also change the return type of IFGAS_FontMgr::Create() to smart
pointer type.
BUG=pdfium:518
Review-Url: https://codereview.chromium.org/2227883002
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_resolveprocessor.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_resolveprocessor.h | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_locale.cpp | 44 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_locale.h | 8 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_localemgr.cpp | 15 |
5 files changed, 55 insertions, 22 deletions
diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp index 2a281f9c4b..60f3671418 100644 --- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -18,9 +18,7 @@ CXFA_ResolveProcessor::CXFA_ResolveProcessor() : m_iCurStart(0), m_pNodeHelper(new CXFA_NodeHelper) {} -CXFA_ResolveProcessor::~CXFA_ResolveProcessor() { - delete m_pNodeHelper; -} +CXFA_ResolveProcessor::~CXFA_ResolveProcessor() {} int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { if (!rnd.m_CurNode) { diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.h b/xfa/fxfa/parser/cxfa_resolveprocessor.h index 4db0ea2270..630a54ea3c 100644 --- a/xfa/fxfa/parser/cxfa_resolveprocessor.h +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ #define XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ +#include <memory> + #include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" @@ -46,7 +48,7 @@ class CXFA_ResolveProcessor { int32_t iCount); void SetCurStart(int32_t start) { m_iCurStart = start; } - CXFA_NodeHelper* GetNodeHelper() { return m_pNodeHelper; } + CXFA_NodeHelper* GetNodeHelper() const { return m_pNodeHelper.get(); } private: int32_t ResolveForAttributeRs(CXFA_Object* curNode, @@ -72,7 +74,7 @@ class CXFA_ResolveProcessor { void FilterCondition(CXFA_ResolveNodesData& rnd, CFX_WideString wsCondition); int32_t m_iCurStart; - CXFA_NodeHelper* m_pNodeHelper; + std::unique_ptr<CXFA_NodeHelper> m_pNodeHelper; }; #endif // XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ diff --git a/xfa/fxfa/parser/xfa_locale.cpp b/xfa/fxfa/parser/xfa_locale.cpp index 67a9760646..723fdbc15c 100644 --- a/xfa/fxfa/parser/xfa_locale.cpp +++ b/xfa/fxfa/parser/xfa_locale.cpp @@ -6,6 +6,8 @@ #include "xfa/fxfa/parser/xfa_locale.h" +#include <utility> + #include "core/fxcrt/include/fx_xml.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" @@ -17,19 +19,19 @@ static const FX_WCHAR g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; static const FX_WCHAR g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; static const FX_WCHAR g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; -CXFA_XMLLocale::CXFA_XMLLocale(CXML_Element* pLocaleData) - : m_pLocaleData(pLocaleData) {} +CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) + : m_pLocaleData(std::move(pLocaleData)) {} -CXFA_XMLLocale::~CXFA_XMLLocale() { - delete m_pLocaleData; -} +CXFA_XMLLocale::~CXFA_XMLLocale() {} void CXFA_XMLLocale::Release() { delete this; } + CFX_WideString CXFA_XMLLocale::GetName() { return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); } + void CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, CFX_WideString& wsNumSymbol) const { CFX_ByteString bsSymbols; @@ -74,6 +76,7 @@ void CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, CFX_ByteStringC(bsSymbols.c_str(), bsSymbols.GetLength() - 1), wsName.AsStringC(), wsNumSymbol); } + void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { if (!m_pLocaleData) { return; @@ -86,26 +89,32 @@ void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { } wsDtSymbol = pNumberSymbols->GetContent(0); } + void CXFA_XMLLocale::GetMonthName(int32_t nMonth, CFX_WideString& wsMonthName, FX_BOOL bAbbr) const { wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); } + void CXFA_XMLLocale::GetDayName(int32_t nWeek, CFX_WideString& wsDayName, FX_BOOL bAbbr) const { wsDayName = GetCalendarSymbol("day", nWeek, bAbbr); } + void CXFA_XMLLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, FX_BOOL bAM) const { wsMeridiemName = GetCalendarSymbol("meridiem", bAM ? 0 : 1, FALSE); } + void CXFA_XMLLocale::GetTimeZone(FX_TIMEZONE& tz) const { CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); } + void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, FALSE); } + CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, int index, FX_BOOL bAbbr) const { @@ -132,6 +141,7 @@ CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, } return wsSymbolName; } + void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, CFX_WideString& wsPattern) const { CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); @@ -156,6 +166,7 @@ void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, } GetPattern(pElement, "datePattern", wsName.AsStringC(), wsPattern); } + void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, CFX_WideString& wsPattern) const { CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); @@ -180,6 +191,7 @@ void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, } GetPattern(pElement, "timePattern", wsName.AsStringC(), wsPattern); } + void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, CFX_WideString& wsPattern) const { CXML_Element* pElement = m_pLocaleData->GetElement("", "numberPatterns"); @@ -201,6 +213,7 @@ void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, break; } } + void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, const CFX_ByteStringC& bsTag, const CFX_WideStringC& wsName, @@ -214,17 +227,20 @@ void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, } } } -CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) { - m_pLocale = pLocale; -} + +CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) : m_pLocale(pLocale) {} + CXFA_NodeLocale::~CXFA_NodeLocale() {} + void CXFA_NodeLocale::Release() { delete this; } + CFX_WideString CXFA_NodeLocale::GetName() { return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) : nullptr); } + void CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, CFX_WideString& wsNumSymbol) const { switch (eType) { @@ -254,33 +270,40 @@ void CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, break; } } + void CXFA_NodeLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { CXFA_Node* pSymbols = m_pLocale ? m_pLocale->GetChild(0, XFA_Element::DateTimeSymbols) : nullptr; wsDtSymbol = pSymbols ? pSymbols->GetContent() : CFX_WideString(); } + void CXFA_NodeLocale::GetMonthName(int32_t nMonth, CFX_WideString& wsMonthName, FX_BOOL bAbbr) const { wsMonthName = GetCalendarSymbol(XFA_Element::MonthNames, nMonth, bAbbr); } + void CXFA_NodeLocale::GetDayName(int32_t nWeek, CFX_WideString& wsDayName, FX_BOOL bAbbr) const { wsDayName = GetCalendarSymbol(XFA_Element::DayNames, nWeek, bAbbr); } + void CXFA_NodeLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, FX_BOOL bAM) const { wsMeridiemName = GetCalendarSymbol(XFA_Element::MeridiemNames, bAM ? 0 : 1, FALSE); } + void CXFA_NodeLocale::GetTimeZone(FX_TIMEZONE& tz) const { CXFA_TimeZoneProvider::Get()->GetTimeZone(tz); } + void CXFA_NodeLocale::GetEraName(CFX_WideString& wsEraName, FX_BOOL bAD) const { wsEraName = GetCalendarSymbol(XFA_Element::EraNames, bAD ? 1 : 0, FALSE); } + void CXFA_NodeLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, CFX_WideString& wsPattern) const { switch (eType) { @@ -299,6 +322,7 @@ void CXFA_NodeLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, break; } } + void CXFA_NodeLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, CFX_WideString& wsPattern) const { switch (eType) { @@ -317,6 +341,7 @@ void CXFA_NodeLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, break; } } + void CXFA_NodeLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, CFX_WideString& wsPattern) const { switch (eType) { @@ -334,6 +359,7 @@ void CXFA_NodeLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, break; } } + CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, const CFX_WideStringC& wsName) const { CXFA_Node* pChild = @@ -349,6 +375,7 @@ CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, } return nullptr; } + CFX_WideString CXFA_NodeLocale::GetSymbol( XFA_Element eElement, const CFX_WideStringC& symbol_type) const { @@ -356,6 +383,7 @@ CFX_WideString CXFA_NodeLocale::GetSymbol( CXFA_Node* pSymbol = GetNodeByName(pSymbols, symbol_type); return pSymbol ? pSymbol->GetContent() : CFX_WideString(); } + CFX_WideString CXFA_NodeLocale::GetCalendarSymbol(XFA_Element eElement, int index, FX_BOOL bAbbr) const { diff --git a/xfa/fxfa/parser/xfa_locale.h b/xfa/fxfa/parser/xfa_locale.h index 0c72381cd5..0463a9f9e9 100644 --- a/xfa/fxfa/parser/xfa_locale.h +++ b/xfa/fxfa/parser/xfa_locale.h @@ -7,12 +7,14 @@ #ifndef XFA_FXFA_PARSER_XFA_LOCALE_H_ #define XFA_FXFA_PARSER_XFA_LOCALE_H_ +#include <memory> + #include "xfa/fgas/localization/fgas_locale.h" #include "xfa/fxfa/parser/xfa_object.h" class CXFA_XMLLocale : public IFX_Locale { public: - CXFA_XMLLocale(CXML_Element* pLocaleData); + explicit CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData); // IFX_Locale void Release() override; @@ -51,7 +53,7 @@ class CXFA_XMLLocale : public IFX_Locale { FX_BOOL bAbbr) const; private: - CXML_Element* m_pLocaleData; + std::unique_ptr<CXML_Element> m_pLocaleData; }; class CXFA_NodeLocale : public IFX_Locale { @@ -94,7 +96,7 @@ class CXFA_NodeLocale : public IFX_Locale { int index, FX_BOOL bAbbr) const; - CXFA_Node* m_pLocale; + CXFA_Node* const m_pLocale; }; #endif // XFA_FXFA_PARSER_XFA_LOCALE_H_ diff --git a/xfa/fxfa/parser/xfa_localemgr.cpp b/xfa/fxfa/parser/xfa_localemgr.cpp index 2d100746c9..efc18af6e0 100644 --- a/xfa/fxfa/parser/xfa_localemgr.cpp +++ b/xfa/fxfa/parser/xfa_localemgr.cpp @@ -6,6 +6,9 @@ #include "xfa/fxfa/parser/xfa_localemgr.h" +#include <memory> +#include <utility> + #include "core/fxcodec/include/fx_codec.h" #include "core/fxcrt/include/fx_xml.h" #include "core/fxge/include/cfx_gemodule.h" @@ -1029,6 +1032,8 @@ const uint8_t g_ruRU_Locale[] = { 0x89, 0x26, 0xB5, 0x2C, 0xA3, 0xB6, 0x4E, 0x5C, 0xA6, 0x17, 0xA4, 0x7B, 0xB3, 0x85, 0xFA, 0x59, 0x2A, 0x7A, 0xFF, 0x3D, 0xC4, 0x3F, 0xDE, 0xCB, 0x8B, 0xC4}; + +// TODO(weili): Change this function to return std::unique_ptr type. static IFX_Locale* XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) { if (!pBuf || nBufLen <= 0) { return nullptr; @@ -1041,20 +1046,18 @@ static IFX_Locale* XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) { if (!pCodecMgr) { return nullptr; } - CXML_Element* pLocale = nullptr; + std::unique_ptr<CXML_Element> pLocale; uint8_t* pOut = nullptr; uint32_t dwSize; pCodecMgr->GetFlateModule()->FlateOrLZWDecode(FALSE, pBuf, nBufLen, TRUE, 0, 0, 0, 0, 0, pOut, dwSize); if (pOut) { - pLocale = CXML_Element::Parse(pOut, dwSize); + pLocale.reset(CXML_Element::Parse(pOut, dwSize)); FX_Free(pOut); } - if (pLocale) { - return new CXFA_XMLLocale(pLocale); - } - return nullptr; + return pLocale ? new CXFA_XMLLocale(std::move(pLocale)) : nullptr; } + static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) { uint16_t dwLangueID = XFA_LANGID_en_US; if (wsLanguage.GetLength() < 2) { |