[Libreoffice-commits] core.git: i18npool/source i18nutil/source
Michael Weghorn
m.weghorn at posteo.de
Wed Dec 17 22:06:44 PST 2014
i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx | 2
i18npool/source/localedata/localedata.cxx | 65 ++--------
i18npool/source/search/levdis.cxx | 4
i18npool/source/transliteration/textToPronounce_zh.cxx | 5
i18nutil/source/utility/oneToOneMapping.cxx | 12 -
i18nutil/source/utility/widthfolding.cxx | 12 -
6 files changed, 32 insertions(+), 68 deletions(-)
New commits:
commit 652e09f734fefb9b49787e8e565d235d504a1e73
Author: Michael Weghorn <m.weghorn at posteo.de>
Date: Wed Dec 17 17:54:18 2014 +0100
fdo#39440 reduce scope of local variables
This addresses some cppcheck warnings.
Change-Id: I7e85aca5a86f993a9906525edffbd44a179dc245
Reviewed-on: https://gerrit.libreoffice.org/13510
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
Tested-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index 684ef2b..d790c19 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -395,7 +395,6 @@ void lcl_formatPersianWord( sal_Int32 nNumber, OUString& rsResult )
throw( IllegalArgumentException, RuntimeException )
{
OUStringBuffer aTemp(64);
- unsigned int nDigit;
static const sal_Unicode asPersianWord_conjunction_data[] = {0x20,0x0648,0x20,0};
OUString asPersianWord_conjunction( asPersianWord_conjunction_data );
unsigned char nSection = 0;
@@ -409,6 +408,7 @@ void lcl_formatPersianWord( sal_Int32 nNumber, OUString& rsResult )
aTemp.insert( 0, asPersianWord_conjunction).insert( 0, table_PersianWord_decadeX[nSection-1]);
}
+ unsigned int nDigit;
if ((nDigit = nPart % 100) < 20)
{
if (!aTemp.isEmpty())
diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx
index 85a16dc..875ab3c 100644
--- a/i18npool/source/localedata/localedata.cxx
+++ b/i18npool/source/localedata/localedata.cxx
@@ -369,13 +369,11 @@ LocaleDataImpl::~LocaleDataImpl()
LocaleDataItem SAL_CALL
LocaleDataImpl::getLocaleItem( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **dataItem = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLocaleItem" );
if ( func ) {
sal_Int16 dataItemCount = 0;
- dataItem = func(dataItemCount);
+ sal_Unicode **dataItem = func(dataItemCount);
LocaleDataItem item(
dataItem[0],
@@ -444,13 +442,11 @@ lcl_LookupTableHelper::lcl_LookupTableHelper()
lcl_LookupTableHelper::~lcl_LookupTableHelper()
{
- LocaleDataLookupTableItem* pItem = 0;
-
std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end());
std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin());
for ( ; aIter != aEnd; ++aIter ) {
- pItem = *aIter;
+ LocaleDataLookupTableItem* pItem = *aIter;
delete pItem->module;
delete pItem;
}
@@ -480,13 +476,12 @@ oslGenericFunction SAL_CALL lcl_LookupTableHelper::getFunctionSymbolByName(
(bFallback && aFallback.equalsAscii(aLibTable[i].pLocale)))
{
#ifndef DISABLE_DYNLOADING
- LocaleDataLookupTableItem* pCurrent = 0;
OUStringBuffer aBuf(strlen(aLibTable[i].pLocale) + 1 + strlen(pFunction));
{
::osl::MutexGuard aGuard( maMutex );
for (size_t l = 0; l < maLookupTable.size(); l++)
{
- pCurrent = maLookupTable[l];
+ LocaleDataLookupTableItem* pCurrent = maLookupTable[l];
if (pCurrent->dllName == aLibTable[i].pLib)
{
OSL_ASSERT( pOutCachedItem );
@@ -761,13 +756,11 @@ LocaleDataImpl::getAllCalendars( const Locale& rLocale ) throw(RuntimeException,
Sequence< Currency2 > SAL_CALL
LocaleDataImpl::getAllCurrencies2( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **allCurrencies = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCurrencies" );
if ( func ) {
sal_Int16 currencyCount = 0;
- allCurrencies = func(currencyCount);
+ sal_Unicode **allCurrencies = func(currencyCount);
Sequence< Currency2 > seq(currencyCount);
for(int i = 0, nOff = 0; i < currencyCount; i++, nOff += 8 ) {
@@ -896,14 +889,12 @@ LocaleDataImpl::getAllFormats( const Locale& rLocale ) throw(RuntimeException, s
Sequence< OUString > SAL_CALL
LocaleDataImpl::getDateAcceptancePatterns( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **patternsArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getDateAcceptancePatterns" );
if (func)
{
sal_Int16 patternsCount = 0;
- patternsArray = func( patternsCount );
+ sal_Unicode **patternsArray = func( patternsCount );
Sequence< OUString > seq( patternsCount );
for (sal_Int16 i = 0; i < patternsCount; ++i)
{
@@ -942,13 +933,11 @@ LocaleDataImpl::getCollatorRuleByAlgorithm( const Locale& rLocale, const OUStrin
Sequence< Implementation > SAL_CALL
LocaleDataImpl::getCollatorImplementations( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **collatorArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
if ( func ) {
sal_Int16 collatorCount = 0;
- collatorArray = func(collatorCount);
+ sal_Unicode **collatorArray = func(collatorCount);
Sequence< Implementation > seq(collatorCount);
for(sal_Int16 i = 0; i < collatorCount; i++) {
Implementation impl(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO],
@@ -967,13 +956,11 @@ LocaleDataImpl::getCollatorImplementations( const Locale& rLocale ) throw(Runtim
Sequence< OUString > SAL_CALL
LocaleDataImpl::getCollationOptions( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **optionsArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollationOptions" );
if ( func ) {
sal_Int16 optionsCount = 0;
- optionsArray = func(optionsCount);
+ sal_Unicode **optionsArray = func(optionsCount);
Sequence< OUString > seq(optionsCount);
for(sal_Int16 i = 0; i < optionsCount; i++) {
seq[i] = OUString( optionsArray[i] );
@@ -989,13 +976,11 @@ LocaleDataImpl::getCollationOptions( const Locale& rLocale ) throw(RuntimeExcept
Sequence< OUString > SAL_CALL
LocaleDataImpl::getSearchOptions( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **optionsArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getSearchOptions" );
if ( func ) {
sal_Int16 optionsCount = 0;
- optionsArray = func(optionsCount);
+ sal_Unicode **optionsArray = func(optionsCount);
Sequence< OUString > seq(optionsCount);
for(sal_Int16 i = 0; i < optionsCount; i++) {
seq[i] = OUString( optionsArray[i] );
@@ -1105,13 +1090,11 @@ LocaleDataImpl::getIndexModuleByAlgorithm( const Locale& rLocale, const OUString
Sequence< UnicodeScript > SAL_CALL
LocaleDataImpl::getUnicodeScripts( const Locale& rLocale ) throw(RuntimeException)
{
- sal_Unicode **scriptArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getUnicodeScripts" );
if ( func ) {
sal_Int16 scriptCount = 0;
- scriptArray = func(scriptCount);
+ sal_Unicode **scriptArray = func(scriptCount);
Sequence< UnicodeScript > seq(scriptCount);
for(sal_Int16 i = 0; i < scriptCount; i++) {
seq[i] = UnicodeScript( OUString(scriptArray[i]).toInt32() );
@@ -1127,13 +1110,11 @@ LocaleDataImpl::getUnicodeScripts( const Locale& rLocale ) throw(RuntimeExceptio
Sequence< OUString > SAL_CALL
LocaleDataImpl::getFollowPageWords( const Locale& rLocale ) throw(RuntimeException)
{
- sal_Unicode **wordArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getFollowPageWords" );
if ( func ) {
sal_Int16 wordCount = 0;
- wordArray = func(wordCount);
+ sal_Unicode **wordArray = func(wordCount);
Sequence< OUString > seq(wordCount);
for(sal_Int16 i = 0; i < wordCount; i++) {
seq[i] = OUString(wordArray[i]);
@@ -1149,14 +1130,11 @@ LocaleDataImpl::getFollowPageWords( const Locale& rLocale ) throw(RuntimeExcepti
Sequence< OUString > SAL_CALL
LocaleDataImpl::getTransliterations( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
-
- sal_Unicode **transliterationsArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getTransliterations" );
if ( func ) {
sal_Int16 transliterationsCount = 0;
- transliterationsArray = func(transliterationsCount);
+ sal_Unicode **transliterationsArray = func(transliterationsCount);
Sequence< OUString > seq(transliterationsCount);
for(int i = 0; i < transliterationsCount; i++) {
@@ -1177,14 +1155,11 @@ LocaleDataImpl::getTransliterations( const Locale& rLocale ) throw(RuntimeExcept
LanguageCountryInfo SAL_CALL
LocaleDataImpl::getLanguageCountryInfo( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
-
- sal_Unicode **LCInfoArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLCInfo" );
if ( func ) {
sal_Int16 LCInfoCount = 0;
- LCInfoArray = func(LCInfoCount);
+ sal_Unicode **LCInfoArray = func(LCInfoCount);
LanguageCountryInfo info(LCInfoArray[0],
LCInfoArray[1],
LCInfoArray[2],
@@ -1203,13 +1178,11 @@ LocaleDataImpl::getLanguageCountryInfo( const Locale& rLocale ) throw(RuntimeExc
ForbiddenCharacters SAL_CALL
LocaleDataImpl::getForbiddenCharacters( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **LCForbiddenCharactersArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
if ( func ) {
sal_Int16 LCForbiddenCharactersCount = 0;
- LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
+ sal_Unicode **LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
ForbiddenCharacters chars(LCForbiddenCharactersArray[0], LCForbiddenCharactersArray[1]);
return chars;
}
@@ -1222,13 +1195,11 @@ LocaleDataImpl::getForbiddenCharacters( const Locale& rLocale ) throw(RuntimeExc
OUString SAL_CALL
LocaleDataImpl::getHangingCharacters( const Locale& rLocale ) throw(RuntimeException)
{
- sal_Unicode **LCForbiddenCharactersArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
if ( func ) {
sal_Int16 LCForbiddenCharactersCount = 0;
- LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
+ sal_Unicode **LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
return OUString(LCForbiddenCharactersArray[2]);
}
@@ -1238,13 +1209,11 @@ LocaleDataImpl::getHangingCharacters( const Locale& rLocale ) throw(RuntimeExcep
Sequence< OUString > SAL_CALL
LocaleDataImpl::getBreakIteratorRules( const Locale& rLocale ) throw(RuntimeException)
{
- sal_Unicode **LCBreakIteratorRulesArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getBreakIteratorRules" );
if ( func ) {
sal_Int16 LCBreakIteratorRuleCount = 0;
- LCBreakIteratorRulesArray = func(LCBreakIteratorRuleCount);
+ sal_Unicode **LCBreakIteratorRulesArray = func(LCBreakIteratorRuleCount);
Sequence< OUString > seq(LCBreakIteratorRuleCount);
for(int i = 0; i < (LCBreakIteratorRuleCount); i++) {
OUString elem(LCBreakIteratorRulesArray[i]);
@@ -1262,13 +1231,11 @@ LocaleDataImpl::getBreakIteratorRules( const Locale& rLocale ) throw(RuntimeExc
Sequence< OUString > SAL_CALL
LocaleDataImpl::getReservedWord( const Locale& rLocale ) throw(RuntimeException, std::exception)
{
- sal_Unicode **LCReservedWordsArray = NULL;
-
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getReservedWords" );
if ( func ) {
sal_Int16 LCReservedWordsCount = 0;
- LCReservedWordsArray = func(LCReservedWordsCount);
+ sal_Unicode **LCReservedWordsArray = func(LCReservedWordsCount);
Sequence< OUString > seq(LCReservedWordsCount);
for(int i = 0; i < (LCReservedWordsCount); i++) {
OUString elem(LCReservedWordsArray[i]);
diff --git a/i18npool/source/search/levdis.cxx b/i18npool/source/search/levdis.cxx
index d2c0571..40e7291 100644
--- a/i18npool/source/search/levdis.cxx
+++ b/i18npool/source/search/levdis.cxx
@@ -167,7 +167,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
&& nSPMin <= (bSplitCount ? 2 * nLimit : nLimit) )
{
sal_Unicode c;
- int nP, nQ, nR, nPij, d1, d2;
+ int nP, nQ, nR, nPij, d2;
j++;
c = cpPattern[j];
@@ -193,7 +193,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
// for each pattern column run though the string
for ( sal_Int32 i=1; i <= nStringLen; i++ )
{
- d1 = d2; // WLD( X(i-1), Y(j-1) )
+ int d1 = d2; // WLD( X(i-1), Y(j-1) )
d2 = npDistance[i]; // WLD( X(i) , Y(j-1) )
if ( cString[i-1] == c )
{
diff --git a/i18npool/source/transliteration/textToPronounce_zh.cxx b/i18npool/source/transliteration/textToPronounce_zh.cxx
index cc2b8ee..5f96eb9 100644
--- a/i18npool/source/transliteration/textToPronounce_zh.cxx
+++ b/i18npool/source/transliteration/textToPronounce_zh.cxx
@@ -92,7 +92,6 @@ TextToPronounce_zh::equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCo
sal_Int32 realCount;
int i; // loop variable
const sal_Unicode * s1, * s2;
- const sal_Unicode *pron1, *pron2;
if (nCount1 + pos1 > str1.getLength())
nCount1 = str1.getLength() - pos1;
@@ -105,8 +104,8 @@ TextToPronounce_zh::equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCo
s1 = str1.getStr() + pos1;
s2 = str2.getStr() + pos2;
for (i = 0; i < realCount; i++) {
- pron1=getPronounce(*s1++);
- pron2=getPronounce(*s2++);
+ const sal_Unicode *pron1 = getPronounce(*s1++);
+ const sal_Unicode *pron2 = getPronounce(*s2++);
if (pron1 != pron2) {
nMatch1 = nMatch2 = i;
return sal_False;
diff --git a/i18nutil/source/utility/oneToOneMapping.cxx b/i18nutil/source/utility/oneToOneMapping.cxx
index 39c74de..2ced0f8 100644
--- a/i18nutil/source/utility/oneToOneMapping.cxx
+++ b/i18nutil/source/utility/oneToOneMapping.cxx
@@ -38,10 +38,9 @@ sal_Unicode oneToOneMapping::find(const sal_Unicode nKey) const
// binary search
int bottom = 0;
int top = mnSize - 1;
- int current;
for (;;) {
- current = (top + bottom) / 2;
+ const int current = (top + bottom) / 2;
if( nKey < mpTable[current].first )
top = current - 1;
else if( nKey > mpTable[current].first )
@@ -78,15 +77,15 @@ void oneToOneMappingWithFlag::makeIndex()
{
if( !mbHasIndex && mpTableWF )
{
- int i, j, high, low, current = -1;
+ int i, j, current = -1;
for( i = 0; i < 256; i++ )
mpIndex[i] = NULL;
for( size_t k = 0; k < mnSize; k++ )
{
- high = (mpTableWF[k].first >> 8) & 0xFF;
- low = (mpTableWF[k].first) & 0xFF;
+ const int high = (mpTableWF[k].first >> 8) & 0xFF;
+ const int low = (mpTableWF[k].first) & 0xFF;
if( high != current )
{
current = high;
@@ -124,10 +123,9 @@ sal_Unicode oneToOneMappingWithFlag::find( const sal_Unicode nKey ) const
// binary search
int bottom = 0;
int top = mnSize - 1;
- int current;
for (;;) {
- current = (top + bottom) / 2;
+ const int current = (top + bottom) / 2;
if( nKey < mpTableWF[current].first )
top = current - 1;
else if( nKey > mpTableWF[current].first )
diff --git a/i18nutil/source/utility/widthfolding.cxx b/i18nutil/source/utility/widthfolding.cxx
index 2d3fcb1..a471523 100644
--- a/i18nutil/source/utility/widthfolding.cxx
+++ b/i18nutil/source/utility/widthfolding.cxx
@@ -222,12 +222,12 @@ oneToOneMapping& widthfolding::getfull2halfTableForASC()
//
// See the following page for detail:
// http://wiki.openoffice.org/wiki/Calc/Features/JIS_and_ASC_functions
- int i, j, high, low;
+ int i, j;
int n = sizeof(full2halfASCException) / sizeof(UnicodePairWithFlag);
for( i = 0; i < n; i++ )
{
- high = (full2halfASCException[i].first >> 8) & 0xFF;
- low = (full2halfASCException[i].first) & 0xFF;
+ const int high = (full2halfASCException[i].first >> 8) & 0xFF;
+ const int low = (full2halfASCException[i].first) & 0xFF;
if( !table.mpIndex[high] )
{
@@ -256,12 +256,12 @@ oneToOneMapping& widthfolding::gethalf2fullTableForJIS()
//
// See the following page for detail:
// http://wiki.openoffice.org/wiki/Calc/Features/JIS_and_ASC_functions
- int i, j, high, low;
+ int i, j;
int n = sizeof(half2fullJISException) / sizeof(UnicodePairWithFlag);
for( i = 0; i < n; i++ )
{
- high = (half2fullJISException[i].first >> 8) & 0xFF;
- low = (half2fullJISException[i].first) & 0xFF;
+ const int high = (half2fullJISException[i].first >> 8) & 0xFF;
+ const int low = (half2fullJISException[i].first) & 0xFF;
if( !table.mpIndex[high] )
{
More information about the Libreoffice-commits
mailing list