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 /cpputools/source | |
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 'cpputools/source')
-rw-r--r-- | cpputools/source/unoexe/unoexe.cxx | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/cpputools/source/unoexe/unoexe.cxx b/cpputools/source/unoexe/unoexe.cxx index fe1d9766941a..971ce344b08a 100644 --- a/cpputools/source/unoexe/unoexe.cxx +++ b/cpputools/source/unoexe/unoexe.cxx @@ -89,7 +89,7 @@ static sal_Bool readOption( OUString * pValue, const sal_Char * pOpt, throw (RuntimeException) { const OUString dash("-"); - if(aArg.indexOf(dash) != 0) + if(!aArg.startsWith(dash)) return sal_False; OUString aOpt = OUString::createFromAscii( pOpt ); @@ -145,7 +145,7 @@ static sal_Bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt, const OUString dashdash("--"); OUString aOpt = OUString::createFromAscii(pOpt); - if(aArg.indexOf(dashdash) == 0 && aOpt.equals(aArg.copy(2))) + if(aArg.startsWith(dashdash) && aOpt.equals(aArg.copy(2))) { ++(*pnIndex); *pbOpt = sal_True; |