You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Henri Yandell <ba...@generationjava.com> on 2002/07/20 21:39:09 UTC

[lang] Avalon.Excalibur.Util.StringUtils

I've taken another look at the StringUtils class that forms a part of the
Util package over at Avalon [submitted to Commons by Nicola Ken Barozzi on
20th June].

The code in there splits into two types:

1) Methods that would be good fits for Lang.StringUtils except that they
can already be expressed using existing Lang.StringUtils methods:

Excalibur.concat(String[]) can be:
Lang.join(String[], "")

Excalibur.replaceSubString(String,String,String) is:
Lang.replace(String,String,String)

Excalibur.truncate(String,int) is:
Lang.left(String,int)

Excalibur.split(String,String) is:
Lang.split(String,String)

Excalibur.stripWhitespace(String) is [I think]:
Lang.CharSetUtils.delete(String, " \t\r\n\b")

Excalibur.join(String[], String) is:
Lang.join(String[], String)

Excalibur.appendWhiteSpace(StringBuffer, int) is:
Lang.rightPad(String, int)
[EXCEPT that appendWS returns void and rightPad returns String]

A couple of these [the ones with String literals] are good examples of
methods that could be added to Commons.Lang as helpful overrides.

I've changed all bar the appendWhiteSpace method and run the build and
unit tests without issue.

2) More esoteric methods which might not be good fits for StringUtils:

hexDisplay(byte[], int) -

    Puts hex display on left and text on right. A nice component, but
    better placed in codec or util.

truncateNicely(String, int) -
    Cuts the length of a String, but tries to do it nicely by truncating
    on whitespace and then appending "..."

wordWrap(String, int, boolean) -
    We moved StringUtils.wordWrap functions out to Commons.Util. This has
    to merge into that somehow.

format(int, int, boolean, String) -

    Another kind of word wrapper. Or maybe wordWrap is kind of String
    formatter. We're starting to accumulate these :)

private:getIndexOfBreak( StringBuffer, String, int, int, forceBreak) -

    wordWrap and truncateNicely both use this.


Any opinions?

Hen


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH] Re: [lang] Avalon.Excalibur.Util.StringUtils

Posted by Peter Donald <pe...@apache.org>.
Rather than redirect calls across and add another dependency I will just leave 
it as is. When the commons stuff is all released we can jus delete the Avalon 
one (which has never been part of formal release anyway).

On Mon, 22 Jul 2002 06:26, Henri Yandell wrote:
> On Sun, 21 Jul 2002, Peter Donald wrote:
> > You can probably drop truncateNicely as I am the only person that uses
> > that. If wordwrap can be pushed somewhere else then thats all good.
>
> I've added deprecated tags to truncateNicely, format and appendWhitespace.
>
> WordWrap and getIndexOfBreak will goto Util.WordWrapper, though it might
> have a silly method name like 'avalonWordWrap' or some such until the code
> can be intelligently merged. HexDisplay to goto Codec at some point. These
> methods aren't deprecated yet.
>
> Also deprecated all methods that merely call over to
> Commons.Lang.StringUtils.
>
> Commons.Lang.StringUtils now has a deleteWhitespace method.
>
> Patch and new source both attached. Code compiles and tests pass.
>
> > format() has been supersceded by the printf() stuff in jdk1.4
>
> Really? Where's this in 1.4? I made the choice of a Mac for Java, so stuck
> on 1.3.
>
> Hen

-- 
Cheers,

Peter Donald
--------------------------------------------------
 Logic: The art of being wrong with confidence...
--------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[PATCH] Re: [lang] Avalon.Excalibur.Util.StringUtils

Posted by Henri Yandell <ba...@generationjava.com>.

On Sun, 21 Jul 2002, Peter Donald wrote:

> You can probably drop truncateNicely as I am the only person that uses that.
> If wordwrap can be pushed somewhere else then thats all good.

I've added deprecated tags to truncateNicely, format and appendWhitespace.

WordWrap and getIndexOfBreak will goto Util.WordWrapper, though it might
have a silly method name like 'avalonWordWrap' or some such until the code
can be intelligently merged. HexDisplay to goto Codec at some point. These
methods aren't deprecated yet.

Also deprecated all methods that merely call over to
Commons.Lang.StringUtils.

Commons.Lang.StringUtils now has a deleteWhitespace method.

Patch and new source both attached. Code compiles and tests pass.

>
> format() has been supersceded by the printf() stuff in jdk1.4

Really? Where's this in 1.4? I made the choice of a Mac for Java, so stuck
on 1.3.

Hen

Re: [lang] Avalon.Excalibur.Util.StringUtils

Posted by Peter Donald <pe...@apache.org>.
On Sun, 21 Jul 2002 05:39, Henri Yandell wrote:
> I've taken another look at the StringUtils class that forms a part of the
> Util package over at Avalon [submitted to Commons by Nicola Ken Barozzi on
> 20th June].
>
> The code in there splits into two types:
>
> 1) Methods that would be good fits for Lang.StringUtils except that they
> can already be expressed using existing Lang.StringUtils methods:

sounds good to me.

> 2) More esoteric methods which might not be good fits for StringUtils:
>
> hexDisplay(byte[], int) -
>
>     Puts hex display on left and text on right. A nice component, but
>     better placed in codec or util.
>
> truncateNicely(String, int) -
>     Cuts the length of a String, but tries to do it nicely by truncating
>     on whitespace and then appending "..."
>
> wordWrap(String, int, boolean) -
>     We moved StringUtils.wordWrap functions out to Commons.Util. This has
>     to merge into that somehow.
>
> format(int, int, boolean, String) -
>
>     Another kind of word wrapper. Or maybe wordWrap is kind of String
>     formatter. We're starting to accumulate these :)
>
> private:getIndexOfBreak( StringBuffer, String, int, int, forceBreak) -
>
>     wordWrap and truncateNicely both use this.
>
>
> Any opinions?

You can probably drop truncateNicely as I am the only person that uses that. 
If wordwrap can be pushed somewhere else then thats all good. 

format() and the appendWhitespace(StringBuffer) were used for a performance 
logging applicaiton and probably can go the way of the dodo. Especially since 
format() has been supersceded by the printf() stuff in jdk1.4

thanks for this!

-- 
Cheers,

Peter Donald
*---------------------------------------------------------*
| Contrary to popular belief, UNIX is user-friendly. It   |
| just happens to be selective on who it makes friendship |
| with.                                                   |
|                       - Richard Cook                    |
*---------------------------------------------------------* 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>