Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1213

ordinalIndexOf may skip first occurrence when searched string is longer than 1 char

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Resolved
    • None
    • 3.4
    • None
    • None

    Description

      The method

      private static int ordinalIndexOf(final CharSequence str, final CharSequence searchStr, final int ordinal, final boolean lastIndex) 
      

      source
      at the line

      1028                index = CharSequenceUtils.indexOf(str, searchStr, index + searchStr.length());
      

      is using as starting index for search the index+searchStr.length() .In case where the searchStr is a single character, the first run will start from index

      -1+1 = 0
      

      if the searchStr is long N, it will start at N-1 index and if str contains the searchStr before N-1 it will miss it

      Attachments

        Activity

          People

            Unassigned Unassigned
            alexgallotta@gmail.com Alessandro Gallotta
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: