ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Loïc Péron <loic.pe...@bigfoot.com>
Subject [PATCH] Basename.java has wrong behaviour against suffix removal
Date Thu, 27 Jun 2002 16:02:19 GMT

Hi,

I just saw Basename.java has wrong behaviour against suffix removal
which I corrected:

--- Basename.java	Thu Jun 27 11:04:55 2002
+++ Basename.java.patched	Thu Jun 27 11:05:59 2002
@@ -127,7 +127,7 @@
       } else {
         value = file.getName();
         if (suffix != null && value.endsWith(suffix)) {
-            int pos = value.indexOf('.');
+            int pos = value.lastIndexOf(suffix);
             value = value.substring(0, pos);
         }
         getProject().setNewProperty(property, value);

At first, as it is removing a _suffix_, it must use lastIndexOf()
instead of indexOf(): there would have been problems with file.tar.gz
for example.

Then, as the complete suffix is supplied, this suffix should be
removed instead of relying on a '.' suffix separator.

At last, a simple computation could be used to get the position:
             int pos = value.length() - suffix.length();
but this does not seem as versatile as lastIndexOf() in case anything
other than the bare supplied suffix is used to compute the position.

What do you think of it?
PS: I'm not subscribed to this list, please cc: me in case of a reply.

-- 
Loïc Péron

phone:(33) 683 880 177
mailto:loic.peron@bigfoot.com
Mime
View raw message