ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r513899 - /ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
Date Fri, 02 Mar 2007 19:24:57 GMT
Author: mbenson
Date: Fri Mar  2 11:24:56 2007
New Revision: 513899

URL: http://svn.apache.org/viewvc?view=rev&rev=513899
Log:
allow parsed human sizes to be prefixed by +/-

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java?view=diff&rev=513899&r1=513898&r2=513899
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java Fri Mar  2 11:24:56
2007
@@ -201,28 +201,43 @@
      * @since Ant 1.7
      */
     public static long parseHumanSizes(String humanSize) throws Exception {
+        long factor = 1L;
+        char s = humanSize.charAt(0);
+        switch (s) {
+            case '+':
+                humanSize = humanSize.substring(1);
+                break;
+            case '-':
+                factor = -1L;
+                humanSize = humanSize.substring(1);
+                break;
+            default:
+                break;
+        }
         //last character isn't a digit
-        if (!Character.isDigit(humanSize.charAt(humanSize.length() - 1))) {
-            char c = humanSize.charAt(humanSize.length() - 1);
-            long value = Long.valueOf(
-                humanSize.substring(
-                    0, humanSize.length() - 1)).longValue();
+        char c = humanSize.charAt(humanSize.length() - 1);
+        if (!Character.isDigit(c)) {
             switch (c) {
                 case 'K':
-                    return value * KILOBYTE;
+                    factor *= KILOBYTE;
+                    break;
                 case 'M':
-                    return value * MEGABYTE;
+                    factor *= MEGABYTE;
+                    break;
                 case 'G':
-                    return value * GIGABYTE;
+                    factor *= GIGABYTE;
+                    break;
                 case 'T':
-                    return value * TERABYTE;
+                    factor *= TERABYTE;
+                    break;
                 case 'P':
-                    return value * PETABYTE;
+                    factor *= PETABYTE;
+                    break;
                 default:
-                    return value;
+                    break;
             }
-        } else {
-            return Long.parseLong(humanSize);
+            humanSize = humanSize.substring(0, humanSize.length() - 1);
         }
+        return factor * Long.parseLong(humanSize);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message