summaryrefslogtreecommitdiffstats
path: root/svtools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-01-02 10:55:27 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-01-05 09:18:19 +0000
commitbacfd2dc4cea1a5d87658ed8592116acd931e000 (patch)
treed22172a33fdd13a440b6882a28c23ea2d639bbad /svtools
parentGetTokenCount on empty string is always 0 (diff)
downloadcore-bacfd2dc4cea1a5d87658ed8592116acd931e000.tar.gz
core-bacfd2dc4cea1a5d87658ed8592116acd931e000.zip
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 'svtools')
-rw-r--r--svtools/bmpmaker/bmpsum.cxx4
-rw-r--r--svtools/inc/svtools/filter.hxx4
-rw-r--r--svtools/source/config/printoptions.cxx11
-rw-r--r--svtools/source/contnr/fileview.cxx5
-rw-r--r--svtools/source/dialogs/addresstemplate.cxx23
-rw-r--r--svtools/source/filter/FilterConfigItem.cxx28
-rw-r--r--svtools/source/filter/filter.cxx15
-rw-r--r--svtools/source/filter/ixbm/xbmread.cxx6
-rw-r--r--svtools/source/filter/sgvtext.cxx9
-rw-r--r--svtools/source/misc/imap2.cxx6
-rw-r--r--svtools/source/misc/templatefoldercache.cxx10
-rw-r--r--svtools/source/svhtml/parhtml.cxx2
12 files changed, 68 insertions, 55 deletions
diff --git a/svtools/bmpmaker/bmpsum.cxx b/svtools/bmpmaker/bmpsum.cxx
index 72ddfde089d1..ead4930b4f09 100644
--- a/svtools/bmpmaker/bmpsum.cxx
+++ b/svtools/bmpmaker/bmpsum.cxx
@@ -428,10 +428,10 @@ void BmpSum::ProcessFileList( const String& rInFileList,
aFileName.SearchAndReplaceAll( '\\', '/' );
- sal_uInt16 nTokenCount = aFileName.GetTokenCount( '/' );
+ sal_Int32 nTokenCount = comphelper::string::getTokenCount(aFileName, '/');
DirEntry aNewDir( aBaseDir );
- for( sal_uInt16 n = 0; ( n < nTokenCount - 1 ); n++ )
+ for (sal_Int32 n = 0; ( n < nTokenCount - 1 ); ++n)
{
aNewDir += DirEntry( comphelper::string::getToken(aFileName, n, '/') );
aNewDir.MakeDir();
diff --git a/svtools/inc/svtools/filter.hxx b/svtools/inc/svtools/filter.hxx
index 7defa39b48a5..ce530b5d5ac6 100644
--- a/svtools/inc/svtools/filter.hxx
+++ b/svtools/inc/svtools/filter.hxx
@@ -269,7 +269,7 @@ private:
protected:
- String aFilterPath;
+ rtl::OUString aFilterPath;
FilterConfigCache* pConfig;
FilterErrorEx* pErrorEx;
sal_Bool bAbort;
@@ -288,7 +288,7 @@ public:
GraphicFilter( sal_Bool bUseConfig = sal_True );
~GraphicFilter();
- void SetFilterPath( const String& rFilterPath ) { aFilterPath = rFilterPath; };
+ void SetFilterPath( const rtl::OUString& rFilterPath ) { aFilterPath = rFilterPath; };
sal_uInt16 GetImportFormatCount();
sal_uInt16 GetImportFormatNumber( const String& rFormatName );
diff --git a/svtools/source/config/printoptions.cxx b/svtools/source/config/printoptions.cxx
index 6090c865724c..fc553edd5113 100644
--- a/svtools/source/config/printoptions.cxx
+++ b/svtools/source/config/printoptions.cxx
@@ -48,8 +48,8 @@
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <comphelper/configurationhelper.hxx>
-
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <unotools/loghelper.hxx>
@@ -178,10 +178,11 @@ SvtPrintOptions_Impl::SvtPrintOptions_Impl(const OUString& rConfigRoot)
if (m_xCfg.is())
{
- UniString sTmp = UniString(rConfigRoot);
- xub_StrLen nTokenCount = sTmp.GetTokenCount('/');
- sTmp = sTmp.GetToken(nTokenCount - 1, '/');
- m_xCfg->getByName(OUString(sTmp.GetBuffer())) >>= m_xNode;
+ using comphelper::string::getTokenCount;
+ using comphelper::string::getToken;
+ sal_Int32 nTokenCount = getTokenCount(rConfigRoot, '/');
+ rtl::OUString sTok = getToken(rConfigRoot, nTokenCount - 1, '/');
+ m_xCfg->getByName(sTok) >>= m_xNode;
}
}
catch (const css::uno::Exception& ex)
diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx
index f726a091e0de..7717d467059c 100644
--- a/svtools/source/contnr/fileview.cxx
+++ b/svtools/source/contnr/fileview.cxx
@@ -145,9 +145,8 @@ namespace
void FilterMatch::createWildCardFilterList(const String& _rFilterList,::std::vector< WildCard >& _rFilters)
{
if( _rFilterList.Len() )
- {// filter is given
- xub_StrLen nCount = _rFilterList.GetTokenCount();
- _rFilters.reserve( nCount );
+ {
+ // filter is given
xub_StrLen nIndex = 0;
OUString sToken;
do
diff --git a/svtools/source/dialogs/addresstemplate.cxx b/svtools/source/dialogs/addresstemplate.cxx
index 3e61787e046c..fa322a79979f 100644
--- a/svtools/source/dialogs/addresstemplate.cxx
+++ b/svtools/source/dialogs/addresstemplate.cxx
@@ -34,14 +34,15 @@
#include <svtools/helpid.hrc>
#include <svtools/svtdata.hxx>
#include <tools/debug.hxx>
+#include <comphelper/extract.hxx>
+#include <comphelper/interaction.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/stl_types.hxx>
+#include <comphelper/string.hxx>
#include <vcl/stdtext.hxx>
#include <vcl/waitobj.hxx>
#include <vcl/msgbox.hxx>
#include <toolkit/helper/vclunohelper.hxx>
-#include <comphelper/extract.hxx>
-#include <comphelper/interaction.hxx>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
@@ -180,10 +181,14 @@ public:
// first collect all known programmatic names
StringBag aKnownNames;
- String sLogicalFieldNames( SvtResId( STR_LOCAGICAL_FIELD_NAMES ) );
- sal_Int32 nTokenCount = sLogicalFieldNames.GetTokenCount(';');
- for (sal_Int32 i = 0; i<nTokenCount; ++i)
- aKnownNames.insert(sLogicalFieldNames.GetToken((sal_uInt16)i, ';'));
+ rtl::OUString sLogicalFieldNames(ResId::toString(SvtResId(STR_LOCAGICAL_FIELD_NAMES)));
+ sal_Int32 nIndex = 0;
+ do
+ {
+ rtl::OUString aToken = sLogicalFieldNames.getToken(0, ';', nIndex);
+ aKnownNames.insert(aToken);
+ }
+ while ( nIndex >= 0);
// loop throuzh the given names
const AliasProgrammaticPair* pFields = _rFields.getConstArray();
@@ -685,13 +690,13 @@ void AssignmentPersistentData::Commit()
implScrollFields(0, sal_False, sal_False);
// the logical names
- String sLogicalFieldNames(SvtResId(STR_LOCAGICAL_FIELD_NAMES));
- sal_Int32 nAdjustedTokenCount = sLogicalFieldNames.GetTokenCount(';') + (m_pImpl->bOddFieldNumber ? 1 : 0);
+ rtl::OUString sLogicalFieldNames(ResId::toString(SvtResId(STR_LOCAGICAL_FIELD_NAMES)));
+ sal_Int32 nAdjustedTokenCount = comphelper::string::getTokenCount(sLogicalFieldNames, ';') + (m_pImpl->bOddFieldNumber ? 1 : 0);
DBG_ASSERT(nAdjustedTokenCount == (sal_Int32)m_pImpl->aFieldLabels.size(),
"AddressBookSourceDialog::AddressBookSourceDialog: inconsistence between logical and UI field names!");
m_pImpl->aLogicalFieldNames.reserve(nAdjustedTokenCount);
for (sal_Int32 i = 0; i<nAdjustedTokenCount; ++i)
- m_pImpl->aLogicalFieldNames.push_back(sLogicalFieldNames.GetToken((sal_uInt16)i, ';'));
+ m_pImpl->aLogicalFieldNames.push_back(comphelper::string::getToken(sLogicalFieldNames, i, ';'));
PostUserEvent(LINK(this, AddressBookSourceDialog, OnDelayedInitialize));
// so the dialog will at least show up before we do the loading of the
diff --git a/svtools/source/filter/FilterConfigItem.cxx b/svtools/source/filter/FilterConfigItem.cxx
index 831947f649ed..d97bfc059e1e 100644
--- a/svtools/source/filter/FilterConfigItem.cxx
+++ b/svtools/source/filter/FilterConfigItem.cxx
@@ -31,6 +31,7 @@
#include <tools/debug.hxx>
#include <unotools/configmgr.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/util/XChangesBatch.hpp>
@@ -47,21 +48,24 @@ using namespace ::com::sun::star::awt ; // Size
using namespace ::com::sun::star::container ; //
using namespace ::com::sun::star::task ; // XStatusIndicator
-static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv, const String& rTree )
+static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv, const rtl::OUString& rTree )
{
- sal_Bool bAvailable = rTree.Len() != 0;
+ sal_Bool bAvailable = !rTree.isEmpty();
if ( bAvailable )
{
- xub_StrLen nTokenCount = rTree.GetTokenCount( (sal_Unicode)'/' );
- xub_StrLen i = 0;
+ using comphelper::string::getTokenCount;
+ using comphelper::string::getToken;
- if ( rTree.GetChar( 0 ) == (sal_Unicode)'/' )
- i++;
- if ( rTree.GetChar( rTree.Len() - 1 ) == (sal_Unicode)'/' )
- nTokenCount--;
+ sal_Int32 nTokenCount = getTokenCount(rTree, '/');
+ sal_Int32 i = 0;
+
+ if ( rTree[0] == '/' )
+ ++i;
+ if ( rTree[rTree.getLength() - 1] == '/' )
+ --nTokenCount;
Any aAny;
- aAny <<= (OUString)rTree.GetToken( i++, (sal_Unicode)'/' );
+ aAny <<= getToken(rTree, i++, '/');
// creation arguments: nodepath
PropertyValue aPathArgument;
@@ -78,7 +82,7 @@ static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv
OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ),
aArguments );
}
- catch ( ::com::sun::star::uno::Exception& )
+ catch (const ::com::sun::star::uno::Exception&)
{
bAvailable = sal_False;
}
@@ -93,7 +97,7 @@ static sal_Bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >& rXCfgProv
bAvailable = sal_False;
else
{
- String aNode( rTree.GetToken( i, (sal_Unicode)'/' ) );
+ rtl::OUString aNode( getToken(rTree, i, '/') );
if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) )
bAvailable = sal_False;
else
@@ -131,7 +135,7 @@ void FilterConfigItem::ImpInitTree( const String& rSubTree )
OUString sTree(
OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.")) +
rSubTree);
- if ( ImpIsTreeAvailable( xCfgProv, String( sTree ) ) )
+ if ( ImpIsTreeAvailable(xCfgProv, sTree) )
{
Any aAny;
// creation arguments: nodepath
diff --git a/svtools/source/filter/filter.cxx b/svtools/source/filter/filter.cxx
index 8047b7b74e00..89dd2dba4bc0 100644
--- a/svtools/source/filter/filter.cxx
+++ b/svtools/source/filter/filter.cxx
@@ -29,6 +29,7 @@
#include <osl/mutex.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <ucbhelper/content.hxx>
#include <cppuhelper/implbase1.hxx>
#include <tools/urlobj.hxx>
@@ -66,7 +67,6 @@
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/localfilehelper.hxx>
-#include <comphelper/processfactory.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/instance.hxx>
#include <vector>
@@ -87,6 +87,9 @@
using namespace ::rtl;
using namespace ::com::sun::star;
+using comphelper::string::getTokenCount;
+using comphelper::string::getToken;
+
typedef ::std::vector< GraphicFilter* > FilterList_impl;
static FilterList_impl* pFilterHdlList = NULL;
@@ -1634,11 +1637,11 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath,
{
ImpFilterLibCacheEntry* pFilter = NULL;
- // find first filter in filter pathes
- xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' );
+ // find first filter in filter paths
+ sal_Int32 i, nTokenCount = getTokenCount(aFilterPath, ';');
ImpFilterLibCache &rCache = Cache::get();
for( i = 0; ( i < nTokenCount ) && ( pFilter == NULL ); i++ )
- pFilter = rCache.GetFilter( aFilterPath.GetToken(i), aFilterName );
+ pFilter = rCache.GetFilter( getToken(aFilterPath, i, ';'), aFilterName );
if( !pFilter )
nStatus = GRFILTER_FILTERERROR;
else
@@ -2055,10 +2058,10 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& rGraphic, const String&
}
else
{
- xub_StrLen i, nTokenCount = aFilterPath.GetTokenCount( ';' );
+ sal_Int32 i, nTokenCount = getTokenCount(aFilterPath, ';');
for ( i = 0; i < nTokenCount; i++ )
{
- String aPhysicalName( ImpCreateFullFilterPath( aFilterPath.GetToken( i ), aFilterName ) );
+ String aPhysicalName( ImpCreateFullFilterPath( getToken(aFilterPath, i, ';'), aFilterName ) );
osl::Module aLibrary( aPhysicalName );
PFilterCall pFunc = (PFilterCall) aLibrary.getFunctionSymbol( UniString::CreateFromAscii( EXPORT_FUNCTION_NAME ) );
diff --git a/svtools/source/filter/ixbm/xbmread.cxx b/svtools/source/filter/ixbm/xbmread.cxx
index ff21e59f3728..559f12190375 100644
--- a/svtools/source/filter/ixbm/xbmread.cxx
+++ b/svtools/source/filter/ixbm/xbmread.cxx
@@ -227,13 +227,13 @@ sal_Bool XBMReader::ParseData( SvStream* pInStm, const ByteString& aLastLine, XB
if( aLine.Len() )
{
- const sal_uInt16 nCount = aLine.GetTokenCount( ',' );
+ const sal_Int32 nCount = comphelper::string::getTokenCount(aLine, ',');
- for( sal_uInt16 i = 0; ( i < nCount ) && ( nRow < nHeight ); i++ )
+ for( sal_Int32 i = 0; ( i < nCount ) && ( nRow < nHeight ); ++i )
{
const rtl::OString aToken(comphelper::string::getToken(aLine,i, ','));
const sal_Int32 nLen = aToken.getLength();
- sal_Bool bProcessed = sal_False;
+ sal_Bool bProcessed = sal_False;
nBit = nDigits = nValue = 0;
diff --git a/svtools/source/filter/sgvtext.cxx b/svtools/source/filter/sgvtext.cxx
index 171d141a4e88..8848c1f0bd48 100644
--- a/svtools/source/filter/sgvtext.cxx
+++ b/svtools/source/filter/sgvtext.cxx
@@ -1162,8 +1162,7 @@ SgfFontOne::SgfFontOne()
void SgfFontOne::ReadOne( const rtl::OString& rID, ByteString& Dsc )
{
- sal_uInt16 i,j,n;
- rtl::OString s;
+ sal_uInt16 i,j;
if ( Dsc.Len() < 4 || ( Dsc.GetChar( 0 ) != '(' ) )
return;
@@ -1185,10 +1184,10 @@ void SgfFontOne::ReadOne( const rtl::OString& rID, ByteString& Dsc )
Dsc.Erase(i,j);
IFID = (sal_uInt32)rID.toInt32();
- n=Dsc.GetTokenCount(' ');
- for (i=0;i<n;i++)
+ sal_Int32 nTokenCount = comphelper::string::getTokenCount(Dsc, ' ');
+ for (sal_Int32 nIdx = 0; nIdx < nTokenCount; ++nIdx)
{
- s = comphelper::string::getToken(Dsc, i,' ');
+ rtl::OString s = comphelper::string::getToken(Dsc, nIdx, ' ');
if (!s.isEmpty())
{
s = s.toAsciiUpperCase();
diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx
index ffcf82aa4ca7..41dff428ed16 100644
--- a/svtools/source/misc/imap2.cxx
+++ b/svtools/source/misc/imap2.cxx
@@ -303,7 +303,8 @@ void ImageMap::ImpReadCERNLine( const rtl::OString& rLine, const String& rBaseUR
}
else if ( ( aToken == "polygon" ) || ( aToken == "poly" ) )
{
- const sal_uInt16 nCount = aStr.GetTokenCount( '(' ) - 1;
+ const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr,
+ '(') - 1;
Polygon aPoly( nCount );
String aURL;
@@ -448,7 +449,8 @@ void ImageMap::ImpReadNCSALine( const rtl::OString& rLine, const String& rBaseUR
}
else if ( aToken == "poly" )
{
- const sal_uInt16 nCount = aStr.GetTokenCount( ',' ) - 1;
+ const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr,
+ ',') - 1;
const String aURL( ImpReadNCSAURL( &pStr, rBaseURL ) );
Polygon aPoly( nCount );
diff --git a/svtools/source/misc/templatefoldercache.cxx b/svtools/source/misc/templatefoldercache.cxx
index e2a340a8291b..ccf74ec2dafa 100644
--- a/svtools/source/misc/templatefoldercache.cxx
+++ b/svtools/source/misc/templatefoldercache.cxx
@@ -686,14 +686,13 @@ namespace svt
// the template directories from the config
const SvtPathOptions aPathOptions;
- String aDirs = aPathOptions.GetTemplatePath();
- sal_uInt16 nDirs = aDirs.GetTokenCount( ';' );
+ rtl::OUString aDirs = aPathOptions.GetTemplatePath();
- m_aCurrentState.reserve( nDirs );
// loop through all the root-level template folders
- for ( sal_uInt16 i=0; i<nDirs; ++i)
+ sal_Int32 nIndex = 0;
+ do
{
- String sTemplatePath( aDirs.GetToken( i, ';' ) );
+ String sTemplatePath( aDirs.getToken(0, ';', nIndex) );
sTemplatePath = aPathOptions.ExpandMacros( sTemplatePath );
// create a new entry
m_aCurrentState.push_back( new TemplateContent( INetURLObject( sTemplatePath ) ) );
@@ -703,6 +702,7 @@ namespace svt
if ( !implReadFolder( *aCurrentRoot ) )
return sal_False;
}
+ while ( nIndex >= 0 );
// normalize the array (which basically means "sort it")
normalize( m_aCurrentState );
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index d77e36de3ac8..c8e8ab253757 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -2178,7 +2178,7 @@ bool HTMLParser::ParseMetaOptionsImpl(
case HTML_META_CREATED:
case HTML_META_CHANGED:
if ( i_xDocProps.is() && aContent.Len() &&
- aContent.GetTokenCount() == 2 )
+ comphelper::string::getTokenCount(aContent, ';') == 2 )
{
Date aDate( (sal_uLong)aContent.GetToken(0).ToInt32() );
Time aTime( (sal_uLong)aContent.GetToken(1).ToInt32() );