harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r999724 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
Date Wed, 22 Sep 2010 01:57:57 GMT
Author: tellison
Date: Wed Sep 22 01:57:57 2010
New Revision: 999724

URL: http://svn.apache.org/viewvc?rev=999724&view=rev
Log:
Apply patch for HARMONY-6635 (FloatingPointParser uses toLowerCase unnecessarily)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java?rev=999724&r1=999723&r2=999724&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
Wed Sep 22 01:57:57 2010
@@ -280,6 +280,28 @@ public final class FloatingPointParser {
 		throw new NumberFormatException();
 	}
 
+	/*
+	 * Answers true if the string should be parsed as a hex encoding.
+	 * Assumes the string is trimmed.
+	 */
+    private static boolean parseAsHex(String s) {
+        int length = s.length();
+        if (length < 2) {
+            return false;
+        }
+        char first = s.charAt(0);
+        char second = s.charAt(1);
+        if (first == '+' || first == '-') {
+            // Move along
+            if (length < 3) {
+                return false;
+            }
+            first = second;
+            second = s.charAt(2);
+        }
+        return (first == '0') && (second == 'x' || second == 'X');
+    }
+
 	/**
 	 * Returns the closest double value to the real number in the string.
 	 * 
@@ -305,7 +327,7 @@ public final class FloatingPointParser {
 		}
         
         // See if it could be a hexadecimal representation
-        if (s.toLowerCase().indexOf("0x") != -1) { //$NON-NLS-1$
+        if (parseAsHex(s)) {
             return HexStringParser.parseDouble(s);
         }
         
@@ -354,7 +376,7 @@ public final class FloatingPointParser {
 		}
         
         // See if it could be a hexadecimal representation
-        if (s.toLowerCase().indexOf("0x") != -1) { //$NON-NLS-1$
+        if (parseAsHex(s)) {
             return HexStringParser.parseFloat(s);
         }
         



Mime
View raw message