summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-10-25 16:43:20 +0200
committerNoel Grandin <noel@peralex.com>2013-10-31 08:34:21 +0200
commite2451bd729d0f1d795a5b689deba65bc4e9d92c6 (patch)
tree4f2356107b0e58db7afda0fc324b9eac49ff68c0 /ucb
parent460b52838fdad0352188bdd877b69cbb5f17ca63 (diff)
Convert indexOf->startsWith and lastIndexOf->endsWith
This is both an optimisation and a cleanup. This converts code like aStr.indexOf("XX") == 0 to aStr.startsWith("XX") and converts code like aStr.lastIndexOf("XXX") == aStr.getLength() - 3 to aStr.endsWith("XXX") Note that in general aStr.lastIndexOf("X") == aStr.getLength() - 1 converts to aStr.isEmpty() || aStr.endsWith("X") so I used the surrounding context to determine if aStr could be empty when modifying the code. Change-Id: I22cb8ca7c2a4d0288b001f72adb27fd63af87669
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/ftp/ftpurl.cxx23
-rw-r--r--ucb/source/ucp/hierarchy/hierarchydatasource.cxx11
-rw-r--r--ucb/source/ucp/tdoc/tdoc_uri.hxx2
-rw-r--r--ucb/source/ucp/webdav-neon/NeonSession.cxx7
-rw-r--r--ucb/source/ucp/webdav/SerfSession.cxx7
5 files changed, 21 insertions, 29 deletions
diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index ba0e29840dca..60b6dcae0753 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -531,11 +531,9 @@ OUString FTPURL::net_title() const
while(true) {
OUString url(ident(false,true));
- if(try_more &&
- 1+url.lastIndexOf(sal_Unicode('/')) != url.getLength())
- url += OUString("/"); // add end-slash
- else if(!try_more &&
- 1+url.lastIndexOf(sal_Unicode('/')) == url.getLength())
+ if(try_more && !url.endsWith("/"))
+ url += "/"; // add end-slash
+ else if(!try_more && url.endsWith("/"))
url = url.copy(0,url.getLength()-1); // remove end-slash
SET_URL(url);
@@ -550,8 +548,7 @@ OUString FTPURL::net_title() const
// analyze the output:
// Format of current working directory:
// 257 "/bla/bla" is current directory
- sal_Int32 index1 = aNetTitle.lastIndexOf(
- OUString("257"));
+ sal_Int32 index1 = aNetTitle.lastIndexOf("257");
index1 = 1+aNetTitle.indexOf(sal_Unicode('"'),index1);
sal_Int32 index2 = aNetTitle.indexOf(sal_Unicode('"'),index1);
aNetTitle = aNetTitle.copy(index1,index2-index1);
@@ -712,8 +709,8 @@ void FTPURL::mkdir(bool ReplaceExisting) const
curl_easy_setopt(curl,CURLOPT_POSTQUOTE,slist);
OUString url(parent(true));
- if(1+url.lastIndexOf(sal_Unicode('/')) != url.getLength())
- url += OUString("/");
+ if(!url.endsWith("/"))
+ url += "/";
SET_URL(url);
CURLcode err = curl_easy_perform(curl);
@@ -752,8 +749,8 @@ OUString FTPURL::ren(const OUString& NewTitle)
curl_easy_setopt(curl,CURLOPT_QUOTE,0);
OUString url(parent(true));
- if(1+url.lastIndexOf(sal_Unicode('/')) != url.getLength())
- url += OUString("/");
+ if(!url.endsWith("/"))
+ url += "/";
SET_URL(url);
CURLcode err = curl_easy_perform(curl);
@@ -802,8 +799,8 @@ void FTPURL::del() const
curl_easy_setopt(curl,CURLOPT_QUOTE,0);
OUString url(parent(true));
- if(1+url.lastIndexOf(sal_Unicode('/')) != url.getLength())
- url += OUString("/");
+ if(!url.endsWith("/"))
+ url += "/";
SET_URL(url);
CURLcode err = curl_easy_perform(curl);
diff --git a/ucb/source/ucp/hierarchy/hierarchydatasource.cxx b/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
index 2f10717cc9ce..96b747140109 100644
--- a/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
+++ b/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
@@ -543,28 +543,25 @@ bool HierarchyDataSource::createConfigPath(
{
if ( !rInPath.isEmpty() )
{
- if ( rInPath.indexOf( '/' ) == 0 )
+ if ( rInPath.startsWith( "/" ) )
{
OSL_FAIL( "HierarchyDataSource::createConfigPath - "
"Leading slash in node path!" );
return false;
}
- if ( rInPath.lastIndexOf( '/' ) == rInPath.getLength() - 1 )
+ if ( rInPath.endsWith( "/" ) )
{
OSL_FAIL( "HierarchyDataSource::createConfigPath - "
"Trailing slash in node path!" );
return false;
}
- OUString aOutPath(
- CONFIG_DATA_ROOT_KEY "/" );
- aOutPath += rInPath;
- rOutPath = aOutPath;
+ rOutPath = CONFIG_DATA_ROOT_KEY "/" + rInPath;
}
else
{
- rOutPath = OUString( CONFIG_DATA_ROOT_KEY );
+ rOutPath = CONFIG_DATA_ROOT_KEY;
}
return true;
diff --git a/ucb/source/ucp/tdoc/tdoc_uri.hxx b/ucb/source/ucp/tdoc/tdoc_uri.hxx
index 4da9166e17dc..a137b6881ec9 100644
--- a/ucb/source/ucp/tdoc/tdoc_uri.hxx
+++ b/ucb/source/ucp/tdoc/tdoc_uri.hxx
@@ -115,7 +115,7 @@ inline sal_Bool Uri::isDocument() const
inline sal_Bool Uri::isFolder() const
{
init();
- return ( m_aPath.lastIndexOf( '/' ) == m_aPath.getLength() - 1 );
+ return m_aPath.isEmpty() || m_aPath.endsWith( "/" );
}
} // namespace tdoc_ucp
diff --git a/ucb/source/ucp/webdav-neon/NeonSession.cxx b/ucb/source/ucp/webdav-neon/NeonSession.cxx
index cee643a587dc..04e6de0ab990 100644
--- a/ucb/source/ucp/webdav-neon/NeonSession.cxx
+++ b/ucb/source/ucp/webdav-neon/NeonSession.cxx
@@ -347,9 +347,8 @@ namespace {
sal_Int32 nContStart = _rRawString.indexOf( sPartId );
if ( nContStart != -1 )
{
- nContStart = nContStart + sPartId.getLength();
- sal_Int32 nContEnd
- = _rRawString.indexOf( sal_Unicode( ',' ), nContStart );
+ nContStart += sPartId.getLength();
+ sal_Int32 nContEnd = _rRawString.indexOf( sal_Unicode( ',' ), nContStart );
sPart = _rRawString.copy( nContStart, nContEnd - nContStart );
}
return sPart;
@@ -2031,7 +2030,7 @@ NeonSession::isDomainMatch( OUString certHostName )
if (hostName.equalsIgnoreAsciiCase( certHostName ) )
return sal_True;
- if ( 0 == certHostName.indexOf( '*' ) &&
+ if ( certHostName.startsWith( "*" ) &&
hostName.getLength() >= certHostName.getLength() )
{
OUString cmpStr = certHostName.copy( 1 );
diff --git a/ucb/source/ucp/webdav/SerfSession.cxx b/ucb/source/ucp/webdav/SerfSession.cxx
index 92cd797c4838..3eb5e3cf51ec 100644
--- a/ucb/source/ucp/webdav/SerfSession.cxx
+++ b/ucb/source/ucp/webdav/SerfSession.cxx
@@ -351,9 +351,8 @@ namespace {
sal_Int32 nContStart = _rRawString.indexOf( sPartId );
if ( nContStart != -1 )
{
- nContStart = nContStart + sPartId.getLength();
- sal_Int32 nContEnd
- = _rRawString.indexOf( sal_Unicode( ',' ), nContStart );
+ nContStart += sPartId.getLength();
+ sal_Int32 nContEnd = _rRawString.indexOf( sal_Unicode( ',' ), nContStart );
sPart = _rRawString.copy( nContStart, nContEnd - nContStart );
}
return sPart;
@@ -1547,7 +1546,7 @@ SerfSession::isDomainMatch( OUString certHostName )
if (hostName.equalsIgnoreAsciiCase( certHostName ) )
return sal_True;
- if ( 0 == certHostName.indexOf( '*' ) &&
+ if ( certHostName.startsWith( '*' ) &&
hostName.getLength() >= certHostName.getLength() )
{
OUString cmpStr = certHostName.copy( 1 );