summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-06-26 09:41:14 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-06-27 08:42:36 +0200
commit513ac8eb79e45de332d7ddab5b27c70578b904f1 (patch)
tree46f35b236d75651eb612a088e2cdfd48aa85a21c /i18npool
parent72b706d7def9e4805e35f3174170dad422b2e7f8 (diff)
loplugin:useuniqueptr in various
extending it to find places we can use std::unique_ptr on arrays Change-Id: I9feb1d12d738d6931e752ecb6dd51cbc1540c81b Reviewed-on: https://gerrit.libreoffice.org/39255 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/localedata/LocaleNode.cxx24
-rw-r--r--i18npool/source/localedata/LocaleNode.hxx7
-rw-r--r--i18npool/source/search/levdis.hxx13
3 files changed, 13 insertions, 31 deletions
diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx
index c1c5aaa81e32..8464775b2b2d 100644
--- a/i18npool/source/localedata/LocaleNode.cxx
+++ b/i18npool/source/localedata/LocaleNode.cxx
@@ -44,9 +44,6 @@ LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList >
: aName(name)
, aAttribs(attr)
, parent(nullptr)
- , children(nullptr)
- , nChildren(0)
- , childArrSize(0)
, nError(0)
{
}
@@ -54,7 +51,7 @@ LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList >
int LocaleNode::getError() const
{
int err = nError;
- for (sal_Int32 i=0;i<nChildren;i++)
+ for (size_t i=0;i<children.size();i++)
err += children[i]->getError();
return err;
}
@@ -69,22 +66,14 @@ void LocaleNode::print () const {
void LocaleNode::printR () const {
print();
- for (sal_Int32 i=0;i<nChildren;i++)
+ for (size_t i=0;i<children.size();i++)
children[i]->printR();
printf ("\t");
print();
}
void LocaleNode::addChild ( LocaleNode * node) {
- if (childArrSize <= nChildren) {
- LocaleNode ** arrN = new LocaleNode*[childArrSize+10];
- for (sal_Int32 i = 0; i<childArrSize; ++i)
- arrN[i] = children[i];
- delete [] children;
- childArrSize += 10;
- children = arrN;
- }
- children[nChildren++] = node;
+ children.push_back(node);
node->parent = this;
}
@@ -100,7 +89,7 @@ const LocaleNode* LocaleNode::getRoot() const
const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
if (aName.equalsAscii(name))
return this;
- for (sal_Int32 i = 0; i< nChildren; i++) {
+ for (size_t i = 0; i< children.size(); i++) {
const LocaleNode *n=children[i]->findNode(name);
if (n)
return n;
@@ -110,9 +99,8 @@ const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
LocaleNode::~LocaleNode()
{
- for (sal_Int32 i=0; i < nChildren; ++i)
+ for (size_t i=0; i < children.size(); ++i)
delete children[i];
- delete [] children;
}
LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
@@ -228,7 +216,7 @@ void LocaleNode::generateCode (const OFileWriter &of) const
++nError;
fprintf( stderr, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD);
}
- for (sal_Int32 i=0; i<nChildren;i++)
+ for (size_t i=0; i<children.size(); i++)
children[i]->generateCode (of);
// print_node( this );
}
diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx
index b64bdbb4ba0d..c3e6c57e6a22 100644
--- a/i18npool/source/localedata/LocaleNode.hxx
+++ b/i18npool/source/localedata/LocaleNode.hxx
@@ -18,6 +18,7 @@
*/
#ifndef INCLUDED_I18NPOOL_SOURCE_LOCALEDATA_LOCALENODE_HXX
#define INCLUDED_I18NPOOL_SOURCE_LOCALEDATA_LOCALENODE_HXX
+
#include <com/sun/star/xml/sax/XParser.hpp>
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
@@ -84,9 +85,7 @@ class LocaleNode
OUString aValue;
Attr aAttribs;
LocaleNode * parent;
- LocaleNode* * children;
- sal_Int32 nChildren;
- sal_Int32 childArrSize;
+ std::vector<LocaleNode*> children;
protected:
mutable int nError;
@@ -97,7 +96,7 @@ public:
const OUString& getName() const { return aName; };
const OUString& getValue() const { return aValue; };
const Attr& getAttr() const { return aAttribs; };
- sal_Int32 getNumberOfChildren () const { return nChildren; };
+ sal_Int32 getNumberOfChildren () const { return sal_Int32(children.size()); };
LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
const LocaleNode * findNode ( const sal_Char *name) const;
void print () const;
diff --git a/i18npool/source/search/levdis.hxx b/i18npool/source/search/levdis.hxx
index daf8778806a3..1c4604ffd11e 100644
--- a/i18npool/source/search/levdis.hxx
+++ b/i18npool/source/search/levdis.hxx
@@ -96,8 +96,8 @@
/** "Safe" memory allocation in ctor */
class WLevDisPatternMem
{
- sal_Unicode *cp;
- bool *bp;
+ std::unique_ptr<sal_Unicode[]> cp;
+ std::unique_ptr<bool[]> bp;
public:
explicit WLevDisPatternMem( sal_Int32 s )
: cp(new sal_Unicode[s])
@@ -105,13 +105,8 @@ public:
{
}
- ~WLevDisPatternMem()
- {
- delete [] cp;
- delete [] bp;
- }
- sal_Unicode* GetcPtr() const { return cp; }
- bool* GetbPtr() const { return bp; }
+ sal_Unicode* GetcPtr() const { return cp.get(); }
+ bool* GetbPtr() const { return bp.get(); }
};
class WLevDisDistanceMem