myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r740764 - in /myfaces/tobago/branches/tobago-1.0.x/core/src: main/java/org/apache/myfaces/tobago/util/LayoutUtil.java test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
Date Wed, 04 Feb 2009 15:16:11 GMT
Author: idus
Date: Wed Feb  4 15:16:10 2009
New Revision: 740764

URL: http://svn.apache.org/viewvc?rev=740764&view=rev
Log:
TOBAGO-639: removed regular expression used in replaceAll

Modified:
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java?rev=740764&r1=740763&r2=740764&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
Wed Feb  4 15:16:10 2009
@@ -128,7 +128,7 @@
         String labelWidth = (String) label.getAttributes().get(ATTR_WIDTH);
         if (labelWidth != null) {
           try {
-            return Integer.parseInt(labelWidth.replaceAll("\\D", ""));
+            return Integer.parseInt(stripNonNumericChars(labelWidth));
           } catch (NumberFormatException e) {
             LOG.warn("Can't parse label width, using default value", e);
           }
@@ -153,7 +153,7 @@
     Object value = ComponentUtil.getAttribute(component, sizeAttribute);
     if (value != null) {
       if (value instanceof String) {
-        return new Integer(((String) value).replaceAll("\\D", ""));
+        return new Integer(stripNonNumericChars(((String) value)));
       } else {
         return (Integer) value;
       }
@@ -281,4 +281,18 @@
     return LayoutTokens.parseToken(columnToken) != null;
   }
 
+  static String stripNonNumericChars(String token) {
+    if (token == null || token.isEmpty()) {
+      return token;
+    }
+    StringBuilder builder = new StringBuilder(token.length());
+    for (int i = 0; i < token.length(); ++i) {
+      char c = token.charAt(i);
+      if (Character.isDigit(c)) {
+        builder.append(c);
+      }
+    }
+    return builder.toString();
+  }
+
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java?rev=740764&r1=740763&r2=740764&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
Wed Feb  4 15:16:10 2009
@@ -7,19 +7,27 @@
  */
 public class LayoutUtilTest extends TestCase {
 
-    public void testCheckTokens() {
-        assertTrue(LayoutUtil.checkTokens("1px;*;25%;fixed"));
-        assertFalse(LayoutUtil.checkTokens("1px; *; fixed")); // XXX whitespace shouldn't
matter
-        assertTrue(LayoutUtil.checkTokens("0px"));
-        assertTrue(LayoutUtil.checkTokens("1px"));
-        assertTrue(LayoutUtil.checkTokens("99999px"));
-        assertTrue(LayoutUtil.checkTokens("*"));
-        assertTrue(LayoutUtil.checkTokens("1*"));
-        assertTrue(LayoutUtil.checkTokens("99*"));
-        assertTrue(LayoutUtil.checkTokens("0%"));
-        assertTrue(LayoutUtil.checkTokens("1%"));
-        assertTrue(LayoutUtil.checkTokens("200%")); // XXX percentile value over 100 doesn't
make much sense, does it?
-        assertTrue(LayoutUtil.checkTokens("fixed"));
-    }
+  public void testCheckTokens() {
+    assertTrue(LayoutUtil.checkTokens("1px;*;25%;fixed"));
+    assertFalse(LayoutUtil.checkTokens("1px; *; fixed")); // XXX whitespace shouldn't matter
+    assertTrue(LayoutUtil.checkTokens("0px"));
+    assertTrue(LayoutUtil.checkTokens("1px"));
+    assertTrue(LayoutUtil.checkTokens("99999px"));
+    assertTrue(LayoutUtil.checkTokens("*"));
+    assertTrue(LayoutUtil.checkTokens("1*"));
+    assertTrue(LayoutUtil.checkTokens("99*"));
+    assertTrue(LayoutUtil.checkTokens("0%"));
+    assertTrue(LayoutUtil.checkTokens("1%"));
+    assertTrue(LayoutUtil.checkTokens("200%")); // XXX percentile value over 100 doesn't
make much sense, does it?
+    assertTrue(LayoutUtil.checkTokens("fixed"));
+  }
+
+  public void testStripNonNumericChars() {
+    assertEquals("1", LayoutUtil.stripNonNumericChars("1px"));
+    assertEquals("99", LayoutUtil.stripNonNumericChars("99px"));
+    assertEquals("50", LayoutUtil.stripNonNumericChars("50%"));
+    assertEquals("3", LayoutUtil.stripNonNumericChars("3*"));
+    assertEquals("", LayoutUtil.stripNonNumericChars("*"));
+  }
 
 }



Mime
View raw message