diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-04 10:33:53 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-08-07 16:14:45 +0100 |
commit | db95e0b75903a34a1b88a3701334e154f32eeceb (patch) | |
tree | ed9a2370175d5dc85b2908b35e430d9051e8dee3 /sc | |
parent | 95ef04b5364845f41d9484905e70ba09a018950d (diff) |
move UniString::GetQuotedToken to sc, you can keep it
Change-Id: I6bc724186d9d701316e3e945d877bfaa88ac120d
Diffstat (limited to 'sc')
-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 |
4 files changed, 138 insertions, 4 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" { |