From fb092e26659bb16693e782b04df96e1d914a5a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 26 Jul 2011 01:13:31 +0100 Subject: [PATCH] strip down unused old-style string methods --- tools/inc/tools/string.hxx | 12 --- tools/source/string/strimp.cxx | 165 ------------------------------- tools/source/string/tstring.cxx | 149 ++++++++++++++++++++++++++++ tools/source/string/tustring.cxx | 39 -------- 4 files changed, 149 insertions(+), 216 deletions(-) diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx index 9435d4fb9bd9..c405c41ac860 100644 --- a/tools/inc/tools/string.hxx +++ b/tools/inc/tools/string.hxx @@ -519,7 +519,6 @@ public: UniString& Insert( const UniString& rStr, xub_StrLen nIndex = STRING_LEN ); UniString& Insert( const UniString& rStr, xub_StrLen nPos, xub_StrLen nLen, xub_StrLen nIndex = STRING_LEN ); - UniString& Insert( const sal_Unicode* pCharStr, xub_StrLen nIndex = STRING_LEN ); UniString& Insert( sal_Unicode c, xub_StrLen nIndex = STRING_LEN ); UniString& InsertAscii( const sal_Char* pAsciiStr, xub_StrLen nIndex = STRING_LEN ); UniString& Replace( xub_StrLen nIndex, xub_StrLen nLen, const UniString& rStr ); @@ -546,18 +545,13 @@ public: StringCompare CompareTo( const UniString& rStr, xub_StrLen nLen = STRING_LEN ) const; - StringCompare CompareTo( const sal_Unicode* pCharStr, - xub_StrLen nLen = STRING_LEN ) const; StringCompare CompareToAscii( const sal_Char* pAsciiStr, xub_StrLen nLen = STRING_LEN ) const; StringCompare CompareIgnoreCaseToAscii( const UniString& rStr, xub_StrLen nLen = STRING_LEN ) const; - StringCompare CompareIgnoreCaseToAscii( const sal_Unicode* pCharStr, - xub_StrLen nLen = STRING_LEN ) const; StringCompare CompareIgnoreCaseToAscii( const sal_Char* pAsciiStr, xub_StrLen nLen = STRING_LEN ) const; sal_Bool Equals( const UniString& rStr ) const; - sal_Bool Equals( const sal_Unicode* pCharStr ) const; sal_Bool EqualsAscii( const sal_Char* pAsciiStr ) const; sal_Bool EqualsIgnoreCaseAscii( const UniString& rStr ) const; sal_Bool EqualsIgnoreCaseAscii( const sal_Unicode* pCharStr ) const; @@ -570,13 +564,10 @@ public: xub_StrLen nIndex, xub_StrLen nLen ) const; sal_Bool EqualsIgnoreCaseAscii( const UniString& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const; - sal_Bool EqualsIgnoreCaseAscii( const sal_Unicode* pCharStr, - xub_StrLen nIndex, xub_StrLen nLen ) const; sal_Bool EqualsIgnoreCaseAscii( const sal_Char* pAsciiStr, xub_StrLen nIndex, xub_StrLen nLen ) const; xub_StrLen Match( const UniString& rStr ) const; - xub_StrLen Match( const sal_Unicode* pCharStr ) const; xub_StrLen Search( sal_Unicode c, xub_StrLen nIndex = 0 ) const; xub_StrLen Search( const UniString& rStr, xub_StrLen nIndex = 0 ) const; @@ -589,13 +580,10 @@ public: xub_StrLen nIndex = 0 ); xub_StrLen SearchAndReplace( const UniString& rStr, const UniString& rRepStr, xub_StrLen nIndex = 0 ); - xub_StrLen SearchAndReplace( const sal_Unicode* pCharStr, const UniString& rRepStr, - xub_StrLen nIndex = 0 ); xub_StrLen SearchAndReplaceAscii( const sal_Char* pAsciiStr, const UniString& rRepStr, xub_StrLen nIndex = 0 ); void SearchAndReplaceAll( sal_Unicode c, sal_Unicode cRep ); void SearchAndReplaceAll( const UniString& rStr, const UniString& rRepStr ); - void SearchAndReplaceAll( const sal_Unicode* pCharStr, const UniString& rRepStr ); void SearchAndReplaceAllAscii( const sal_Char* pAsciiStr, const UniString& rRepStr ); xub_StrLen GetTokenCount( sal_Unicode cTok = ';' ) const; diff --git a/tools/source/string/strimp.cxx b/tools/source/string/strimp.cxx index 2f79410a9c19..f351aea90044 100644 --- a/tools/source/string/strimp.cxx +++ b/tools/source/string/strimp.cxx @@ -28,23 +28,6 @@ // no include "precompiled_tools.hxx" because this is included in other cxx files. -// ======================================================================= - -static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 ) -{ - sal_Int32 nRet; - while ( ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) && - *pStr2 ) - { - ++pStr1, - ++pStr2; - } - - return nRet; -} - -// ----------------------------------------------------------------------- - static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2, xub_StrLen nCount ) { @@ -108,39 +91,6 @@ static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2 // ----------------------------------------------------------------------- -static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2, - xub_StrLen nCount ) -{ - sal_Int32 nRet = 0; - STRCODE c1; - STRCODE c2; - do - { - if ( !nCount ) - break; - - // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln - c1 = *pStr1; - c2 = *pStr2; - if ( (c1 >= 65) && (c1 <= 90) ) - c1 += 32; - if ( (c2 >= 65) && (c2 <= 90) ) - c2 += 32; - nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2)); - if ( nRet != 0 ) - break; - - ++pStr1, - ++pStr2, - --nCount; - } - while ( c2 ); - - return nRet; -} - -// ----------------------------------------------------------------------- - static sal_Int32 ImplStringICompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2, sal_Int32 nCount ) { @@ -691,43 +641,6 @@ STRING& STRING::Insert( const STRING& rStr, xub_StrLen nIndex ) // ----------------------------------------------------------------------- -STRING& STRING::Insert( const STRCODE* pCharStr, xub_StrLen nIndex ) -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - DBG_ASSERT( pCharStr, "String::Insert() - pCharStr is NULL" ); - - // Stringlaenge ermitteln - sal_Int32 nCopyLen = ImplStringLen( pCharStr ); - - // Ueberlauf abfangen - nCopyLen = ImplGetCopyLen( mpData->mnLen, nCopyLen ); - - // Ist der einzufuegende String ein Leerstring - if ( !nCopyLen ) - return *this; - - // Index groesser als Laenge - if ( nIndex > mpData->mnLen ) - nIndex = static_cast< xub_StrLen >(mpData->mnLen); - - // Neue Laenge ermitteln und neuen String anlegen - STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen ); - - // String kopieren - memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); - memcpy( pNewData->maStr+nIndex, pCharStr, nCopyLen*sizeof( STRCODE ) ); - memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex, - (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); - - // Alte Daten loeschen und Neue zuweisen - STRING_RELEASE((STRING_TYPE *)mpData); - mpData = pNewData; - - return *this; -} - -// ----------------------------------------------------------------------- - STRING& STRING::Insert( STRCODE c, xub_StrLen nIndex ) { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); @@ -1191,43 +1104,6 @@ StringCompare STRING::CompareTo( const STRING& rStr, xub_StrLen nLen ) const // ----------------------------------------------------------------------- -StringCompare STRING::CompareTo( const STRCODE* pCharStr, xub_StrLen nLen ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - // String vergleichen - sal_Int32 nCompare = ImplStringCompare( mpData->maStr, pCharStr, nLen ); - - // Rueckgabewert anpassen - if ( nCompare == 0 ) - return COMPARE_EQUAL; - else if ( nCompare < 0 ) - return COMPARE_LESS; - else - return COMPARE_GREATER; -} - -// ----------------------------------------------------------------------- - -StringCompare STRING::CompareIgnoreCaseToAscii( const STRCODE* pCharStr, - xub_StrLen nLen ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - // String vergleichen - sal_Int32 nCompare = ImplStringICompare( mpData->maStr, pCharStr, nLen ); - - // Rueckgabewert anpassen - if ( nCompare == 0 ) - return COMPARE_EQUAL; - else if ( nCompare < 0 ) - return COMPARE_LESS; - else - return COMPARE_GREATER; -} - -// ----------------------------------------------------------------------- - sal_Bool STRING::Equals( const STRING& rStr ) const { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); @@ -1247,15 +1123,6 @@ sal_Bool STRING::Equals( const STRING& rStr ) const // ----------------------------------------------------------------------- -sal_Bool STRING::Equals( const STRCODE* pCharStr ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - return (ImplStringCompare( mpData->maStr, pCharStr ) == 0); -} - -// ----------------------------------------------------------------------- - sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr ) const { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); @@ -1497,21 +1364,6 @@ xub_StrLen STRING::SearchAndReplace( const STRING& rStr, const STRING& rRepStr, // ----------------------------------------------------------------------- -xub_StrLen STRING::SearchAndReplace( const STRCODE* pCharStr, const STRING& rRepStr, - xub_StrLen nIndex ) -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); - - xub_StrLen nSPos = Search( pCharStr, nIndex ); - if ( nSPos != STRING_NOTFOUND ) - Replace( nSPos, ImplStringLen( pCharStr ), rRepStr ); - - return nSPos; -} - -// ----------------------------------------------------------------------- - void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep ) { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); @@ -1533,23 +1385,6 @@ void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep ) // ----------------------------------------------------------------------- -void STRING::SearchAndReplaceAll( const STRCODE* pCharStr, const STRING& rRepStr ) -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); - - xub_StrLen nCharLen = ImplStringLen( pCharStr ); - xub_StrLen nSPos = Search( pCharStr, 0 ); - while ( nSPos != STRING_NOTFOUND ) - { - Replace( nSPos, nCharLen, rRepStr ); - nSPos = nSPos + rRepStr.Len(); - nSPos = Search( pCharStr, nSPos ); - } -} - -// ----------------------------------------------------------------------- - void STRING::SearchAndReplaceAll( const STRING& rStr, const STRING& rRepStr ) { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); diff --git a/tools/source/string/tstring.cxx b/tools/source/string/tstring.cxx index b89a51ba7cdc..e3675c855e08 100644 --- a/tools/source/string/tstring.cxx +++ b/tools/source/string/tstring.cxx @@ -227,4 +227,153 @@ sal_Bool ByteString::IsAlphaNumericAscii() const return sal_True; } +void STRING::SearchAndReplaceAll( const STRCODE* pCharStr, const STRING& rRepStr ) +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); + + xub_StrLen nCharLen = ImplStringLen( pCharStr ); + xub_StrLen nSPos = Search( pCharStr, 0 ); + while ( nSPos != STRING_NOTFOUND ) + { + Replace( nSPos, nCharLen, rRepStr ); + nSPos = nSPos + rRepStr.Len(); + nSPos = Search( pCharStr, nSPos ); + } +} + +xub_StrLen STRING::SearchAndReplace( const STRCODE* pCharStr, const STRING& rRepStr, + xub_StrLen nIndex ) +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); + + xub_StrLen nSPos = Search( pCharStr, nIndex ); + if ( nSPos != STRING_NOTFOUND ) + Replace( nSPos, ImplStringLen( pCharStr ), rRepStr ); + + return nSPos; +} + +static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2, + xub_StrLen nCount ) +{ + sal_Int32 nRet = 0; + STRCODE c1; + STRCODE c2; + do + { + if ( !nCount ) + break; + + // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln + c1 = *pStr1; + c2 = *pStr2; + if ( (c1 >= 65) && (c1 <= 90) ) + c1 += 32; + if ( (c2 >= 65) && (c2 <= 90) ) + c2 += 32; + nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2)); + if ( nRet != 0 ) + break; + + ++pStr1, + ++pStr2, + --nCount; + } + while ( c2 ); + + return nRet; +} + +StringCompare STRING::CompareIgnoreCaseToAscii( const STRCODE* pCharStr, + xub_StrLen nLen ) const +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + + // String vergleichen + sal_Int32 nCompare = ImplStringICompare( mpData->maStr, pCharStr, nLen ); + + // Rueckgabewert anpassen + if ( nCompare == 0 ) + return COMPARE_EQUAL; + else if ( nCompare < 0 ) + return COMPARE_LESS; + else + return COMPARE_GREATER; +} + +StringCompare STRING::CompareTo( const STRCODE* pCharStr, xub_StrLen nLen ) const +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + + // String vergleichen + sal_Int32 nCompare = ImplStringCompare( mpData->maStr, pCharStr, nLen ); + + // Rueckgabewert anpassen + if ( nCompare == 0 ) + return COMPARE_EQUAL; + else if ( nCompare < 0 ) + return COMPARE_LESS; + else + return COMPARE_GREATER; +} + +// ======================================================================= + +static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 ) +{ + sal_Int32 nRet; + while ( ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) && + *pStr2 ) + { + ++pStr1, + ++pStr2; + } + + return nRet; +} + +sal_Bool STRING::Equals( const STRCODE* pCharStr ) const +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + + return (ImplStringCompare( mpData->maStr, pCharStr ) == 0); +} + +STRING& STRING::Insert( const STRCODE* pCharStr, xub_StrLen nIndex ) +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + DBG_ASSERT( pCharStr, "String::Insert() - pCharStr is NULL" ); + + // Stringlaenge ermitteln + sal_Int32 nCopyLen = ImplStringLen( pCharStr ); + + // Ueberlauf abfangen + nCopyLen = ImplGetCopyLen( mpData->mnLen, nCopyLen ); + + // Ist der einzufuegende String ein Leerstring + if ( !nCopyLen ) + return *this; + + // Index groesser als Laenge + if ( nIndex > mpData->mnLen ) + nIndex = static_cast< xub_StrLen >(mpData->mnLen); + + // Neue Laenge ermitteln und neuen String anlegen + STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen ); + + // String kopieren + memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); + memcpy( pNewData->maStr+nIndex, pCharStr, nCopyLen*sizeof( STRCODE ) ); + memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex, + (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); + + // Alte Daten loeschen und Neue zuweisen + STRING_RELEASE((STRING_TYPE *)mpData); + mpData = pNewData; + + return *this; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/string/tustring.cxx b/tools/source/string/tustring.cxx index 9ef026f6cce8..c7ab3162f601 100644 --- a/tools/source/string/tustring.cxx +++ b/tools/source/string/tustring.cxx @@ -231,32 +231,6 @@ STRING& STRING::Reverse() // ----------------------------------------------------------------------- -xub_StrLen STRING::Match( const STRCODE* pCharStr ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - // Ist dieser String leer - if ( !mpData->mnLen ) - return STRING_MATCH; - - // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen - const STRCODE* pStr = mpData->maStr; - xub_StrLen i = 0; - while ( i < mpData->mnLen ) - { - // Stimmt das Zeichen nicht ueberein, dann abbrechen - if ( *pStr != *pCharStr ) - return i; - ++pStr, - ++pCharStr, - ++i; - } - - return STRING_MATCH; -} - -// ----------------------------------------------------------------------- - STRING& STRING::Insert( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen, xub_StrLen nIndex ) { @@ -460,19 +434,6 @@ sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr, xub_StrLen nIndex, x // ----------------------------------------------------------------------- -sal_Bool STRING::EqualsIgnoreCaseAscii( const STRCODE* pCharStr, xub_StrLen nIndex, xub_StrLen nLen ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - // Are there enough codes for comparing? - if ( nIndex > mpData->mnLen ) - return (*pCharStr == 0); - - return (ImplStringICompare( mpData->maStr+nIndex, pCharStr, nLen ) == 0); -} - -// ----------------------------------------------------------------------- - StringCompare STRING::CompareIgnoreCaseToAscii( const STRING& rStr, xub_StrLen nLen ) const {