DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13367>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13367 StringUtil enhancement ------- Additional Comments From [EMAIL PROTECTED] 2003-03-13 20:14 ------- Just a comment: I propose the following two functions - the first is identical to Leonardo's suggestione except for the name, but I think the names are clearer. Further, it makes it possible to have both functions (I personally use the latter more than the former, which makes it seem that there are uses for both): /** Removes control characters, including whitespace, from both ends of this string. Returns null if the string is empty (isEmpty(s) is true) or if it's null. @param s the string to me trimmed. @return trim(s), or null if it's empty. */ public String trimToNull(String s) { String ts = trim(s); return (ts == null || ts.length() == 0 ? null : ts); } /** Removes control characters, including whitespace, from both ends of this string if it is not null. Returns an empty string if the string is empty (isEmpty(s) is true) or if it's null. @param s the string to me trimmed. @return trim(s), or the empty string if it's empty. */ public String trimToEmptyString(String s) { String ts = trim(s); return (ts == null ? "" : ts); } Given these functions, here's the expected behaviour (following - and copying - again from the text above): StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc" StringUtils.trim(" ") = "" StringUtils.trim("") = "" StringUtils.trim(null) = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc" StringUtils.trimToNull(" ") = null StringUtils.trimToNull("") = null StringUtils.trimToNull(null) = null StringUtils.trimToEmptyString("abc") = "abc" StringUtils.trimToEmptyString(" abc ") = "abc" StringUtils.trimToEmptyString(" ") = "" StringUtils.trimToEmptyString("") = "" StringUtils.trimToEmptyString(null) = "" --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]