diff options
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/parser/xfa_locale.cpp | 12 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_locale.h | 12 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_localemgr.cpp | 134 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_localemgr.h | 15 |
4 files changed, 72 insertions, 101 deletions
diff --git a/xfa/fxfa/parser/xfa_locale.cpp b/xfa/fxfa/parser/xfa_locale.cpp index 723fdbc15c..686af80576 100644 --- a/xfa/fxfa/parser/xfa_locale.cpp +++ b/xfa/fxfa/parser/xfa_locale.cpp @@ -24,11 +24,7 @@ CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) CXFA_XMLLocale::~CXFA_XMLLocale() {} -void CXFA_XMLLocale::Release() { - delete this; -} - -CFX_WideString CXFA_XMLLocale::GetName() { +CFX_WideString CXFA_XMLLocale::GetName() const { return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); } @@ -232,11 +228,7 @@ 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() { +CFX_WideString CXFA_NodeLocale::GetName() const { return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) : nullptr); } diff --git a/xfa/fxfa/parser/xfa_locale.h b/xfa/fxfa/parser/xfa_locale.h index 0463a9f9e9..75104b456c 100644 --- a/xfa/fxfa/parser/xfa_locale.h +++ b/xfa/fxfa/parser/xfa_locale.h @@ -15,10 +15,10 @@ class CXFA_XMLLocale : public IFX_Locale { public: explicit CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData); + ~CXFA_XMLLocale() override; // IFX_Locale - void Release() override; - CFX_WideString GetName() override; + CFX_WideString GetName() const override; void GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, CFX_WideString& wsNumSymbol) const override; @@ -42,8 +42,6 @@ class CXFA_XMLLocale : public IFX_Locale { CFX_WideString& wsPattern) const override; protected: - ~CXFA_XMLLocale() override; - void GetPattern(CXML_Element* pElement, const CFX_ByteStringC& bsTag, const CFX_WideStringC& wsName, @@ -59,10 +57,10 @@ class CXFA_XMLLocale : public IFX_Locale { class CXFA_NodeLocale : public IFX_Locale { public: CXFA_NodeLocale(CXFA_Node* pLocale); + ~CXFA_NodeLocale() override; // IFX_Locale - void Release() override; - CFX_WideString GetName() override; + CFX_WideString GetName() const override; void GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, CFX_WideString& wsNumSymbol) const override; @@ -86,8 +84,6 @@ class CXFA_NodeLocale : public IFX_Locale { CFX_WideString& wsPattern) const override; protected: - ~CXFA_NodeLocale() override; - CXFA_Node* GetNodeByName(CXFA_Node* pParent, const CFX_WideStringC& wsName) const; CFX_WideString GetSymbol(XFA_Element eElement, diff --git a/xfa/fxfa/parser/xfa_localemgr.cpp b/xfa/fxfa/parser/xfa_localemgr.cpp index efc18af6e0..94a2f5a3f6 100644 --- a/xfa/fxfa/parser/xfa_localemgr.cpp +++ b/xfa/fxfa/parser/xfa_localemgr.cpp @@ -1033,19 +1033,18 @@ const uint8_t g_ruRU_Locale[] = { 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) { +static std::unique_ptr<IFX_Locale> XFA_GetLocaleFromBuffer(const uint8_t* pBuf, + int nBufLen) { + if (!pBuf || nBufLen <= 0) return nullptr; - } CFX_GEModule* pGeModule = CFX_GEModule::Get(); - if (!pGeModule) { + if (!pGeModule) return nullptr; - } + CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); - if (!pCodecMgr) { + if (!pCodecMgr) return nullptr; - } + std::unique_ptr<CXML_Element> pLocale; uint8_t* pOut = nullptr; uint32_t dwSize; @@ -1055,7 +1054,9 @@ static IFX_Locale* XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) { pLocale.reset(CXML_Element::Parse(pOut, dwSize)); FX_Free(pOut); } - return pLocale ? new CXFA_XMLLocale(std::move(pLocale)) : nullptr; + return pLocale ? std::unique_ptr<IFX_Locale>( + new CXFA_XMLLocale(std::move(pLocale))) + : nullptr; } static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) { @@ -1119,29 +1120,23 @@ static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) { } return dwLangueID; } + CXFA_LocaleMgr::CXFA_LocaleMgr(CXFA_Node* pLocaleSet, CFX_WideString wsDeflcid) : m_dwLocaleFlags(0x00) { m_dwDeflcid = XFA_GetLanguage(wsDeflcid); if (pLocaleSet) { CXFA_Node* pNodeLocale = pLocaleSet->GetNodeItem(XFA_NODEITEM_FirstChild); while (pNodeLocale) { - m_LocaleArray.Add(new CXFA_NodeLocale(pNodeLocale)); + m_LocaleArray.emplace_back(new CXFA_NodeLocale(pNodeLocale)); pNodeLocale = pNodeLocale->GetNodeItem(XFA_NODEITEM_NextSibling); } } m_pDefLocale = GetLocaleByName(wsDeflcid); } -CXFA_LocaleMgr::~CXFA_LocaleMgr() { - for (int32_t i = 0; i < m_LocaleArray.GetSize(); i++) - m_LocaleArray[i]->Release(); - for (int32_t j = 0; j < m_XMLLocaleArray.GetSize(); j++) - m_XMLLocaleArray[j]->Release(); -} -void CXFA_LocaleMgr::Release() { - delete this; -} -uint16_t CXFA_LocaleMgr::GetDefLocaleID() { +CXFA_LocaleMgr::~CXFA_LocaleMgr() {} + +uint16_t CXFA_LocaleMgr::GetDefLocaleID() const { return m_dwDeflcid; } @@ -1149,101 +1144,82 @@ IFX_Locale* CXFA_LocaleMgr::GetDefLocale() { if (m_pDefLocale) return m_pDefLocale; - if (m_LocaleArray.GetSize()) - return m_LocaleArray[0]; + if (!m_LocaleArray.empty()) + return m_LocaleArray[0].get(); - if (m_XMLLocaleArray.GetSize()) - return m_XMLLocaleArray[0]; + if (!m_XMLLocaleArray.empty()) + return m_XMLLocaleArray[0].get(); - m_pDefLocale = GetLocale(m_dwDeflcid); - if (m_pDefLocale) - m_XMLLocaleArray.Add(m_pDefLocale); + std::unique_ptr<IFX_Locale> locale(GetLocale(m_dwDeflcid)); + m_pDefLocale = locale.get(); + if (locale) + m_XMLLocaleArray.push_back(std::move(locale)); return m_pDefLocale; } -IFX_Locale* CXFA_LocaleMgr::GetLocale(uint16_t lcid) { - IFX_Locale* pLocal = nullptr; +std::unique_ptr<IFX_Locale> CXFA_LocaleMgr::GetLocale(uint16_t lcid) { switch (lcid) { case XFA_LANGID_zh_CN: - pLocal = XFA_GetLocaleFromBuffer(g_zhCN_Locale, sizeof(g_zhCN_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_zhCN_Locale, sizeof(g_zhCN_Locale)); case XFA_LANGID_zh_TW: - pLocal = XFA_GetLocaleFromBuffer(g_zhTW_Locale, sizeof(g_zhTW_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_zhTW_Locale, sizeof(g_zhTW_Locale)); case XFA_LANGID_zh_HK: - pLocal = XFA_GetLocaleFromBuffer(g_zhHK_Locale, sizeof(g_zhHK_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_zhHK_Locale, sizeof(g_zhHK_Locale)); case XFA_LANGID_ja_JP: - pLocal = XFA_GetLocaleFromBuffer(g_jaJP_Locale, sizeof(g_jaJP_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_jaJP_Locale, sizeof(g_jaJP_Locale)); case XFA_LANGID_ko_KR: - pLocal = XFA_GetLocaleFromBuffer(g_koKR_Locale, sizeof(g_koKR_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_koKR_Locale, sizeof(g_koKR_Locale)); case XFA_LANGID_en_GB: - pLocal = XFA_GetLocaleFromBuffer(g_enGB_Locale, sizeof(g_enGB_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_enGB_Locale, sizeof(g_enGB_Locale)); case XFA_LANGID_es_LA: - pLocal = XFA_GetLocaleFromBuffer(g_esLA_Locale, sizeof(g_esLA_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_esLA_Locale, sizeof(g_esLA_Locale)); case XFA_LANGID_es_ES: - pLocal = XFA_GetLocaleFromBuffer(g_esES_Locale, sizeof(g_esES_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_esES_Locale, sizeof(g_esES_Locale)); case XFA_LANGID_de_DE: - pLocal = XFA_GetLocaleFromBuffer(g_deDE_Loacale, sizeof(g_deDE_Loacale)); - break; + return XFA_GetLocaleFromBuffer(g_deDE_Loacale, sizeof(g_deDE_Loacale)); case XFA_LANGID_fr_FR: - pLocal = XFA_GetLocaleFromBuffer(g_frFR_Locale, sizeof(g_frFR_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_frFR_Locale, sizeof(g_frFR_Locale)); case XFA_LANGID_it_IT: - pLocal = XFA_GetLocaleFromBuffer(g_itIT_Locale, sizeof(g_itIT_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_itIT_Locale, sizeof(g_itIT_Locale)); case XFA_LANGID_pt_BR: - pLocal = XFA_GetLocaleFromBuffer(g_ptBR_Locale, sizeof(g_ptBR_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_ptBR_Locale, sizeof(g_ptBR_Locale)); case XFA_LANGID_nl_NL: - pLocal = XFA_GetLocaleFromBuffer(g_nlNL_Locale, sizeof(g_nlNL_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_nlNL_Locale, sizeof(g_nlNL_Locale)); case XFA_LANGID_ru_RU: - pLocal = XFA_GetLocaleFromBuffer(g_ruRU_Locale, sizeof(g_ruRU_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_ruRU_Locale, sizeof(g_ruRU_Locale)); case XFA_LANGID_en_US: default: - pLocal = XFA_GetLocaleFromBuffer(g_enUS_Locale, sizeof(g_enUS_Locale)); - break; + return XFA_GetLocaleFromBuffer(g_enUS_Locale, sizeof(g_enUS_Locale)); } - return pLocal; } + IFX_Locale* CXFA_LocaleMgr::GetLocaleByName( const CFX_WideString& wsLocaleName) { - int32_t iCount = m_LocaleArray.GetSize(); - int32_t i = 0; - for (i = 0; i < iCount; i++) { - IFX_Locale* pLocale = m_LocaleArray[i]; - if (pLocale->GetName() == wsLocaleName) { + for (size_t i = 0; i < m_LocaleArray.size(); i++) { + IFX_Locale* pLocale = m_LocaleArray[i].get(); + if (pLocale->GetName() == wsLocaleName) return pLocale; - } } - int32_t iLen = wsLocaleName.GetLength(); - if (iLen < 2) { + if (wsLocaleName.GetLength() < 2) return nullptr; - } - iCount = m_XMLLocaleArray.GetSize(); - for (i = 0; i < iCount; i++) { - IFX_Locale* pLocale = m_XMLLocaleArray[i]; - if (pLocale->GetName() == wsLocaleName) { + for (size_t i = 0; i < m_XMLLocaleArray.size(); i++) { + IFX_Locale* pLocale = m_XMLLocaleArray[i].get(); + if (pLocale->GetName() == wsLocaleName) return pLocale; - } } uint16_t dwLangueID = XFA_GetLanguage(wsLocaleName); - IFX_Locale* pLocale = GetLocale(dwLangueID); + std::unique_ptr<IFX_Locale> pLocale(GetLocale(dwLangueID)); + IFX_Locale* pRetLocale = pLocale.get(); if (pLocale) - m_XMLLocaleArray.Add(pLocale); - return pLocale; + m_XMLLocaleArray.push_back(std::move(pLocale)); + return pRetLocale; } + void CXFA_LocaleMgr::SetDefLocale(IFX_Locale* pLocale) { m_pDefLocale = pLocale; } + CFX_WideStringC CXFA_LocaleMgr::GetConfigLocaleName(CXFA_Node* pConfig) { if (!(m_dwLocaleFlags & 0x01)) { m_wsConfigLocale.clear(); @@ -1268,6 +1244,7 @@ CFX_WideStringC CXFA_LocaleMgr::GetConfigLocaleName(CXFA_Node* pConfig) { } return m_wsConfigLocale.AsStringC(); } + static CXFA_TimeZoneProvider* g_pProvider = nullptr; // Static. @@ -1303,10 +1280,13 @@ CXFA_TimeZoneProvider::CXFA_TimeZoneProvider() { m_tz.tzMinute = (int8_t)((FXSYS_abs((int)timezone) % 3600) / 60); #endif } + CXFA_TimeZoneProvider::~CXFA_TimeZoneProvider() {} + void CXFA_TimeZoneProvider::SetTimeZone(FX_TIMEZONE& tz) { m_tz = tz; } + void CXFA_TimeZoneProvider::GetTimeZone(FX_TIMEZONE& tz) { tz = m_tz; } diff --git a/xfa/fxfa/parser/xfa_localemgr.h b/xfa/fxfa/parser/xfa_localemgr.h index 7051fc9ac3..51c6a3b5fb 100644 --- a/xfa/fxfa/parser/xfa_localemgr.h +++ b/xfa/fxfa/parser/xfa_localemgr.h @@ -7,6 +7,9 @@ #ifndef XFA_FXFA_PARSER_XFA_LOCALEMGR_H_ #define XFA_FXFA_PARSER_XFA_LOCALEMGR_H_ +#include <memory> +#include <vector> + #include "xfa/fgas/localization/fgas_datetime.h" #include "xfa/fgas/localization/fgas_locale.h" #include "xfa/fxfa/parser/xfa_localemgr.h" @@ -36,19 +39,19 @@ class CXFA_LocaleMgr : public IFX_LocaleMgr { ~CXFA_LocaleMgr() override; // IFX_LocaleMgr - void Release() override; - uint16_t GetDefLocaleID() override; + uint16_t GetDefLocaleID() const override; IFX_Locale* GetDefLocale() override; - IFX_Locale* GetLocale(uint16_t lcid) override; IFX_Locale* GetLocaleByName(const CFX_WideString& wsLocaleName) override; void SetDefLocale(IFX_Locale* pLocale); CFX_WideStringC GetConfigLocaleName(CXFA_Node* pConfig); protected: - CFX_ArrayTemplate<IFX_Locale*> m_LocaleArray; - CFX_ArrayTemplate<IFX_Locale*> m_XMLLocaleArray; - IFX_Locale* m_pDefLocale; + std::unique_ptr<IFX_Locale> GetLocale(uint16_t lcid) override; + + std::vector<std::unique_ptr<IFX_Locale>> m_LocaleArray; + std::vector<std::unique_ptr<IFX_Locale>> m_XMLLocaleArray; + IFX_Locale* m_pDefLocale; // owned by m_LocaleArray or m_XMLLocaleArray. CFX_WideString m_wsConfigLocale; uint16_t m_dwDeflcid; uint16_t m_dwLocaleFlags; |