commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <ggreg...@seagullsw.com>
Subject RE: [lang] new functionality in StringUtils and ArrayUtils - prop osal 01
Date Mon, 24 Nov 2003 00:24:23 GMT
>   /**
>   * Flanks the given string with the flank String or char.
>   * <pre>
>   * StringUtils.flank(null, *)      = null
>   * StringUtils.flank("", *)        = *
>   * StringUtils.flank("abc", null)  = abc
>   * StringUtils.flank("abc", "x")  = xabcx
>   * StringUtils.flank("abc", "xy")  = xyabcxy  // xy...xy
>   * </pre>
>   */
>   StringUtils.flank(String flankee, String flank)
>   StringUtils.flank(String flankee, char flank)

I am not fond of the word "flank", it is not part of my string manipulation
vocabulary, maybe it is a Perl thing? I think "wrap" or your other "enclose"
is *much* better for things like that.

>   * StringUtils.flank("", *)        = *

This one does not seem quite right:

StringUtils.flank("", "x") = "x" 

Should it not be = "xx"?

>   /**
>    * <pre>
>    * StringUtils.doubleQuote("Now is the time...") = "Now is the time..."
>    * </pre>
>    */
>   StringUtils.doubleQuote(String quotee)

The edge cases are not specified in the above. An @see could also do be
added to avoid duplicating the edge case docs.

>   StringUtils.lead(String leadee, String leadChar)

hmmm... "abc" + "zz" = "zzabc"

Unless you want to handle edge cases specifically this seems over the top...

Gary

> -----Original Message-----
> From: Ash .. [mailto:equinus100@hotmail.com]
> Sent: Sunday, November 23, 2003 12:45
> To: commons-dev@jakarta.apache.org
> Cc: equinus100@hotmail.com
> Subject: [lang] new functionality in StringUtils and ArrayUtils - proposal
> 01
> 
> Hi,
> 
> I would like to propose the following methods to the StringUtils and
> ArrayUtils classes.
> They are just minor additions to the existing functionality, but I thought
> would be interesting,
> hopefully quite useful too.
> 
> 
> Waiting for feedback and looking forward to some development in this
> regard.
> I would be glad to submit an implementation to the concerned people, if
> you
> feel this functionality
> is include-worthy.
> 
> Thanks,
> Ash
> 
> 
> 
> 
> 
> 
>   /**
>   * Flanks the given string with the flank String or char.
>   * <pre>
>   * StringUtils.flank(null, *)      = null
>   * StringUtils.flank("", *)        = *
>   * StringUtils.flank("abc", null)  = abc
>   * StringUtils.flank("abc", "x")  = xabcx
>   * StringUtils.flank("abc", "xy")  = xyabcxy  // xy...xy
>   * </pre>
>   */
>   StringUtils.flank(String flankee, String flank)
>   StringUtils.flank(String flankee, char flank)
> 
> 
> Some special cases of flanking are quotes.
> 
>   /**
>    * <pre>
>    * StringUtils.singleQuote("Now is the time...") = 'Now is the time...'
>    * </pre>
>    */
>   StringUtils.singleQuote(String quotee)
> 
> 
> 
> 
>   /**
>    * Enclose the string with a pair of symmetrical characters
>    * given one of the pair. Such pairs are
>    *
>    * <tt>
>    * (), {}, [], &lt;&gt;,
>    * </tt>
>    *
>    * When the encloser is not from a recognized pair,
>    * the method resorts to flank-like appending, with the order
>    * for the afterpart reversed.
>    *
>    * <pre>
>    * StringUtils.enclose("abc", "[")    = "[abc]"
>    * StringUtils.enclose("abc", "[[")   = "[[abc]]"
>    * StringUtils.enclose("abc", "x")    = xabcx
>    * StringUtils.enclose("abc", "xy")   = xyabcyx  // xy..yx
>    * </pre>
>    *
>    * @param enclosee the String to be enclosed
>    * @param either of such pairs of strings as given above
>    */
>   StringUtils.enclose(String enclosee, String encloser)
> 
> 
> 
>   /**
>    * <pre>
>    * StringUtils.lead("abc", "zz")  = "zzabc"
>    * </pre>
>    */
>   StringUtils.lead(String leadee, String leadStr)
> 
>   /**
>    * <pre>
>    * StringUtils.lead("abc", '.', 3)  = "abc..."
>    */
>   StringUtils.lead(String leadee, char leadStr,   int repeatCount)
>   StringUtils.lead(String leadee, String leadStr, int repeatCount)
> 
>   /**
>    * <pre>
>    * StringUtils.trail("abc", "zz")  = "abczz"
>    * </pre>
>    */
>   StringUtils.trail(String trailee, String trailStr)
>   StringUtils.trail(String trailee, char trailChar)
>   StringUtils.trail(String trailee, String trailStr, int repeatCount)
>   StringUtils.trail(String trailee, char trailChar, int repeatCount)
> 
> 
> 
>   /**
>    * The concept of naught.
>    * True if the String is null or "null".
>    * <pre>
>    * StringUtils.isNaught("abc") = false
>    * StringUtils.isNaught(null)  = true
>    * StringUtils.isNaught("null") = true
>    * </pre>
>    */
>   StringUtils.isNaught(String str)
> 
> 
> 
>   // ArrayUtils methods
> 
>   /**
>    * Similar to the existing <code>toString</code> but
>    * using delimiter given.
>    */
>   ArrayUtils.toString(Object array, String delimiter)
>   ArrayUtils.toString(Object array, char delimiter)
> 
>   /**
>    * A <code>toString</code> that emits only a given part
>    * of the array.
>    */
>   ArrayUtils.toString(Object arr, int startIndex, int endIndex)
> 
> 
> 
>   /**
>    * Obtain a new array of the given size, with the elements
>    * present between startIndex (inclusive) and endIndex (exclusive).
>    */
>   ArrayUtils.subarray(arr, startIndex, endIndex)
> 
> 
> 
> 
> ---------------
> 
> 
> 
> 
> >The concept of a "naught" String.
> >
> >A String is naught if it is either 'null' or is the literal "null".
> >
> >I have often encountered this situation in my JSP project where a
> >particular
> >parameter is passed in
> >as x=null, and I need to insert code everytime saying if(x == null ||
> >x.equals("null"))
> 
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://www.msn.co.uk/messenger
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message