diff options
author | Noel Grandin <noel@peralex.com> | 2013-10-25 16:43:20 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-10-31 08:34:21 +0200 |
commit | e2451bd729d0f1d795a5b689deba65bc4e9d92c6 (patch) | |
tree | 4f2356107b0e58db7afda0fc324b9eac49ff68c0 /ucb/source/ucp/ftp/ftpurl.cxx | |
parent | 460b52838fdad0352188bdd877b69cbb5f17ca63 (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/source/ucp/ftp/ftpurl.cxx')
-rw-r--r-- | ucb/source/ucp/ftp/ftpurl.cxx | 23 |
1 files changed, 10 insertions, 13 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); |