private static int ordinalIndexOf(CharSequence str, CharSequence 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 = 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;
    }
<p>Finds the n-th index within a String, handling {@code null}.
This method uses {@link String#indexOf(String)} if possible.</p>

<p>A {@code null} CharSequence will return {@code -1}.</p>

@param str  the CharSequence to check, may be null
@param searchStr  the CharSequence to find, may be null
@param ordinal  the n-th {@code searchStr} to find
@param lastIndex true if lastOrdinalIndexOf() otherwise false if ordinalIndexOf()
@return the n-th index of the search CharSequence,
 {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input
android/android_framework/base/src/main/java/lang3/StringUtils.java