code: private static int ordinalIndexOf(String str, String searchStr, int ordinal, 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 = str.lastIndexOf(searchStr, index - 1);
              } else {
                  index = str.indexOf(searchStr, index + 1);
              }
              if (index < 0) {
                  return index;
              }
              found++;
          } while (found < ordinal);
          return index;
      }
docs: Shared code between ordinalIndexOf(String,String,int) and lastOrdinalIndexOf(String,String,int)