commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1160660 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/math/NumberUtils.java site/changes/changes.xml test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Date Tue, 23 Aug 2011 12:32:52 GMT
Author: sebb
Date: Tue Aug 23 12:32:52 2011
New Revision: 1160660

URL: http://svn.apache.org/viewvc?rev=1160660&view=rev
Log:
LANG-746 NumberUtils does not handle upper-case hex: 0X and -0X

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
    commons/proper/lang/trunk/src/site/changes/changes.xml
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=1160660&r1=1160659&r2=1160660&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Tue Aug 23 12:32:52 2011
@@ -428,7 +428,7 @@ public class NumberUtils {
      * <code>BigInteger</code> and from <code>Float</code> to
      * <code>BigDecimal</code>.</p>
      *
-     * <p>If the string starts with <code>0x</code> or <code>-0x</code>,
it
+     * <p>If the string starts with <code>0x</code> or <code>-0x</code>
(lower or upper case), it
      * will be interpreted as a hexadecimal integer.  Values with leading
      * <code>0</code>'s will not be interpreted as octal.</p>
      *
@@ -438,7 +438,7 @@ public class NumberUtils {
      * or trailing spaces will generate NumberFormatExceptions.</p>
      *
      * @param str  String containing a number, may be null
-     * @return Number created from the string
+     * @return Number created from the string (or null if the input is null)
      * @throws NumberFormatException if the value cannot be converted
      */
     public static Number createNumber(String str) throws NumberFormatException {
@@ -455,7 +455,7 @@ public class NumberUtils {
             // a wrong value.
             return null;
         }
-        if (str.startsWith("0x") || str.startsWith("-0x")) {
+        if (str.startsWith("0x") || str.startsWith("-0x") || str.startsWith("0X") || str.startsWith("-0X"))
{
             return createInteger(str);
         }   
         char lastChar = str.charAt(str.length() - 1);

Modified: commons/proper/lang/trunk/src/site/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/site/changes/changes.xml?rev=1160660&r1=1160659&r2=1160660&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/site/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/site/changes/changes.xml Tue Aug 23 12:32:52 2011
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.0.2" date="unreleased" description="September release">  
+    <action type="fix" issue="LANG-746">NumberUtils does not handle upper-case hex:
0X and -0X</action>
     <action type="update" issue="LANG-736">CharUtils static final array CHAR_STRING
is not needed to compute CHAR_STRING_ARRAY</action>
     <action type="fix" issue="LANG-744">StringUtils throws java.security.AccessControlException
on Google App Engine</action>
     <action type="add" issue="LANG-695">SystemUtils.IS_OS_UNIX doesn't recognize FreeBSD
as a Unix system</action>

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=1160660&r1=1160659&r2=1160660&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Tue Aug 23 12:32:52 2011
@@ -193,8 +193,10 @@ public class NumberUtilsTest {
         assertEquals("createNumber(String) 6 failed", Long.valueOf(12345), NumberUtils.createNumber("12345l"));
         assertEquals("createNumber(String) 7 failed", Float.valueOf("-1234.5"), NumberUtils.createNumber("-1234.5"));
         assertEquals("createNumber(String) 8 failed", Integer.valueOf("-12345"), NumberUtils.createNumber("-12345"));
-        assertTrue("createNumber(String) 9 failed", 0xFADE == NumberUtils.createNumber("0xFADE").intValue());
-        assertTrue("createNumber(String) 10 failed", -0xFADE == NumberUtils.createNumber("-0xFADE").intValue());
+        assertTrue("createNumber(String) 9a failed", 0xFADE == NumberUtils.createNumber("0xFADE").intValue());
+        assertTrue("createNumber(String) 9b failed", 0xFADE == NumberUtils.createNumber("0Xfade").intValue());
+        assertTrue("createNumber(String) 10a failed", -0xFADE == NumberUtils.createNumber("-0xFADE").intValue());
+        assertTrue("createNumber(String) 10b failed", -0xFADE == NumberUtils.createNumber("-0Xfade").intValue());
         assertEquals("createNumber(String) 11 failed", Double.valueOf("1.1E200"), NumberUtils.createNumber("1.1E200"));
         assertEquals("createNumber(String) 12 failed", Float.valueOf("1.1E20"), NumberUtils.createNumber("1.1E20"));
         assertEquals("createNumber(String) 13 failed", Double.valueOf("-1.1E200"), NumberUtils.createNumber("-1.1E200"));



Mime
View raw message