From 513ac8eb79e45de332d7ddab5b27c70578b904f1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 26 Jun 2017 09:41:14 +0200 Subject: 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 Reviewed-by: Noel Grandin --- svl/source/numbers/zformat.cxx | 77 +++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 46 deletions(-) (limited to 'svl') diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 6b06d6beed62..31073130b07b 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -269,8 +269,6 @@ sal_uInt8 SvNumberNatNum::MapNatNumToDBNum( sal_uInt8 nNatNum, LanguageType eLan ImpSvNumFor::ImpSvNumFor() { nAnzStrings = 0; - aI.nTypeArray = nullptr; - aI.sStrArray = nullptr; aI.eScannedType = css::util::NumberFormat::UNDEFINED; aI.bThousand = false; aI.nThousand = 0; @@ -282,27 +280,15 @@ ImpSvNumFor::ImpSvNumFor() ImpSvNumFor::~ImpSvNumFor() { - delete [] aI.sStrArray; - delete [] aI.nTypeArray; } void ImpSvNumFor::Enlarge(sal_uInt16 nAnz) { if ( nAnzStrings != nAnz ) { - delete [] aI.nTypeArray; - delete [] aI.sStrArray; nAnzStrings = nAnz; - if ( nAnz ) - { - aI.nTypeArray = new short[nAnz]; - aI.sStrArray = new OUString[nAnz]; - } - else - { - aI.nTypeArray = nullptr; - aI.sStrArray = nullptr; - } + aI.nTypeArray.resize(nAnz); + aI.sStrArray.resize(nAnz); } } @@ -3363,11 +3349,11 @@ bool SvNumberformat::ImpIsIso8601( const ImpSvNumFor& rNumFor ) const eNotIso }; State eState = eNone; - short const * const pType = rNumFor.Info().nTypeArray; + auto & rTypeArray = rNumFor.Info().nTypeArray; sal_uInt16 nAnz = rNumFor.GetCount(); for (sal_uInt16 i=0; i < nAnz && !bIsIso && eState != eNotIso; ++i) { - switch ( pType[i] ) + switch ( rTypeArray[i] ) { case NF_KEY_YY: // two digits not strictly ISO 8601 case NF_KEY_YYYY: @@ -4652,7 +4638,7 @@ const OUString* SvNumberformat::GetNumForString( sal_uInt16 nNumFor, sal_uInt16 nPos = nAnz - 1; if ( bString ) { // Backwards - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; + short const * pType = NumFor[nNumFor].Info().nTypeArray.data() + nPos; while ( nPos > 0 && (*pType != NF_SYMBOLTYPE_STRING) && (*pType != NF_SYMBOLTYPE_CURRENCY) ) { @@ -4672,7 +4658,7 @@ const OUString* SvNumberformat::GetNumForString( sal_uInt16 nNumFor, sal_uInt16 else if ( bString ) { // vorwaerts - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; + short const * pType = NumFor[nNumFor].Info().nTypeArray.data() + nPos; while ( nPos < nAnz && (*pType != NF_SYMBOLTYPE_STRING) && (*pType != NF_SYMBOLTYPE_CURRENCY) ) { @@ -4730,26 +4716,25 @@ bool SvNumberformat::IsNegativeInBracket() const { return false; } - OUString *tmpStr = NumFor[1].Info().sStrArray; - return tmpStr[0] == "(" && tmpStr[nAnz-1] == ")"; + auto& tmp = NumFor[1].Info().sStrArray; + return tmp[0] == "(" && tmp[nAnz-1] == ")"; } bool SvNumberformat::HasPositiveBracketPlaceholder() const { sal_uInt16 nAnz = NumFor[0].GetCount(); - OUString *tmpStr = NumFor[0].Info().sStrArray; - return tmpStr[nAnz-1] == "_)"; + return NumFor[0].Info().sStrArray[nAnz-1] == "_)"; } DateOrder SvNumberformat::GetDateOrder() const { if ( (eType & css::util::NumberFormat::DATE) == css::util::NumberFormat::DATE ) { - short const * const pType = NumFor[0].Info().nTypeArray; + auto& rTypeArray = NumFor[0].Info().nTypeArray; sal_uInt16 nAnz = NumFor[0].GetCount(); for ( sal_uInt16 j=0; j 1 && pStr[j][1] == '+' ) + if ( rStrArray[j].getLength() > 1 && rStrArray[j][1] == '+' ) aStr.append( "+" ); else // tdf#102370: Excel code for exponent without sign @@ -5070,33 +5055,33 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, break; case NF_SYMBOLTYPE_FRACBLANK : case NF_SYMBOLTYPE_STRING : - if ( pStr[j].getLength() == 1 ) + if ( rStrArray[j].getLength() == 1 ) { - if ( pType[j] == NF_SYMBOLTYPE_STRING ) + if ( rTypeArray[j] == NF_SYMBOLTYPE_STRING ) aStr.append( '\\' ); - aStr.append( pStr[j] ); + aStr.append( rStrArray[j] ); } else { aStr.append( '"' ); - aStr.append( pStr[j] ); + aStr.append( rStrArray[j] ); aStr.append( '"' ); } break; case NF_SYMBOLTYPE_CALDEL : - if ( pStr[j+1] == "gengou" ) + if ( rStrArray[j+1] == "gengou" ) { nCalendarID = 0x0030000; } - else if ( pStr[j+1] == "hijri" ) + else if ( rStrArray[j+1] == "hijri" ) { nCalendarID = 0x0060000; } - else if ( pStr[j+1] == "buddhist" ) + else if ( rStrArray[j+1] == "buddhist" ) { nCalendarID = 0x0070000; } - else if ( pStr[j+1] == "jewish" ) + else if ( rStrArray[j+1] == "jewish" ) { nCalendarID = 0x0080000; } @@ -5105,7 +5090,7 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, j = j+2; break; default: - aStr.append( pStr[j] ); + aStr.append( rStrArray[j] ); } } } @@ -5443,10 +5428,10 @@ sal_uInt16 SvNumberformat::ImpGetNumForStringElementCount( sal_uInt16 nNumFor ) { sal_uInt16 nCnt = 0; sal_uInt16 nAnz = NumFor[nNumFor].GetCount(); - short const * const pType = NumFor[nNumFor].Info().nTypeArray; + auto& rTypeArray = NumFor[nNumFor].Info().nTypeArray; for ( sal_uInt16 j=0; j