commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (LANG-1281) Javadoc of StringUtils.ordinalIndexOf is contradictory.
Date Thu, 03 Nov 2016 22:51:58 GMT


ASF GitHub Bot commented on LANG-1281:

Github user aioobe commented on the issue:
    Of course there are matches for the empty string. a) there is both a leading and trailing
empty string in "a" for instance. b) the implementation doesn't return INDEX_NOT_FOUND when
given the empty string.
    As far as I can tell, the implementation increments the position with 1 each time a match
is found, except if the sought string is the empty string, in which case it increments with
0 (conceptually that is; in practice it obviously returns 0 right away for that case, since
if it increments by 0 each match, it will never move away from 0).
    Personally I think the implementation is messy and hard to formalize. It would have been
much better if the implementation consistently stuck the idea of incrementing by 1 for each
match. This would not rule out the optimization because one would simply return n for the
empty search string case.
    Given the situation I guess it's not an option to change the implementation though, so
the only option left is to adjust the documentation to reflect the current behavior. Here
are two suggestions:
    "increments by 1 unless the search string is the empty string in which case the position
is never incremented"
    or something like
    "always returns 0 if the search string is the empty string, otherwise it increments the
position by 1 for each match found"

> Javadoc of StringUtils.ordinalIndexOf is contradictory.
> -------------------------------------------------------
>                 Key: LANG-1281
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.5
>            Reporter: Andreas Lundblad
>            Priority: Minor
> Javadoc of StringUtils.ordinalIndexOf states the following:
> "The code increments the starting index by one, rather than by the length of the match
string, so matches may overlap."
> But then gives the following example:
> StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
> which clearly indicates that it does *not* increment the starting index by one in case
of the empty string.

This message was sent by Atlassian JIRA

View raw message