diff options
-rw-r--r-- | sc/inc/stringutil.hxx | 5 | ||||
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 127 | ||||
-rw-r--r-- | sc/source/filter/excel/xicontent.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/dbgui/validate.cxx | 5 | ||||
-rw-r--r-- | tools/inc/tools/string.hxx | 13 | ||||
-rw-r--r-- | tools/source/string/tustring.cxx | 135 |
6 files changed, 138 insertions, 152 deletions
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index 954d4bc1b2bb..a178bebf7ca7 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -30,6 +30,7 @@ #define SC_STRINGUTIL_HXX #include "rtl/ustring.hxx" +#include "tools/string.hxx" #include "scdllapi.h" class SvNumberFormatter; @@ -95,6 +96,10 @@ public: */ static bool parseSimpleNumber( const ::rtl::OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal); + + static xub_StrLen SC_DLLPUBLIC GetQuotedTokenCount(const UniString &rIn, const UniString& rQuotedPairs, sal_Unicode cTok = ';' ); + static UniString SC_DLLPUBLIC GetQuotedToken(const UniString &rIn, xub_StrLen nToken, const UniString& rQuotedPairs, + sal_Unicode cTok, xub_StrLen& rIndex ); }; diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index 7866b99bd9cb..6465c8e282d5 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -192,4 +192,131 @@ bool ScStringUtil::parseSimpleNumber( return true; } +xub_StrLen ScStringUtil::GetQuotedTokenCount(const UniString &rIn, const UniString& rQuotedPairs, sal_Unicode cTok ) +{ + assert( !(rQuotedPairs.Len()%2) ); + assert( rQuotedPairs.Search(cTok) ); + + // Leerer String: TokenCount per Definition 0 + if ( !rIn.Len() ) + return 0; + + xub_StrLen nTokCount = 1; + sal_Int32 nLen = rIn.Len(); + xub_StrLen nQuotedLen = rQuotedPairs.Len(); + sal_Unicode cQuotedEndChar = 0; + const sal_Unicode* pQuotedStr = rQuotedPairs.GetBuffer(); + const sal_Unicode* pStr = rIn.GetBuffer(); + sal_Int32 nIndex = 0; + while ( nIndex < nLen ) + { + sal_Unicode c = *pStr; + if ( cQuotedEndChar ) + { + // Ende des Quotes erreicht ? + if ( c == cQuotedEndChar ) + cQuotedEndChar = 0; + } + else + { + // Ist das Zeichen ein Quote-Anfang-Zeichen ? + xub_StrLen nQuoteIndex = 0; + while ( nQuoteIndex < nQuotedLen ) + { + if ( pQuotedStr[nQuoteIndex] == c ) + { + cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; + break; + } + else + nQuoteIndex += 2; + } + + // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount + if ( c == cTok ) + ++nTokCount; + } + + ++pStr, + ++nIndex; + } + + return nTokCount; +} + +UniString ScStringUtil::GetQuotedToken(const UniString &rIn, xub_StrLen nToken, const UniString& rQuotedPairs, + sal_Unicode cTok, xub_StrLen& rIndex ) +{ + assert( !(rQuotedPairs.Len()%2) ); + assert( rQuotedPairs.Search(cTok) == STRING_NOTFOUND ); + + const sal_Unicode* pStr = rIn.GetBuffer(); + const sal_Unicode* pQuotedStr = rQuotedPairs.GetBuffer(); + sal_Unicode cQuotedEndChar = 0; + xub_StrLen nQuotedLen = rQuotedPairs.Len(); + xub_StrLen nLen = rIn.Len(); + xub_StrLen nTok = 0; + xub_StrLen nFirstChar = rIndex; + xub_StrLen i = nFirstChar; + + // Bestimme die Token-Position und Laenge + pStr += i; + while ( i < nLen ) + { + sal_Unicode c = *pStr; + if ( cQuotedEndChar ) + { + // Ende des Quotes erreicht ? + if ( c == cQuotedEndChar ) + cQuotedEndChar = 0; + } + else + { + // Ist das Zeichen ein Quote-Anfang-Zeichen ? + xub_StrLen nQuoteIndex = 0; + while ( nQuoteIndex < nQuotedLen ) + { + if ( pQuotedStr[nQuoteIndex] == c ) + { + cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; + break; + } + else + nQuoteIndex += 2; + } + + // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount + if ( c == cTok ) + { + ++nTok; + + if ( nTok == nToken ) + nFirstChar = i+1; + else + { + if ( nTok > nToken ) + break; + } + } + } + + ++pStr, + ++i; + } + + if ( nTok >= nToken ) + { + if ( i < nLen ) + rIndex = i+1; + else + rIndex = STRING_NOTFOUND; + return rIn.Copy( nFirstChar, i-nFirstChar ); + } + else + { + rIndex = STRING_NOTFOUND; + return UniString(); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index 424b91b2fc0c..8597d9fb9bac 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -45,6 +45,7 @@ #include <editeng/postitem.hxx> #include <editeng/colritem.hxx> #include <editeng/crsditem.hxx> +#include "stringutil.hxx" #include "document.hxx" #include "editutil.hxx" #include "cell.hxx" @@ -946,12 +947,12 @@ void XclImpWebQuery::ReadWqtables( XclImpStream& rStrm ) const sal_Unicode cSep = ';'; String aQuotedPairs( RTL_CONSTASCII_USTRINGPARAM( "\"\"" ) ); - xub_StrLen nTokenCnt = aTables.GetQuotedTokenCount( aQuotedPairs, ',' ); + xub_StrLen nTokenCnt = ScStringUtil::GetQuotedTokenCount( aTables, aQuotedPairs, ',' ); maTables.Erase(); xub_StrLen nStringIx = 0; for( xub_StrLen nToken = 0; nToken < nTokenCnt; ++nToken ) { - String aToken( aTables.GetQuotedToken( 0, aQuotedPairs, ',', nStringIx ) ); + String aToken( ScStringUtil::GetQuotedToken( aTables, 0, aQuotedPairs, ',', nStringIx ) ); sal_Int32 nTabNum = CharClass::isAsciiNumeric( aToken ) ? aToken.ToInt32() : 0; if( nTabNum > 0 ) ScGlobal::AddToken( maTables, ScfTools::GetNameFromHTMLIndex( static_cast< sal_uInt32 >( nTabNum ) ), cSep ); diff --git a/sc/source/ui/dbgui/validate.cxx b/sc/source/ui/dbgui/validate.cxx index 494672b5ac4c..b8db869126c6 100644 --- a/sc/source/ui/dbgui/validate.cxx +++ b/sc/source/ui/dbgui/validate.cxx @@ -45,6 +45,7 @@ #include "scresid.hxx" #include "sc.hrc" // -> Slot IDs +#include "stringutil.hxx" #include "validat.hxx" #include "validate.hrc" #include "validate.hxx" @@ -283,7 +284,7 @@ void lclGetFormulaFromStringList( String& rFmlaStr, const String& rStringList, s bool lclGetStringListFromFormula( String& rStringList, const String& rFmlaStr, sal_Unicode cFmlaSep ) { String aQuotes( RTL_CONSTASCII_USTRINGPARAM( "\"\"" ) ); - xub_StrLen nTokenCnt = rFmlaStr.GetQuotedTokenCount( aQuotes, cFmlaSep ); + xub_StrLen nTokenCnt = ScStringUtil::GetQuotedTokenCount(rFmlaStr, aQuotes, cFmlaSep ); rStringList.Erase(); bool bIsStringList = (nTokenCnt > 0); @@ -291,7 +292,7 @@ bool lclGetStringListFromFormula( String& rStringList, const String& rFmlaStr, s for( xub_StrLen nToken = 0, nStringIx = 0; bIsStringList && (nToken < nTokenCnt); ++nToken ) { - String aToken( rFmlaStr.GetQuotedToken( 0, aQuotes, cFmlaSep, nStringIx ) ); + String aToken( ScStringUtil::GetQuotedToken(rFmlaStr, 0, aQuotes, cFmlaSep, nStringIx ) ); aToken = comphelper::string::strip(aToken, ' '); if( aToken.Len() ) // ignore empty tokens, i.e. "a";;"b" { diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx index e070fb59afc4..d3528df8ac80 100644 --- a/tools/inc/tools/string.hxx +++ b/tools/inc/tools/string.hxx @@ -287,12 +287,6 @@ public: UniString GetToken( xub_StrLen nToken, sal_Unicode cTok, xub_StrLen& rIndex ) const; UniString GetToken( xub_StrLen nToken, sal_Unicode cTok = ';' ) const; - xub_StrLen GetQuotedTokenCount( const UniString& rQuotedPairs, sal_Unicode cTok = ';' ) const; - UniString GetQuotedToken( xub_StrLen nToken, const UniString& rQuotedPairs, - sal_Unicode cTok, xub_StrLen& rIndex ) const; - UniString GetQuotedToken( xub_StrLen nToken, const UniString& rQuotedPairs, - sal_Unicode cTok = ';' ) const; - const sal_Unicode* GetBuffer() const { return mpData->maStr; } sal_Unicode* GetBufferAccess(); void ReleaseBufferAccess( xub_StrLen nLen = STRING_LEN ); @@ -323,13 +317,6 @@ inline UniString UniString::GetToken( xub_StrLen nToken, sal_Unicode cTok ) cons return GetToken( nToken, cTok, nTempPos ); } -inline UniString UniString::GetQuotedToken( xub_StrLen nToken, const UniString& rQuotedPairs, - sal_Unicode cTok ) const -{ - xub_StrLen nTempPos = 0; - return GetQuotedToken( nToken, rQuotedPairs, cTok, nTempPos ); -} - template< typename charT, typename traits > std::basic_ostream<charT, traits> & operator <<( std::basic_ostream<charT, traits> & stream, UniString const & string) diff --git a/tools/source/string/tustring.cxx b/tools/source/string/tustring.cxx index 120bf002b873..e21b2d018eb3 100644 --- a/tools/source/string/tustring.cxx +++ b/tools/source/string/tustring.cxx @@ -188,141 +188,6 @@ STRING& STRING::Insert( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen, // ----------------------------------------------------------------------- -xub_StrLen STRING::GetQuotedTokenCount( const STRING& rQuotedPairs, STRCODE cTok ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING ); - DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedTokenCount() - QuotedString%2 != 0" ); - DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedTokenCount() - cTok in QuotedString" ); - - // Leerer String: TokenCount per Definition 0 - if ( !mpData->mnLen ) - return 0; - - xub_StrLen nTokCount = 1; - sal_Int32 nLen = mpData->mnLen; - xub_StrLen nQuotedLen = rQuotedPairs.Len(); - STRCODE cQuotedEndChar = 0; - const STRCODE* pQuotedStr = rQuotedPairs.mpData->maStr; - const STRCODE* pStr = mpData->maStr; - sal_Int32 nIndex = 0; - while ( nIndex < nLen ) - { - STRCODE c = *pStr; - if ( cQuotedEndChar ) - { - // Ende des Quotes erreicht ? - if ( c == cQuotedEndChar ) - cQuotedEndChar = 0; - } - else - { - // Ist das Zeichen ein Quote-Anfang-Zeichen ? - xub_StrLen nQuoteIndex = 0; - while ( nQuoteIndex < nQuotedLen ) - { - if ( pQuotedStr[nQuoteIndex] == c ) - { - cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; - break; - } - else - nQuoteIndex += 2; - } - - // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount - if ( c == cTok ) - ++nTokCount; - } - - ++pStr, - ++nIndex; - } - - return nTokCount; -} - -// ----------------------------------------------------------------------- - -STRING STRING::GetQuotedToken( xub_StrLen nToken, const STRING& rQuotedPairs, - STRCODE cTok, xub_StrLen& rIndex ) const -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING ); - DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedToken() - QuotedString%2 != 0" ); - DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedToken() - cTok in QuotedString" ); - - const STRCODE* pStr = mpData->maStr; - const STRCODE* pQuotedStr = rQuotedPairs.mpData->maStr; - STRCODE cQuotedEndChar = 0; - xub_StrLen nQuotedLen = rQuotedPairs.Len(); - xub_StrLen nLen = (xub_StrLen)mpData->mnLen; - xub_StrLen nTok = 0; - xub_StrLen nFirstChar = rIndex; - xub_StrLen i = nFirstChar; - - // Bestimme die Token-Position und Laenge - pStr += i; - while ( i < nLen ) - { - STRCODE c = *pStr; - if ( cQuotedEndChar ) - { - // Ende des Quotes erreicht ? - if ( c == cQuotedEndChar ) - cQuotedEndChar = 0; - } - else - { - // Ist das Zeichen ein Quote-Anfang-Zeichen ? - xub_StrLen nQuoteIndex = 0; - while ( nQuoteIndex < nQuotedLen ) - { - if ( pQuotedStr[nQuoteIndex] == c ) - { - cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; - break; - } - else - nQuoteIndex += 2; - } - - // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount - if ( c == cTok ) - { - ++nTok; - - if ( nTok == nToken ) - nFirstChar = i+1; - else - { - if ( nTok > nToken ) - break; - } - } - } - - ++pStr, - ++i; - } - - if ( nTok >= nToken ) - { - if ( i < nLen ) - rIndex = i+1; - else - rIndex = STRING_NOTFOUND; - return Copy( nFirstChar, i-nFirstChar ); - } - else - { - rIndex = STRING_NOTFOUND; - return STRING(); - } -} - -// ----------------------------------------------------------------------- - static sal_Int32 ImplStringICompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2, sal_Int32 nCount ) { |