commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Johnson (JIRA)" <j...@apache.org>
Subject [jira] Updated: (LANG-269) Shouldn't Commons Lang's StringUtils have a "common" string method?
Date Sun, 09 Jul 2006 03:27:30 GMT
     [ http://issues.apache.org/jira/browse/LANG-269?page=all ]

Scott Johnson updated LANG-269:
-------------------------------

    Attachment: StringUtils.patch

Interesting problem...

Here's a patch that adds two new methods to StringUtils. 

The first is a new method indexOfDifference(String[]).  It's very similar to indexOfDifference(String,String)
except it operates on an array of Strings.  (It actually uses indexOfDifference(String, String)
internally.)  

The second method is called getCommonPrefix (String[]) which does what Michael requested.
 It calls indexOfDifference(String[]) to find the position of the first difference, then returns
the beginning character sequence that is shared between all of the strings.

Both methods handle null arrays, null array entries and empty Strings.

Let me know what you think.

> Shouldn't Commons Lang's StringUtils have a "common" string method?
> -------------------------------------------------------------------
>
>          Key: LANG-269
>          URL: http://issues.apache.org/jira/browse/LANG-269
>      Project: Commons Lang
>         Type: New Feature

>  Environment: generic
>     Reporter: Michael Dang
>      Fix For: 3.0
>  Attachments: StringUtils.patch
>
> A method which accepts a string array and returns a string which is the common portion
of all the strings starting from the left, or more general form of that.
> This is very common operation.  For example, one may want to find the common directory
of a set of path strings.
> passing in:
> "/foo/f1.txt"
> "/foo/moo/f2.txt"
> "/foo/moo/f3.txt"
> should returns "/foo/"
> It is tedious to implement this in every project.  And I think Commons Lang StringUtils
should have some methods to help in this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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