<commit_before>package io.schinzel.basicutils.substring;

import io.schinzel.basicutils.Thrower;
import lombok.Builder;
import lombok.Getter;
import lombok.experimental.Accessors;

/**
 * The purpose of this class is to find the index of a string in another string.
 * <p>
 * Created by schinzel on 2017-03-25.
 */
@Accessors(prefix = "m")
class SubstringIndexFinder {
    /** True if the substring was found, else false. */
    @Getter private final boolean mSubstringFound;
    /** The index of the substring */
    @Getter private final int mSubstringPosition;
    /** Flag for last occurrence */
    static final int LAST_OCCURRENCE = Integer.MAX_VALUE;


    @Builder
    SubstringIndexFinder(String string, String subString, int occurrence, int startPos) {
        mSubstringPosition = getPos(string, subString, occurrence, startPos);
        mSubstringFound = (mSubstringPosition > -1);
    }


    /**
     * @param string     The string in which to look for the sub string
     * @param subString  The sub string to look after
     * @param occurrence The occurrence of the sub string
     * @param startPos   From which index to look for the sub string
     * @return The index of the argument sub string in the argument string. -1 if the substring was
     * not found.
     */
    static int getPos(String string, String subString, int occurrence, int startPos) {
        Thrower.throwIfVarTooSmall(occurrence, "occurrence", 1);
        Thrower.throwIfVarTooSmall(occurrence, "startPos", 0);
        //If looking for the last occurrence
        int pos = (occurrence == LAST_OCCURRENCE)
                //Get the last index of the string
                ? string.lastIndexOf(subString)
                //Get the index of the sub string in the string
                : string.indexOf(subString, startPos);
        //If substring was not found
        if (pos == -1) {
            //Return not found flag
            return -1;
        }// else, i.e. the sub string was found
        else {
            //If this was the look after substring occurrence
            return (occurrence == 1 || occurrence == LAST_OCCURRENCE)
                    //Return this position
                    ? pos
                    //Do recursive request for the next occurrence of the substring
                    : getPos(string, subString, --occurrence, pos + subString.length());
        }
    }
}<commit_msg>Bug fix<commit_after>package io.schinzel.basicutils.substring;

import io.schinzel.basicutils.Thrower;
import lombok.Builder;
import lombok.Getter;
import lombok.experimental.Accessors;

/**
 * The purpose of this class is to find the index of a string in another string.
 * <p>
 * Created by schinzel on 2017-03-25.
 */
@Accessors(prefix = "m")
class SubstringIndexFinder {
    /** True if the substring was found, else false. */
    @Getter private final boolean mSubstringFound;
    /** The index of the substring */
    @Getter private final int mSubstringPosition;
    /** Flag for last occurrence */
    static final int LAST_OCCURRENCE = Integer.MAX_VALUE;


    @Builder
    SubstringIndexFinder(String string, String subString, int occurrence, int startPos) {
        mSubstringPosition = getPos(string, subString, occurrence, startPos);
        mSubstringFound = (mSubstringPosition > -1);
    }


    /**
     * @param string     The string in which to look for the sub string
     * @param subString  The sub string to look after
     * @param occurrence The occurrence of the sub string
     * @param startPos   From which index to look for the sub string
     * @return The index of the argument sub string in the argument string. -1 if the substring was
     * not found.
     */
    static int getPos(String string, String subString, int occurrence, int startPos) {
        Thrower.throwIfVarTooSmall(occurrence, "occurrence", 1);
        Thrower.throwIfVarTooSmall(startPos, "startPos", 0);
        //If looking for the last occurrence
        int pos = (occurrence == LAST_OCCURRENCE)
                //Get the last index of the string
                ? string.lastIndexOf(subString)
                //Get the index of the sub string in the string
                : string.indexOf(subString, startPos);
        //If substring was not found
        if (pos == -1) {
            //Return not found flag
            return -1;
        }// else, i.e. the sub string was found
        else {
            //If this was the look after substring occurrence
            return (occurrence == 1 || occurrence == LAST_OCCURRENCE)
                    //Return this position
                    ? pos
                    //Do recursive request for the next occurrence of the substring
                    : getPos(string, subString, --occurrence, pos + subString.length());
        }
    }
}
{'fraction_non_alphanumeric': 0.08166666666666667, 'fraction_numerical': 0.00625, 'mean_word_length': 2.3019257221458047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5013941', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1278, 'n_words': 487}