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/source/core/tool/stringutil.cxx | |
parent | 95ef04b5364845f41d9484905e70ba09a018950d (diff) |
move UniString::GetQuotedToken to sc, you can keep it
Change-Id: I6bc724186d9d701316e3e945d877bfaa88ac120d
Diffstat (limited to 'sc/source/core/tool/stringutil.cxx')
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 127 |
1 files changed, 127 insertions, 0 deletions
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: */ |