commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r662273 - in /commons/proper/configuration/branches/configuration2_experimental: ./ src/main/java/org/apache/commons/configuration2/PropertyConverter.java src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java
Date Sun, 01 Jun 2008 19:39:25 GMT
Author: oheger
Date: Sun Jun  1 12:39:25 2008
New Revision: 662273

URL: http://svn.apache.org/viewvc?rev=662273&view=rev
Log:
CONFIGURATION-307: Provide a variant of PropertiesConverter.split() which allows disabling
trimming (porting changes from trunk to this branch)

Modified:
    commons/proper/configuration/branches/configuration2_experimental/   (props changed)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java

Propchange: commons/proper/configuration/branches/configuration2_experimental/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Jun  1 12:39:25 2008
@@ -15,3 +15,7 @@
 *.ser
 junit*.properties
 *.patch
+
+.externalToolBuilders
+
+maven-eclipse.xml

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java?rev=662273&r1=662272&r2=662273&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
Sun Jun  1 12:39:25 2008
@@ -57,9 +57,10 @@
      *
      * @param s          the string to split
      * @param delimiter  the delimiter
+     * @param trim       a flag whether the single elements should be trimmed
      * @return a list with the single tokens
      */
-    public static List<String> split(String s, char delimiter)
+    public static List<String> split(String s, char delimiter, boolean trim)
     {
         if (s == null)
         {
@@ -93,7 +94,12 @@
                 if (c == delimiter)
                 {
                     // found a list delimiter -> add token and reset buffer
-                    list.add(token.toString().trim());
+                    String t = token.toString();
+                    if (trim)
+                    {
+                        t = t.trim();
+                    }
+                    list.add(t);
                     token = new StringBuilder();
                 }
                 else if (c == LIST_ESC_CHAR)
@@ -116,12 +122,30 @@
             token.append(LIST_ESC_CHAR);
         }
         // Add last token
-        list.add(token.toString().trim());
+        String t = token.toString();
+        if (trim)
+        {
+            t = t.trim();
+        }
+        list.add(t);
 
         return list;
     }
 
     /**
+     * Split a string on the specified delimiter always trimming the elements.
+     * This is a shortcut for <code>split(s, delimiter, true)</code>.
+     *
+     * @param s          the string to split
+     * @param delimiter  the delimiter
+     * @return a list with the single tokens
+     */
+    public static List<String> split(String s, char delimiter)
+    {
+        return split(s, delimiter, true);
+    }
+
+    /**
      * Escapes the delimiters that might be contained in the given string. This
      * method ensures that list delimiter characters that are part of a
      * property's value are correctly escaped when a configuration is saved to a

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java?rev=662273&r1=662272&r2=662273&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java
Sun Jun  1 12:39:25 2008
@@ -47,6 +47,17 @@
         assertEquals("3rd token for '" + s + "'", "123", list.get(2));
     }
 
+    public void testSplitNoTrim()
+    {
+        String s = "abc, xyz , 123";
+        List<String> list = PropertyConverter.split(s, ',', false);
+
+        assertEquals("size", 3, list.size());
+        assertEquals("1st token for '" + s + "'", "abc", list.get(0));
+        assertEquals("2nd token for '" + s + "'", " xyz ", list.get(1));
+        assertEquals("3rd token for '" + s + "'", " 123", list.get(2));
+    }
+
     public void testSplitWithEscapedSeparator()
     {
         String s = "abc\\,xyz, 123";



Mime
View raw message