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

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

Hi Haiyang!

Your code does make sense, and I've made a patch with it (hope you don't mind) 
for others to take a look and experiment with it. 

I thought about committing it to the trunk, but I got confused with the title 
of the issue.

Running the code as is in the trunk, {{StringUtils.ordinalIndexOf("aaaaaa", 
"aa", 2)}} returns *1*. After applying the patch with your code, 
{{StringUtils.ordinalIndexOf("aaaaaa", "aa", 2)}} returns *3*... so it is still 
!= 2, and I think that's the expected behavior.

Do you reckon that the expected result should be indeed *3*? 

Thanks!
Bruno

> 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
>             Fix For: Discussion
>
>
> {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}
>         int found = 0;
>         int index = lastIndex ? str.length() : INDEX_NOT_FOUND;
>         do {
>             if (lastIndex) {
>                 index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 
> searchStr.length());
>             } else {
>                 index = CharSequenceUtils.indexOf(str, searchStr, index + 
> searchStr.length());
>             }
>             if (index < 0) {
>                 return index;
>             }
>             found++;
>         } while (found < ordinal);
> {code}



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

Reply via email to