commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steven Caswell" <ste...@caswell.name>
Subject RE: [lang] Adding Purple to StringUtils
Date Wed, 05 Mar 2003 21:54:48 GMT
I mostly agree with Henri's comments. Just a couple of additional comments
thrown in...


Steven Caswell
steven@caswell.name
a.k.a Mungo Knotwise of Michel Delving
"One ring to rule them all, one ring to find them..."


> -----Original Message-----
> From: Henri Yandell [mailto:bayard@generationjava.com] 
> Sent: Wednesday, March 05, 2003 1:53 PM
> To: Jakarta Commons Developers List; alex@jguru.com
> Subject: Re: [lang] Adding Purple to StringUtils
> 
> 
> 
> 
> On Wed, 5 Mar 2003, Alex Chaffee / Purple Technology wrote:
> 
> > I'll list these independently, so we can start haggling over
> >
> > 1. yea or nay
> > 2. naming
> > 3. API / method signature
> > 4. appropriate package (if lang.StringUtils is not the right place)
> 
> Seems good.
> 
> > for each in turn.  Naturally, I'm open to any negotiation; 
> the methods 
> > I'd really like to lobby for are htmlescape and strdiffVerbose.
> >
> >  - Alex
> >
> > * isWhitespace(String str)
> >
> > Returns true if the str contains only whitespace characters.
> >
> > Fills a gap in the isAlphanumeric family.  (Funny that 
> isWhitespace is 
> > the only one of the bunch that I had occasion to write!)
> 
> Already there. I suspect it's just not in the 1.0 release.
> 
> > * abbreviate(String str, int max)
> >
> > Turn "Now is the time for all good men" into "Now is the 
> time for..."
> >
> > Specifically:
> >
> > If str is less than max characters long, return it.
> > Else abbreviate it to (substring(str, 0, max-3) + "...").
> > If max is less than 3, throw an IllegalArgumentException.
> > In no case will it return a string of length greater than max.
> 
> String Taglib has a truncateNicely method which is similar to 
> this. I like the abbreviate name and am yea on this, as long 
> as it incorporates trunc-nicely [STATUS.html has a note to 
> add truncateNicely]
> 
> > * String strdiff(String s1, String s2)
> >
> > Compare two strings, and return the portion where they 
> differ.  (More 
> > precisely, return the remainder of the second string, starting from 
> > where it's different from the first.) e.g. strdiff("i am a 
> machine", 
> > "i am a robot") -> "robot"
> >
> > * int strdiffat(String s1, String s2)
> >
> > Compare two strings, and return the index at which the 
> strings begin 
> > to diverge. E.g. strdiff("i am a machine", "i am a robot") -> 7<p>
> > return -1 if they are the same
> 
> yea on both of these.

I'd rename them so the names better indicate the functionality. How about
remainingDifference and differsAt


> 
> >
> > * String strdiffVerbose(String expected, String actual)
> >
> > Compare two strings, and return a verbose description of how they 
> > differ. Shows a window around the location to provide context.
> >
> > E.g. strdiffVerbose("i am a robot", "i am a machine") might 
> return a 
> > string containing
> >
> > strings differ at character 7
> > Expected: ...am a robot
> >   Actual: ...am a machine
> >
> > This was developed in order to provide some sanity to JUnit's 
> > assertEquals display.
> 
> Nay. It's not a 'util' but an applicatin on top of the utils.
> 
> > * String rtrim(String orig)
> > * String ltrim(String orig)
> >
> > Trim the whitespace off the right or left side of a String only. 
> > (Probably rename trimRight and trimLeft.)
> 
> stripStart and stripEnd I believe.
> 
> > * int maxLength(Iterator i)
> >
> > return the length of the longest string in i.  If i contains other 
> > than strings, uses toString() value.
> 
> Not convinced. StringUtils has a stripAll(String[]), which is 
> also a bit daft. Really we're just duplicating every method 
> to get a map() function.
> 
> map( StringUtils.strip, array )
> 
> though the above has a touch of max logic to it. I think it 
> is silly for us to add these. [quick note to implement 'map' in Java].
> 
> > * htmlescape(String)     (should rename: escapeHtml)
> > * htmlunescape(String)   (should rename: unescapeHtml)
> >
> > Turns funky characters into HTML entity equivalents (and 
> vice versa). 
> > This is far and away the most-used function I have.  There is 
> > definitely a need for it to be in Commons.  Apparently there's some 
> > debate as to whether it's appropriate for StringUtils.
> 
> Definitely not going to get in StringUtils. It is a very 
> useful function though.
> 
> > My code supports all the named entities I know about. See 
> > http://hotwired.lycos.com/webmonkey/reference/special_characters/
> >
> >
> > * String jsEscape    (should rename: escapeJavaScript)
> >
> > JavaScript's string escaping is nearly identical to Java's, 
> and it's 
> > sort of a no-brainer to support it as well as Java.  (In 
> JS, a single 
> > quote is escaped; in Java it's not.)
> >
> > * uncurlQuotes(String)
> >
> > Turn Windows and Mac curly-quotes into their non-curly ASCII 
> > equivalents.
> >
> >
> > * capitalize
> >
> > Properly-spelled version of capitalise :-)
> 
> Hey, I offered to rename it :) The general consensus was that 
> there was no reason to enforce such spelling.
> 
> > * lowerize
> >
> > Symmetrical with capitalize. Turn the first character into a 
> > lower-case letter.
> 
> uncapitalize :) Not as amusing as lowerize, but same feature.
> 
> > * pluralize
> >
> > turn String s into a plural English noun (doing the right 
> thing with 
> > "story" -> "stories" and "mess" -> "messes")
> 
> Does it handle all english though? ie) It will fail on 
> pluralising abacus etc.

Seems to me to be beyond the scope of StringUtils

> 
> > * toUnderscore
> >
> > Converts camelCaseVersusC to camel_case_versus_c
> >
> > I'd love to get some ideas on a better name for this.  
> Also, it'd be 
> > nice to have a full, symmetrical set of camelCase vs. 
> under_score vs. 
> > CONSTANT_NAMING vs. "separate words" naming style converters.
> 
> Hmm. Probably a bit specific for StringUtils. Do people often 
> need this?

+1 to Henri's comment. Seems beyond StringUtils scope.

> 
> > * getStackTrace(Throwable t)
> >
> > Convenience method to get a stack trace as a string:
> >         StringWriter s = new StringWriter();
> >         PrintWriter p = new PrintWriter(s);
> >         t.printStackTrace(p);
> >         p.close();
> >         return s.toString();
> 
> This ought to already exist in ExceptionUtils. It made the 
> journey out of StringUtils early on.
> 
> Hen
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
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