summaryrefslogtreecommitdiff
path: root/i18npool/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2010-10-20 10:16:51 +0100
committerCaolán McNamara <caolanm@redhat.com>2010-10-20 10:16:51 +0100
commitff41dd83e5041e1289f3f9f425e148b4b78a74b0 (patch)
tree83643557417ef9ab8b955f478e30bdf5c2897f42 /i18npool/source
parent305a9e0468498d0b8322cd4292a574c2b50c217c (diff)
remove memory leaks to make this a handy valgrind test case
Diffstat (limited to 'i18npool/source')
-rw-r--r--i18npool/source/localedata/LocaleNode.cxx140
-rw-r--r--i18npool/source/localedata/LocaleNode.hxx4
-rw-r--r--i18npool/source/localedata/saxparser.cxx9
3 files changed, 76 insertions, 77 deletions
diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx
index 73dbc6674cab..7b8cceb09bd3 100644
--- a/i18npool/source/localedata/LocaleNode.cxx
+++ b/i18npool/source/localedata/LocaleNode.cxx
@@ -50,7 +50,7 @@ namespace cssi = ::com::sun::star::i18n;
LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList > & attr)
: aName(name)
- , xAttribs(new Attr(attr))
+ , aAttribs(attr)
, parent(0)
, children(0)
, nChildren(0)
@@ -85,11 +85,10 @@ void LocaleNode::printR () const {
void LocaleNode::addChild ( LocaleNode * node) {
if (childArrSize <= nChildren) {
- LocaleNode ** arrN = (LocaleNode **)malloc( sizeof (LocaleNode *)*(childArrSize+10) ) ;
- for (sal_Int32 i = 0; i<childArrSize ; i++)
+ LocaleNode ** arrN = new LocaleNode*[childArrSize+10];
+ for (sal_Int32 i = 0; i<childArrSize; ++i)
arrN[i] = children[i];
- if ( childArrSize > 0 )
- free(children);
+ delete [] children;
childArrSize += 10;
children = arrN;
}
@@ -121,9 +120,11 @@ const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
return 0;
}
- LocaleNode::~LocaleNode() {
- for (sal_Int32 i=0; i<nChildren;i++)
- delete (children[i]);
+LocaleNode::~LocaleNode()
+{
+ for (sal_Int32 i=0; i < nChildren; ++i)
+ delete children[i];
+ delete [] children;
}
LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
@@ -191,22 +192,19 @@ void print_node( const LocaleNode* p, int depth=0 )
print_color(36);
print_OUString( p->getName() );
print_color(0);
- const Attr* q = p->getAttr();
- if( q )
+ const Attr& q = p->getAttr();
+ for( sal_Int32 j = 0; j < q.getLength(); ++j )
{
- for( sal_Int32 j=0; j<q->getLength(); j++ )
- {
- printf(" ");
- print_color(33);
- print_OUString( q->getTypeByIndex(j) );
- print_color(0);
- printf("=");
- print_color(31);
- printf("'");
- print_OUString( q->getValueByIndex(j) );
- printf("'");
- print_color(0);
- }
+ printf(" ");
+ print_color(33);
+ print_OUString( q.getTypeByIndex(j) );
+ print_color(0);
+ printf("=");
+ print_color(31);
+ printf("'");
+ print_OUString( q.getValueByIndex(j) );
+ printf("'");
+ print_color(0);
}
printf(">");
printf("\n");
@@ -234,7 +232,7 @@ void print_node( const LocaleNode* p, int depth=0 )
void LocaleNode :: generateCode (const OFileWriter &of) const
{
- ::rtl::OUString aDTD = getAttr()->getValueByName("versionDTD");
+ ::rtl::OUString aDTD = getAttr().getValueByName("versionDTD");
if (!aDTD.equalsAscii( LOCALE_VERSION_DTD))
{
++nError;
@@ -380,12 +378,12 @@ void LCInfoNode::generateCode (const OFileWriter &of) const
void LCCTYPENode::generateCode (const OFileWriter &of) const
{
const LocaleNode * sepNode = 0;
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getLocaleItem_", useLocale);
return;
}
- ::rtl::OUString str = getAttr() -> getValueByName("unoid");
+ ::rtl::OUString str = getAttr().getValueByName("unoid");
of.writeAsciiString("\n\n");
of.writeParameter("LC_CTYPE_Unoid", str);;
@@ -541,13 +539,13 @@ void LCFormatNode::generateCode (const OFileWriter &of) const
OUString str;
if (mnSection >= 2)
incError("more than 2 LC_FORMAT sections");
- of.writeParameter("replaceFrom", getAttr() -> getValueByName("replaceFrom"), mnSection);
- str = getAttr() -> getValueByName("replaceTo");
+ of.writeParameter("replaceFrom", getAttr().getValueByName("replaceFrom"), mnSection);
+ str = getAttr().getValueByName("replaceTo");
// Locale data generator inserts FFFF for LangID, we need to adapt that.
if (str.endsWithIgnoreAsciiCaseAsciiL( "-FFFF]", 6))
incErrorStr("replaceTo=\"%s\" needs FFFF to be adapted to the real LangID value.", str);
of.writeParameter("replaceTo", str, mnSection);
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
switch (mnSection)
{
@@ -572,25 +570,25 @@ void LCFormatNode::generateCode (const OFileWriter &of) const
OUString aType;
OUString aFormatIndex;
// currNode -> print();
- const Attr * currNodeAttr = currNode->getAttr();
- //printf ("getLen() = %d\n", currNode->getAttr()->getLength());
+ const Attr &currNodeAttr = currNode->getAttr();
+ //printf ("getLen() = %d\n", currNode->getAttr().getLength());
- str = currNodeAttr -> getValueByName("msgid");
+ str = currNodeAttr.getValueByName("msgid");
if (!aMsgIdSet.insert( str).second)
incErrorStr( "Duplicated msgid=\"%s\" in FormatElement.", str);
of.writeParameter("FormatKey", str, formatCount);
- str = currNodeAttr -> getValueByName("default");
+ str = currNodeAttr.getValueByName("default");
bool bDefault = str.equalsAscii( "true");
of.writeDefaultParameter("FormatElement", str, formatCount);
- aType = currNodeAttr -> getValueByName("type");
+ aType = currNodeAttr.getValueByName("type");
of.writeParameter("FormatType", aType, formatCount);
- aUsage = currNodeAttr -> getValueByName("usage");
+ aUsage = currNodeAttr.getValueByName("usage");
of.writeParameter("FormatUsage", aUsage, formatCount);
- aFormatIndex = currNodeAttr -> getValueByName("formatindex");
+ aFormatIndex = currNodeAttr.getValueByName("formatindex");
sal_Int16 formatindex = (sal_Int16)aFormatIndex.toInt32();
if (!aFormatIndexSet.insert( formatindex).second)
incErrorInt( "Duplicated formatindex=\"%d\" in FormatElement.", formatindex);
@@ -635,7 +633,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const
incError( "No LC_CTYPE found for FormatCode.");
else
{
- OUString aRef( pCtype->getAttr()->getValueByName("ref"));
+ OUString aRef( pCtype->getAttr().getValueByName("ref"));
if (aRef.getLength() > 0)
{
if (!bCtypeIsRef)
@@ -863,7 +861,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const
void LCCollationNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getCollatorImplementation_", useLocale);
of.writeRefFunction("getCollationOptions_", useLocale);
@@ -878,11 +876,11 @@ void LCCollationNode::generateCode (const OFileWriter &of) const
if( currNode->getName().compareToAscii("Collator") == 0 )
{
::rtl::OUString str;
- str = currNode->getAttr() -> getValueByName("unoid");
+ str = currNode->getAttr().getValueByName("unoid");
of.writeParameter("CollatorID", str, j);
str = currNode->getValue();
of.writeParameter("CollatorRule", str, j);
- str = currNode -> getAttr() -> getValueByName("default");
+ str = currNode -> getAttr().getValueByName("default");
of.writeDefaultParameter("Collator", str, j);
of.writeAsciiString("\n");
@@ -936,7 +934,7 @@ void LCCollationNode::generateCode (const OFileWriter &of) const
void LCSearchNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getSearchOptions_", useLocale);
return;
@@ -974,7 +972,7 @@ void LCSearchNode::generateCode (const OFileWriter &of) const
void LCIndexNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getIndexAlgorithm_", useLocale);
of.writeRefFunction("getUnicodeScripts_", useLocale);
@@ -990,15 +988,15 @@ void LCIndexNode::generateCode (const OFileWriter &of) const
if( currNode->getName().compareToAscii("IndexKey") == 0 )
{
::rtl::OUString str;
- str = currNode->getAttr() -> getValueByName("unoid");
+ str = currNode->getAttr().getValueByName("unoid");
of.writeParameter("IndexID", str, nbOfIndexs);
- str = currNode->getAttr() -> getValueByName("module");
+ str = currNode->getAttr().getValueByName("module");
of.writeParameter("IndexModule", str, nbOfIndexs);
str = currNode->getValue();
of.writeParameter("IndexKey", str, nbOfIndexs);
- str = currNode -> getAttr() -> getValueByName("default");
+ str = currNode -> getAttr().getValueByName("default");
of.writeDefaultParameter("Index", str, nbOfIndexs);
- str = currNode -> getAttr() -> getValueByName("phonetic");
+ str = currNode -> getAttr().getValueByName("phonetic");
of.writeDefaultParameter("Phonetic", str, nbOfIndexs);
of.writeAsciiString("\n");
@@ -1076,7 +1074,7 @@ void LCIndexNode::generateCode (const OFileWriter &of) const
void LCCalendarNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getAllCalendars_", useLocale);
return;
@@ -1093,21 +1091,21 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const
for ( i = 0; i < nbOfCalendars; i++) {
LocaleNode * calNode = getChildAt (i);
- OUString calendarID = calNode -> getAttr() -> getValueByName("unoid");
+ OUString calendarID = calNode -> getAttr().getValueByName("unoid");
of.writeParameter( "calendarID", calendarID, i);
bool bGregorian = calendarID.equalsAscii( "gregorian");
if (!bHasGregorian)
bHasGregorian = bGregorian;
- str = calNode -> getAttr() -> getValueByName("default");
+ str = calNode -> getAttr().getValueByName("default");
of.writeDefaultParameter("Calendar", str, i);
// Generate Days of Week
const sal_Char *elementTag;
LocaleNode * daysNode = NULL;
- ::rtl::OUString ref_name = calNode->getChildAt(0)->getAttr()->getValueByName("ref");
+ ::rtl::OUString ref_name = calNode->getChildAt(0)->getAttr().getValueByName("ref");
if (ref_name.getLength() > 0 && i > 0) {
for (j = 0; j < i; j++) {
- str = getChildAt(j)->getAttr()->getValueByName("unoid");
+ str = getChildAt(j)->getAttr().getValueByName("unoid");
if (str.equals(ref_name))
daysNode = getChildAt(j)->getChildAt(0);
}
@@ -1136,10 +1134,10 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const
// Generate Months of Year
LocaleNode * monthsNode = NULL;
- ref_name = calNode->getChildAt(1)->getAttr()->getValueByName("ref");
+ ref_name = calNode->getChildAt(1)->getAttr().getValueByName("ref");
if (ref_name.getLength() > 0 && i > 0) {
for (j = 0; j < i; j++) {
- str = getChildAt(j)->getAttr()->getValueByName("unoid");
+ str = getChildAt(j)->getAttr().getValueByName("unoid");
if (str.equals(ref_name))
monthsNode = getChildAt(j)->getChildAt(1);
}
@@ -1168,10 +1166,10 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const
// Generate Era name
LocaleNode * erasNode = NULL;
- ref_name = calNode -> getChildAt(2) ->getAttr()->getValueByName("ref");
+ ref_name = calNode -> getChildAt(2) ->getAttr().getValueByName("ref");
if (ref_name.getLength() > 0 && i > 0) {
for (j = 0; j < i; j++) {
- str = getChildAt(j)->getAttr()->getValueByName("unoid");
+ str = getChildAt(j)->getAttr().getValueByName("unoid");
if (str.equals(ref_name))
erasNode = getChildAt(j)->getChildAt(2);
}
@@ -1325,7 +1323,7 @@ bool isIso4217( const OUString& rStr )
void LCCurrencyNode :: generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getAllCurrencies_", useLocale);
return;
@@ -1338,11 +1336,11 @@ void LCCurrencyNode :: generateCode (const OFileWriter &of) const
bool bTheCompatible = false;
for ( i = 0; i < getNumberOfChildren(); i++,nbOfCurrencies++) {
LocaleNode * calNode = getChildAt (i);
- str = calNode->getAttr() -> getValueByName("default");
+ str = calNode->getAttr().getValueByName("default");
bool bDefault = of.writeDefaultParameter("Currency", str, nbOfCurrencies);
- str = calNode->getAttr() -> getValueByName("usedInCompatibleFormatCodes");
+ str = calNode->getAttr().getValueByName("usedInCompatibleFormatCodes");
bool bCompatible = of.writeDefaultParameter("CurrencyUsedInCompatibleFormatCodes", str, nbOfCurrencies);
- str = calNode->getAttr() -> getValueByName("legacyOnly");
+ str = calNode->getAttr().getValueByName("legacyOnly");
bool bLegacy = of.writeDefaultParameter("CurrencyLegacyOnly", str, nbOfCurrencies);
if (bLegacy && (bDefault || bCompatible))
incError( "Currency: if legacyOnly==true, both 'default' and 'usedInCompatibleFormatCodes' must be false.");
@@ -1420,7 +1418,7 @@ void LCCurrencyNode :: generateCode (const OFileWriter &of) const
void LCTransliterationNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getTransliterations_", useLocale);
return;
@@ -1431,7 +1429,7 @@ void LCTransliterationNode::generateCode (const OFileWriter &of) const
for ( i = 0; i < getNumberOfChildren(); i++,nbOfModules++) {
LocaleNode * calNode = getChildAt (i);
- str = calNode->getAttr() -> getValueByIndex(0);
+ str = calNode->getAttr().getValueByIndex(0);
of.writeParameter("Transliteration", str, nbOfModules);
}
of.writeAsciiString("static const sal_Int16 nbOfTransliterations = ");
@@ -1469,7 +1467,7 @@ static NameValuePair ReserveWord[] = {
void LCMiscNode::generateCode (const OFileWriter &of) const
{
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction("getForbiddenCharacters_", useLocale);
of.writeRefFunction("getBreakIteratorRules_", useLocale);
@@ -1566,7 +1564,7 @@ void LCMiscNode::generateCode (const OFileWriter &of) const
void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
{
of.writeAsciiString("// ---> ContinuousNumbering\n");
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction2("getContinuousNumberingLevels_", useLocale);
return;
@@ -1581,13 +1579,13 @@ void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
sal_Int32 nStyles = getNumberOfChildren();
sal_Int32 i;
- for( i = 0; i < nStyles; i++ )
+ for( i = 0; i < nStyles; ++i )
{
- const Attr* q = getChildAt( i )->getAttr();
- for( sal_Int32 j=0; j<nAttributes; j++ )
+ const Attr &q = getChildAt( i )->getAttr();
+ for( sal_Int32 j=0; j<nAttributes; ++j )
{
const char* name = attr[j];
- OUString value = q->getValueByName( name );
+ OUString value = q.getValueByName( name );
of.writeParameter("continuous", name, value, sal::static_int_cast<sal_Int16>(i) );
}
}
@@ -1636,7 +1634,7 @@ void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
void LCOutlineNumberingLevelNode::generateCode (const OFileWriter &of) const
{
of.writeAsciiString("// ---> OutlineNumbering\n");
- ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
+ ::rtl::OUString useLocale = getAttr().getValueByName("ref");
if (useLocale.getLength() > 0) {
of.writeRefFunction3("getOutlineNumberingLevels_", useLocale);
return;
@@ -1669,11 +1667,11 @@ void LCOutlineNumberingLevelNode::generateCode (const OFileWriter &of) const
nLevels.push_back( p->getNumberOfChildren() );
for( sal_Int32 j=0; j<nLevels.back(); j++ )
{
- const Attr* q = p->getChildAt( j )->getAttr();
- for( sal_Int32 k=0; k<nAttributes; k++ )
+ const Attr& q = p->getChildAt( j )->getAttr();
+ for( sal_Int32 k=0; k<nAttributes; ++k )
{
const char* name = attr[k];
- OUString value = q->getValueByName( name );
+ OUString value = q.getValueByName( name );
of.writeParameter("outline", name, value,
sal::static_int_cast<sal_Int16>(i),
sal::static_int_cast<sal_Int16>(j) );
diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx
index f77e56f82267..fb3506389ac4 100644
--- a/i18npool/source/localedata/LocaleNode.hxx
+++ b/i18npool/source/localedata/LocaleNode.hxx
@@ -108,7 +108,7 @@ class LocaleNode
{
OUString aName;
OUString aValue;
- Attr * xAttribs;
+ Attr aAttribs;
LocaleNode * parent;
LocaleNode* * children;
sal_Int32 nChildren;
@@ -124,7 +124,7 @@ public:
inline void setValue(const OUString &oValue) { aValue += oValue; };
inline const OUString& getName() const { return aName; };
inline const OUString& getValue() const { return aValue; };
- inline const Attr* getAttr() const { return xAttribs; };
+ inline const Attr& getAttr() const { return aAttribs; };
inline sal_Int32 getNumberOfChildren () const { return nChildren; };
inline LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
const LocaleNode * findNode ( const sal_Char *name) const;
diff --git a/i18npool/source/localedata/saxparser.cxx b/i18npool/source/localedata/saxparser.cxx
index 349d833e3025..dd6c02225cef 100644
--- a/i18npool/source/localedata/saxparser.cxx
+++ b/i18npool/source/localedata/saxparser.cxx
@@ -157,6 +157,7 @@ public:
~TestDocumentHandler( )
{
of.closeOutput();
+ delete rootNode;
}
@@ -227,24 +228,24 @@ public: // ExtendedDocumentHandler
LocaleNode * l = LocaleNode::createNode (aName, xAttribs);
if (!currentNode.empty() ) {
- LocaleNode * ln = (LocaleNode *) currentNode . top();
+ LocaleNode * ln = (LocaleNode *) currentNode.top();
ln->addChild(l);
} else {
rootNode = l;
}
- currentNode . push (l);
+ currentNode.push (l);
}
virtual void SAL_CALL endElement(const OUString& /*aName*/) throw (SAXException,RuntimeException)
{
- currentNode . pop();
+ currentNode.pop();
}
virtual void SAL_CALL characters(const OUString& aChars) throw (SAXException,RuntimeException)
{
- LocaleNode * l = currentNode . top();
+ LocaleNode * l = currentNode.top();
l->setValue (aChars);
::rtl::OUString str(aChars);
sal_Unicode nonBreakSPace[2]= {0xa, 0x0};