[ 
https://issues.apache.org/jira/browse/LANG-1077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14244691#comment-14244691
 ] 

Bruno P. Kinoshita commented on LANG-1077:
------------------------------------------

So are you +1 for we applying the existing patch, with your original code? If 
so I will commit the patch to the trunk tonight.

Also, if you agree, I would like to update the title from 
"StringUtils.ordinalIndexOf("aaaaaa", "aa", 2) != 2 in StringUtils" to 
"StringUtils.ordinalIndexOf("aaaaaa", "aa", 2) != *3* in StringUtils" just to 
avoid any confusion in the future.

> (BTW, I a newcomer and we have a project which uses Commons Lang a lot. 
> that's why i'm looking into code. Commons Lang provides a lot of useful APIs 
> and help me a lot. appreciate the work you guys have done. Good job!)

That's a great initiative Haiyang. We are a group of volunteers, and the 
feedback and contributions like yours are very important. Feel free to report 
other issues. If you feel like, you can also write patches (tests are always 
welcome :-D ), this way your code can get merged and released to all users (how 
cool is that?).

All the best,
Bruno

> [PATCH] StringUtils.ordinalIndexOf("aaaaaa", "aa", 2)  != 2 in StringUtils
> --------------------------------------------------------------------------
>
>                 Key: LANG-1077
>                 URL: https://issues.apache.org/jira/browse/LANG-1077
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.3.2
>            Reporter: haiyang li
>              Labels: patch
>             Fix For: Discussion
>
>         Attachments: LANG-1077.patch
>
>
> {code:title= org.apache.commons.lang3.StringUtils.java|borderStyle=solid}
>         int found = 0;
>         int index = lastIndex ? str.length() : INDEX_NOT_FOUND;
>         do {
>             if (lastIndex) {
>                 index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 
> 1);
>             } else {
>                 index = CharSequenceUtils.indexOf(str, searchStr, index + 1);
>             }
>             if (index < 0) {
>                 return index;
>             }
>             found++;
>         } while (found < ordinal);
> {code}
> Should it be:
> {code:title= org.apache.commons.lang3.StringUtils.java|borderStyle=solid}
>         private static int ordinalIndexOf(final CharSequence str, final 
> CharSequence searchStr, final int ordinal, final boolean lastIndex) {
>         //        if (str == null || searchStr == null || ordinal <= 0) {
>         //            return INDEX_NOT_FOUND;
>         //        }
>         //        if (searchStr.length() == 0) {
>         //            return lastIndex ? str.length() : 0;
>         //        }
>         //        int found = 0;
>         //        int index = lastIndex ? str.length() : INDEX_NOT_FOUND;
>         //        do {
>         //            if (lastIndex) {
>         //                index = CharSequenceUtils.lastIndexOf(str, 
> searchStr, index - 1);
>         //            } else {
>         //                index = CharSequenceUtils.indexOf(str, searchStr, 
> index + 1);
>         //            }
>         //            if (index < 0) {
>         //                return index;
>         //            }
>         //            found++;
>         //        } while (found < ordinal);
>         //        return index;
>         if (str == null || searchStr == null || ordinal <= 0) {
>             return INDEX_NOT_FOUND;
>         }
>         if (searchStr.length() == 0) {
>             return lastIndex ? str.length() : 0;
>         }
>         final int searchStrLen = searchStr.length();
>         int index = lastIndex ? str.length() : 0;
>         for (int found = 0; index >= 0;) {
>             if (lastIndex) {
>                 index = CharSequenceUtils.lastIndexOf(str, searchStr, index);
>             } else {
>                 index = CharSequenceUtils.indexOf(str, searchStr, index);
>             }
>             if (index < 0) {
>                 return INDEX_NOT_FOUND;
>             }
>             if (++found >= ordinal) {
>                 break;
>             }
>             index = lastIndex ? index - searchStrLen : index + searchStrLen;
>         }
>         return index;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to