[Libreoffice-commits] core.git: include/svtools svtools/source
Caolán McNamara
caolanm at redhat.com
Mon Aug 29 09:45:38 UTC 2016
include/svtools/collatorres.hxx | 26 +++++++--
include/svtools/indexentryres.hxx | 25 +++++++--
svtools/source/control/collatorres.cxx | 73 +++++---------------------
svtools/source/control/indexentryres.cxx | 86 +++++--------------------------
4 files changed, 70 insertions(+), 140 deletions(-)
New commits:
commit 9ae319f938de37a9de1e8a8853af106b413a4bc7
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sun Aug 28 21:46:45 2016 +0100
coverity#1371317 avoid unnecessary copies
and coverity#1371211
Change-Id: I65e277c4af70a86f1513749de4eb116d929e858f
Reviewed-on: https://gerrit.libreoffice.org/28448
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/include/svtools/collatorres.hxx b/include/svtools/collatorres.hxx
index 762ea7b..5b41b61 100644
--- a/include/svtools/collatorres.hxx
+++ b/include/svtools/collatorres.hxx
@@ -22,19 +22,33 @@
#include <svtools/svtdllapi.h>
#include <rtl/ustring.hxx>
+#include <vector>
class CollatorResourceData;
class SVT_DLLPUBLIC CollatorResource
{
+private:
+ // wrapper for locale specific translations data of collator algorithm
+ class CollatorResourceData
+ {
+ friend class CollatorResource;
private:
-
- CollatorResourceData *mp_Data;
-
+ OUString m_aName;
+ OUString m_aTranslation;
public:
- CollatorResource();
- ~CollatorResource();
- const OUString& GetTranslation (const OUString& r_Algorithm);
+ CollatorResourceData(const OUString& rAlgorithm, const OUString& rTranslation)
+ : m_aName(rAlgorithm)
+ , m_aTranslation(rTranslation)
+ {
+ }
+ const OUString& GetAlgorithm() const { return m_aName; }
+ const OUString& GetTranslation() const { return m_aTranslation; }
+ };
+ std::vector<CollatorResourceData> m_aData;
+public:
+ CollatorResource();
+ const OUString& GetTranslation(const OUString& rAlgorithm);
};
#endif // INCLUDED_SVTOOLS_COLLATORRES_HXX
diff --git a/include/svtools/indexentryres.hxx b/include/svtools/indexentryres.hxx
index 89f8273..2de22b0 100644
--- a/include/svtools/indexentryres.hxx
+++ b/include/svtools/indexentryres.hxx
@@ -22,18 +22,33 @@
#include <svtools/svtdllapi.h>
#include <rtl/ustring.hxx>
+#include <vector>
class IndexEntryResourceData;
class SVT_DLLPUBLIC IndexEntryResource
{
+private:
+ // wrapper for locale specific translations data of indexentry algorithm
+ class IndexEntryResourceData
+ {
+ friend class IndexEntryResource;
private:
- IndexEntryResourceData *mp_Data;
-
+ OUString m_aName;
+ OUString m_aTranslation;
public:
- IndexEntryResource ();
- ~IndexEntryResource ();
- const OUString& GetTranslation (const OUString& r_Algorithm);
+ IndexEntryResourceData(const OUString& rAlgorithm, const OUString& rTranslation)
+ : m_aName(rAlgorithm)
+ , m_aTranslation(rTranslation)
+ {
+ }
+ const OUString& GetAlgorithm () const { return m_aName; }
+ const OUString& GetTranslation () const { return m_aTranslation; }
+ };
+ std::vector<IndexEntryResourceData> m_aData;
+public:
+ IndexEntryResource();
+ const OUString& GetTranslation(const OUString& rAlgorithm);
};
#endif // INCLUDED_SVTOOLS_INDEXENTRYRES_HXX
diff --git a/svtools/source/control/collatorres.cxx b/svtools/source/control/collatorres.cxx
index 26fc9a7..b11cfce 100644
--- a/svtools/source/control/collatorres.cxx
+++ b/svtools/source/control/collatorres.cxx
@@ -17,70 +17,27 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-
#include <svtools/svtresid.hxx>
#include <svtools/svtools.hrc>
#include <svtools/collatorres.hxx>
-
-// wrapper for locale specific translations data of collator algorithm
-
-
-class CollatorResourceData
-{
- friend class CollatorResource;
- private: /* data */
- OUString ma_Name;
- OUString ma_Translation;
- private: /* member functions */
- CollatorResourceData () {}
- public:
- CollatorResourceData ( const OUString &r_Algorithm, const OUString &r_Translation)
- : ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
-
- const OUString& GetAlgorithm () const { return ma_Name; }
-
- const OUString& GetTranslation () const { return ma_Translation; }
-
- ~CollatorResourceData () {}
-
- CollatorResourceData& operator= (const CollatorResourceData& r_From)
- {
- ma_Name = r_From.GetAlgorithm();
- ma_Translation = r_From.GetTranslation();
- return *this;
- }
-};
-
-
// implementation of the collator-algorithm-name translation
-
-
-#define COLLATOR_RESOURCE_COUNT (STR_SVT_COLLATE_END - STR_SVT_COLLATE_START + 1)
-
CollatorResource::CollatorResource()
{
- mp_Data = new CollatorResourceData[COLLATOR_RESOURCE_COUNT];
-
#define RESSTR(rid) SvtResId(rid).toString()
- mp_Data[0] = CollatorResourceData ("alphanumeric", RESSTR(STR_SVT_COLLATE_ALPHANUMERIC));
- mp_Data[1] = CollatorResourceData ("charset", RESSTR(STR_SVT_COLLATE_CHARSET));
- mp_Data[2] = CollatorResourceData ("dict", RESSTR(STR_SVT_COLLATE_DICTIONARY));
- mp_Data[3] = CollatorResourceData ("normal", RESSTR(STR_SVT_COLLATE_NORMAL));
- mp_Data[4] = CollatorResourceData ("pinyin", RESSTR(STR_SVT_COLLATE_PINYIN));
- mp_Data[5] = CollatorResourceData ("radical", RESSTR(STR_SVT_COLLATE_RADICAL));
- mp_Data[6] = CollatorResourceData ("stroke", RESSTR(STR_SVT_COLLATE_STROKE));
- mp_Data[7] = CollatorResourceData ("unicode", RESSTR(STR_SVT_COLLATE_UNICODE));
- mp_Data[8] = CollatorResourceData ("zhuyin", RESSTR(STR_SVT_COLLATE_ZHUYIN));
- mp_Data[9] = CollatorResourceData ("phonebook", RESSTR(STR_SVT_COLLATE_PHONEBOOK));
- mp_Data[10] = CollatorResourceData ("phonetic (alphanumeric first)", RESSTR(STR_SVT_COLLATE_PHONETIC_F));
- mp_Data[11] = CollatorResourceData ("phonetic (alphanumeric last)", RESSTR(STR_SVT_COLLATE_PHONETIC_L));
-}
-
-CollatorResource::~CollatorResource()
-{
- delete[] mp_Data;
+ m_aData.push_back(CollatorResourceData("alphanumeric", RESSTR(STR_SVT_COLLATE_ALPHANUMERIC)));
+ m_aData.push_back(CollatorResourceData("charset", RESSTR(STR_SVT_COLLATE_CHARSET)));
+ m_aData.push_back(CollatorResourceData("dict", RESSTR(STR_SVT_COLLATE_DICTIONARY)));
+ m_aData.push_back(CollatorResourceData("normal", RESSTR(STR_SVT_COLLATE_NORMAL)));
+ m_aData.push_back(CollatorResourceData("pinyin", RESSTR(STR_SVT_COLLATE_PINYIN)));
+ m_aData.push_back(CollatorResourceData("radical", RESSTR(STR_SVT_COLLATE_RADICAL)));
+ m_aData.push_back(CollatorResourceData("stroke", RESSTR(STR_SVT_COLLATE_STROKE)));
+ m_aData.push_back(CollatorResourceData("unicode", RESSTR(STR_SVT_COLLATE_UNICODE)));
+ m_aData.push_back(CollatorResourceData("zhuyin", RESSTR(STR_SVT_COLLATE_ZHUYIN)));
+ m_aData.push_back(CollatorResourceData("phonebook", RESSTR(STR_SVT_COLLATE_PHONEBOOK)));
+ m_aData.push_back(CollatorResourceData("phonetic (alphanumeric first)", RESSTR(STR_SVT_COLLATE_PHONETIC_F)));
+ m_aData.push_back(CollatorResourceData("phonetic (alphanumeric last)", RESSTR(STR_SVT_COLLATE_PHONETIC_L)));
}
const OUString&
@@ -99,10 +56,10 @@ CollatorResource::GetTranslation(const OUString &r_Algorithm)
aLocaleFreeAlgorithm = r_Algorithm.copy(nIndex, r_Algorithm.getLength() - nIndex);
}
- for (sal_uInt32 i = 0; i < COLLATOR_RESOURCE_COUNT; i++)
+ for (size_t i = 0; i < m_aData.size(); ++i)
{
- if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
- return mp_Data[i].GetTranslation();
+ if (aLocaleFreeAlgorithm == m_aData[i].GetAlgorithm())
+ return m_aData[i].GetTranslation();
}
return r_Algorithm;
diff --git a/svtools/source/control/indexentryres.cxx b/svtools/source/control/indexentryres.cxx
index 4fc91f0..11e1acf 100644
--- a/svtools/source/control/indexentryres.cxx
+++ b/svtools/source/control/indexentryres.cxx
@@ -22,77 +22,21 @@
#include <svtools/svtools.hrc>
#include <svtools/indexentryres.hxx>
-
-// wrapper for locale specific translations data of indexentry algorithm
-
-
-class IndexEntryResourceData
-{
- friend class IndexEntryResource;
- private: /* data */
- OUString ma_Name;
- OUString ma_Translation;
- private: /* member functions */
- IndexEntryResourceData () {}
- public:
- IndexEntryResourceData ( const OUString &r_Algorithm, const OUString &r_Translation)
- : ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
-
- const OUString& GetAlgorithm () const { return ma_Name; }
-
- const OUString& GetTranslation () const { return ma_Translation; }
-
- ~IndexEntryResourceData () {}
-
- IndexEntryResourceData& operator= (const IndexEntryResourceData& r_From)
- {
- ma_Name = r_From.GetAlgorithm();
- ma_Translation = r_From.GetTranslation();
- return *this;
- }
-};
-
-
// implementation of the indexentry-algorithm-name translation
-
-
-#define INDEXENTRY_RESOURCE_COUNT (STR_SVT_INDEXENTRY_END - STR_SVT_INDEXENTRY_START + 1)
-
IndexEntryResource::IndexEntryResource()
{
- mp_Data = new IndexEntryResourceData[INDEXENTRY_RESOURCE_COUNT];
-
- #define RESSTR(rid) SvtResId(rid).toString()
-
- mp_Data[STR_SVT_INDEXENTRY_ALPHANUMERIC - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("alphanumeric", RESSTR(STR_SVT_INDEXENTRY_ALPHANUMERIC));
- mp_Data[STR_SVT_INDEXENTRY_DICTIONARY - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("dict", RESSTR(STR_SVT_INDEXENTRY_DICTIONARY));
- mp_Data[STR_SVT_INDEXENTRY_PINYIN - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("pinyin", RESSTR(STR_SVT_INDEXENTRY_PINYIN));
- mp_Data[STR_SVT_INDEXENTRY_PINYIN - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("radical", RESSTR(STR_SVT_INDEXENTRY_RADICAL));
- mp_Data[STR_SVT_INDEXENTRY_STROKE - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("stroke", RESSTR(STR_SVT_INDEXENTRY_STROKE));
- mp_Data[STR_SVT_INDEXENTRY_STROKE - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("zhuyin", RESSTR(STR_SVT_INDEXENTRY_ZHUYIN));
- mp_Data[STR_SVT_INDEXENTRY_ZHUYIN - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("phonetic (alphanumeric first) (grouped by syllable)",
- RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FS));
- mp_Data[STR_SVT_INDEXENTRY_PHONETIC_FS - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("phonetic (alphanumeric first) (grouped by consonant)",
- RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FC));
- mp_Data[STR_SVT_INDEXENTRY_PHONETIC_FC - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("phonetic (alphanumeric last) (grouped by syllable)",
- RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LS));
- mp_Data[STR_SVT_INDEXENTRY_PHONETIC_LS - STR_SVT_INDEXENTRY_START] =
- IndexEntryResourceData ("phonetic (alphanumeric last) (grouped by consonant)",
- RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LC));
-}
-
-IndexEntryResource::~IndexEntryResource()
-{
- delete[] mp_Data;
+ #define RESSTR(rid) SvtResId(rid).toString()
+
+ m_aData.push_back(IndexEntryResourceData("alphanumeric", RESSTR(STR_SVT_INDEXENTRY_ALPHANUMERIC)));
+ m_aData.push_back(IndexEntryResourceData("dict", RESSTR(STR_SVT_INDEXENTRY_DICTIONARY)));
+ m_aData.push_back(IndexEntryResourceData("pinyin", RESSTR(STR_SVT_INDEXENTRY_PINYIN)));
+ m_aData.push_back(IndexEntryResourceData("radical", RESSTR(STR_SVT_INDEXENTRY_RADICAL)));
+ m_aData.push_back(IndexEntryResourceData("stroke", RESSTR(STR_SVT_INDEXENTRY_STROKE)));
+ m_aData.push_back(IndexEntryResourceData("zhuyin", RESSTR(STR_SVT_INDEXENTRY_ZHUYIN)));
+ m_aData.push_back(IndexEntryResourceData("phonetic (alphanumeric first) (grouped by syllable)", RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FS)));
+ m_aData.push_back(IndexEntryResourceData("phonetic (alphanumeric first) (grouped by consonant)", RESSTR(STR_SVT_INDEXENTRY_PHONETIC_FC)));
+ m_aData.push_back(IndexEntryResourceData("phonetic (alphanumeric last) (grouped by syllable)", RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LS)));
+ m_aData.push_back(IndexEntryResourceData("phonetic (alphanumeric last) (grouped by consonant)", RESSTR(STR_SVT_INDEXENTRY_PHONETIC_LC)));
}
const OUString& IndexEntryResource::GetTranslation(const OUString &r_Algorithm)
@@ -107,9 +51,9 @@ const OUString& IndexEntryResource::GetTranslation(const OUString &r_Algorithm)
aLocaleFreeAlgorithm = r_Algorithm.copy(nIndex, r_Algorithm.getLength() - nIndex);
}
- for (sal_uInt32 i = 0; i < INDEXENTRY_RESOURCE_COUNT; i++)
- if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
- return mp_Data[i].GetTranslation();
+ for (size_t i = 0; i < m_aData.size(); ++i)
+ if (aLocaleFreeAlgorithm == m_aData[i].GetAlgorithm())
+ return m_aData[i].GetTranslation();
return r_Algorithm;
}
More information about the Libreoffice-commits
mailing list