summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-05-14 20:54:43 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-05-15 10:21:21 +0100
commit6d1ee0f6fb40cbdac48abde99d4d41b50c4f0fcf (patch)
tree1ea2d4584bd799a0256e7da6e9f06386445a0a81 /i18npool
parente4d428459c0108f4758cca725e9f127b1d20fafc (diff)
coverity#1209074 Same on both sides
Change-Id: I2c02ca45ed12ed571a175fb82bc2478eeb02f31f
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/search/levdis.cxx41
-rw-r--r--i18npool/source/search/levdis.hxx33
2 files changed, 39 insertions, 35 deletions
diff --git a/i18npool/source/search/levdis.cxx b/i18npool/source/search/levdis.cxx
index 12ba7a1a100d..9af44307a99b 100644
--- a/i18npool/source/search/levdis.cxx
+++ b/i18npool/source/search/levdis.cxx
@@ -70,35 +70,6 @@
#define LEVDISBIG (nLimit + 1) // Return value if distance > nLimit
#define LEVDISDOUBLEBUF 2048 // dadrueber wird nicht mehr gedoppelt
-// Balance, aus Geschwindigkeitsgruenden ist dieses keine Funktion
-// c == cpPattern[jj] == cString[ii]
-// erst wird bis Fundstelle gesucht, wenn dort die Balance gleich ist, wird
-// auch nach der Fundstelle verglichen
-#define LEVDISBALANCE(jj,ii) \
-{ \
- if ( jj != ii ) \
- { \
- sal_Int32 k; \
- if ( jj > 0 ) \
- for ( k=0; k < jj; k++ ) \
- if ( cpPattern[k] == c ) \
- nBalance++; \
- if ( ii > 0 ) \
- for ( k=0; k < ii; k++ ) \
- if ( cString[k] == c ) \
- nBalance--; \
- if ( !nBalance ) \
- { \
- for ( k=jj+1; k < nPatternLen; k++ ) \
- if ( cpPattern[k] == c ) \
- nBalance++; \
- for ( k=ii+1; k < nStringLen; k++ ) \
- if ( cString[k] == c ) \
- nBalance--; \
- } \
- } \
-}
-
static sal_Int32 Impl_WLD_StringLen( const sal_Unicode* pStr )
{
const sal_Unicode* pTempStr = pStr;
@@ -178,8 +149,8 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
}
else if ( nReplacePos > 0 && !nP )
{
- int nBalance = 0; // gleiche Anzahl c
- LEVDISBALANCE( 0, i-1 );
+ // gleiche Anzahl c
+ int nBalance = levdisbalance( 0, i-1, c, cString, nStringLen );
if ( !nBalance )
{ // einer wurde ersetzt, der ein Insert war
nRepS--;
@@ -230,8 +201,8 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
nPij = 0; // p(i,j)
if ( nReplacePos < 0 )
{
- int nBalance = 0; // same quantity c
- LEVDISBALANCE( j, i-1 );
+ // same quantity c
+ int nBalance = levdisbalance( j, i-1, c, cString, nStringLen );
if ( !nBalance )
nReplacePos = 0; // keine Ersetzung mehr
}
@@ -259,8 +230,8 @@ int WLevDistance::WLD( const sal_Unicode* cString, sal_Int32 nStringLen )
// Replace keins. Buchstabendreher werden hier erfasst
// und der ReplaceS zurueckgenommen, wodurch das doppelte
// Limit zum Tragen kommt.
- int nBalance = 0; // same quantity c
- LEVDISBALANCE( j, i-1 );
+ // same quantity c
+ int nBalance = levdisbalance( j, i-1, c, cString, nStringLen );
if ( !nBalance )
{ // einer wurde ersetzt, der ein Insert war
nRepS--;
diff --git a/i18npool/source/search/levdis.hxx b/i18npool/source/search/levdis.hxx
index f27e2fc7038a..a9f7407d0bde 100644
--- a/i18npool/source/search/levdis.hxx
+++ b/i18npool/source/search/levdis.hxx
@@ -165,6 +165,39 @@ public:
// SetSplit( TRUE ) macht nur mit Werten nach CalcLPQR() Sinn!
inline bool IsNormal( sal_Int32 nPos ) const { return( !bpPatIsWild[nPos] ); }
+
+ // Balance, aus Geschwindigkeitsgruenden ist dieses keine Funktion
+ // c == cpPattern[jj] == cString[ii]
+ // erst wird bis Fundstelle gesucht, wenn dort die Balance gleich ist, wird
+ // auch nach der Fundstelle verglichen
+ int levdisbalance(sal_Int32 jj, sal_Int32 ii, sal_Unicode c, const sal_Unicode* cString, sal_Int32 nStringLen)
+ {
+ int nBalance = 0;
+
+ if ( jj != ii )
+ {
+ sal_Int32 k;
+ if ( jj > 0 )
+ for ( k=0; k < jj; k++ )
+ if ( cpPattern[k] == c )
+ nBalance++;
+ if ( ii > 0 )
+ for ( k=0; k < ii; k++ )
+ if ( cString[k] == c )
+ nBalance--;
+ if ( !nBalance )
+ {
+ for ( k=jj+1; k < nPatternLen; k++ )
+ if ( cpPattern[k] == c )
+ nBalance++;
+ for ( k=ii+1; k < nStringLen; k++ )
+ if ( cString[k] == c )
+ nBalance--;
+ }
+ }
+
+ return nBalance;
+ }
};
inline int WLevDistance::SetLimit( int nNewLimit )