diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-01-02 10:55:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-01-05 09:18:19 +0000 |
commit | bacfd2dc4cea1a5d87658ed8592116acd931e000 (patch) | |
tree | d22172a33fdd13a440b6882a28c23ea2d639bbad /svl | |
parent | 6281eb0e0792da0194c07da18296e94dd944b8e5 (diff) |
add a comphelper::string::getTokenCount
suitable for conversion from [Byte]String::GetTokenCount
converted low-hanging variants to rtl::O[UString]::getToken loops
added unit test
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/misc/folderrestriction.cxx | 45 | ||||
-rw-r--r-- | svl/source/misc/restrictedpaths.cxx | 43 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 4 |
3 files changed, 45 insertions, 47 deletions
diff --git a/svl/source/misc/folderrestriction.cxx b/svl/source/misc/folderrestriction.cxx index e423be90a812..c03999ad4a1b 100644 --- a/svl/source/misc/folderrestriction.cxx +++ b/svl/source/misc/folderrestriction.cxx @@ -35,41 +35,42 @@ //----------------------------------------------------------------------------- static void convertStringListToUrls ( - const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash ) + const rtl::OUString& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash ) { - const sal_Unicode s_cSeparator = + const sal_Unicode cSeparator = #if defined(WNT) ';' #else ':' #endif ; - xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator ); - _rTokens.resize( 0 ); _rTokens.reserve( nTokens ); - for ( xub_StrLen i=0; i<nTokens; ++i ) + + sal_Int32 nIndex = 0; + do { // the current token in the list - String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator ); - if ( !sCurrentToken.Len() ) - continue; + rtl::OUString sCurrentToken = _rColonSeparatedList.getToken( 0, cSeparator, nIndex ); + if (!sCurrentToken.isEmpty()) + { + INetURLObject aCurrentURL; - INetURLObject aCurrentURL; + String sURL; + if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) + aCurrentURL = INetURLObject( sURL ); + else + { + // smart URL parsing, assuming FILE protocol + aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); + } - String sURL; - if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) - aCurrentURL = INetURLObject( sURL ); - else - { - // smart URL parsing, assuming FILE protocol - aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); + if ( _bFinalSlash ) + aCurrentURL.setFinalSlash( ); + else + aCurrentURL.removeFinalSlash( ); + _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); } - - if ( _bFinalSlash ) - aCurrentURL.setFinalSlash( ); - else - aCurrentURL.removeFinalSlash( ); - _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); } + while ( nIndex >= 0 ); } /** retrieves the value of an environment variable diff --git a/svl/source/misc/restrictedpaths.cxx b/svl/source/misc/restrictedpaths.cxx index 41f9067965aa..d743247e94fe 100644 --- a/svl/source/misc/restrictedpaths.cxx +++ b/svl/source/misc/restrictedpaths.cxx @@ -51,41 +51,38 @@ namespace svt } //----------------------------------------------------------------- - void lcl_convertStringListToUrls( const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash ) + void lcl_convertStringListToUrls( const rtl::OUString& _rColonSeparatedList, ::std::vector< String >& _rTokens ) { - const sal_Unicode s_cSeparator = + const sal_Unicode cSeparator = #if defined(WNT) ';' #else ':' #endif ; - xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator ); - _rTokens.resize( 0 ); _rTokens.reserve( nTokens ); - for ( xub_StrLen i=0; i<nTokens; ++i ) + sal_Int32 nIndex = 0; + do { // the current token in the list - String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator ); - if ( !sCurrentToken.Len() ) - continue; - - INetURLObject aCurrentURL; - - String sURL; - if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) - aCurrentURL = INetURLObject( sURL ); - else + rtl::OUString sCurrentToken = _rColonSeparatedList.getToken( 0, cSeparator, nIndex ); + if ( !sCurrentToken.isEmpty() ) { - // smart URL parsing, assuming FILE protocol - aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); - } + INetURLObject aCurrentURL; + + String sURL; + if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) + aCurrentURL = INetURLObject( sURL ); + else + { + // smart URL parsing, assuming FILE protocol + aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); + } - if ( _bFinalSlash ) aCurrentURL.setFinalSlash( ); - else - aCurrentURL.removeFinalSlash( ); - _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); + _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); + } } + while ( nIndex >= 0 ); } } @@ -175,7 +172,7 @@ namespace svt // append a final slash. This ensures that when we later on check // for unrestricted paths, we don't allow paths like "/home/user35" just because // "/home/user3" is allowed - with the final slash, we make it "/home/user3/". - lcl_convertStringListToUrls( sRestrictedPathList, m_aUnrestrictedURLs, true ); + lcl_convertStringListToUrls( sRestrictedPathList, m_aUnrestrictedURLs ); } RestrictedPaths::~RestrictedPaths() {} diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 9252df0c27bd..8457f5b58c27 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1988,7 +1988,7 @@ void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, String& rOutStr rtl_math_StringFormat_F, nPrecision /*2*/, GetFormatter().GetNumDecimalSep().GetChar(0), true ); if (rOutString.GetChar(0) == '-' && - rOutString.GetTokenCount('0') == rOutString.Len()) + comphelper::string::getTokenCount(rOutString, '0') == rOutString.Len()) rOutString.EraseLeadingChars('-'); // nicht -0 ImpTransliterate( rOutString, NumFor[0].GetNatNum() ); @@ -3856,7 +3856,7 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber, sStr.Erase( nPoint, 1 ); // . herausnehmen } if (bSign && - (sStr.Len() == 0 || sStr.GetTokenCount('0') == sStr.Len()+1)) // nur 00000 + (sStr.Len() == 0 || comphelper::string::getTokenCount(sStr, '0') == sStr.Len()+1)) // nur 00000 bSign = false; // nicht -0.00 } // End of != FLAG_STANDARD_IN_FORMAT |