commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Berin Loritsch" <blorit...@apache.org>
Subject RE: [lang] Commons.Lang promotable?
Date Wed, 17 Jul 2002 13:27:06 GMT
> From: Henri Yandell [mailto:bayard@generationjava.com] 
> 
> The CharSet split is done.
> 
> The stripXXX change is not done as the code uses null for a 
> strip on whitespace. The javadoc shows that the original 
> intention was for:
> 
> StringUtils.stripStart("abbaaword","ab") to strip the a's and 
> the b's out.
> 
> A worry there would be that a user would expect it to strip 
> out only the token 'ab' and not any 'a' or 'b'. Indeed, this 
> would seem the more normal usage, so my suggestion would be 
> for the code to handle delimiters larger than a single 
> character and treat the delimiter as an entire token and not 
> a set of characters as the javadoc suggests.
> 
> Any views?
> 
> [I'm assuming this isn't a major issue regarding the Commons 
> promotion].

I disagree.  When you look at java.util.StringTokenizer, when
you have multiple characters in the delimiter, it means that
any one of those characters splits a token.

You just need to document it explicitly that it strips all
characters until it encounters the first character that is not
in the delimiter list.

What real use would there be if we only striped out the token
"ab"?  I can do that by calling m_str.SubString( "ab".length,
m_str.length() );
The only thing I can think of is to add another parameter that
is a boolean to flag wether the algorithm respects the sequence
of characters in the delimiter or not.

In that case, we should have three methods:

// strip whitespace
StringUtils.stripStart(String word)
{
   StringUtils.stripStart( word, " \b\t\r\n\l" );
}

// strip all characters in the delimiters
StringUtils.stripStart(String word, String delimiters)
{
    StringUtils.stripStart( word, delimiters, false );
}

StringUtils.stripStart(String word, String delimiters, boolean
respectSequence)
{
    // .....
}

As the user needs to be more specific about the requirements of the
stripStart/stripEnd methods, they have something that handles it.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message