commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 13367] - StringUtil enhancement
Date Thu, 13 Mar 2003 20:14:58 GMT
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 apacheBugzilla@AMammenT.cotse.net  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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message