I added a new method to StringUtils. It trims a string, returning null if
the string only has whitespace.

Bug#: 13367

Leonardo Quijano
[EMAIL PROTECTED]
Index: StringUtils.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
retrieving revision 1.32
diff -u -r1.32 StringUtils.java
--- StringUtils.java    20 Jan 2003 22:15:13 -0000      1.32
+++ StringUtils.java    22 Jan 2003 18:22:10 -0000
@@ -120,6 +120,21 @@
     }
 
     /**
+     * <p>Removes control characters, including whitespace, from both
+     * ends of this String. Returns null if the String is empty or if 
+     * it's null.</p>
+     *
+     * @see StringUtils#isEmpty(String)
+     * @see java.lang.String#trim()
+     * @param str the String to check
+     * @return the trimmed text (or <code>null</code>)
+     */
+    public static String trimNull(String str) {
+        String ts = trim(str);
+        return (ts == null || ts.length() == 0 ? null : ts);
+    }
+
+    /**
      * <p>Deletes all 'space' characters from a String.</p>
      *
      * <p>Spaces are defined as <code>{' ', '\t', '\r', '\n', '\b'}</code>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to