<commit_before>/* 
 * Copyright (C) 2014 Information Retrieval Group at Universidad Autonoma
 * de Madrid, http://ir.ii.uam.es
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package es.uam.eps.ir.ranksys.core.util;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
public class FastStringSplitter {

    public static CharSequence[] split(String line, int delimiter) {
        List<Integer> l = limits(line, delimiter);

        CharSequence[] tokens = new CharSequence[l.size() - 1];
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = new StringSegment(line, l.get(i) + 1, l.get(i + 1));
        }

        return tokens;
    }

    public static CharSequence[] split(CharSequence line, int delimiter) {
        List<Integer> l = limits(line, delimiter);

        CharSequence[] tokens = new CharSequence[l.size() - 1];
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = new StringSegment(line, l.get(i) + 1, l.get(i + 1));
        }

        return tokens;
    }

    private static List<Integer> limits(String line, int delimiter) {
        List<Integer> l = new ArrayList<>();

        int j = -1;
        do {
            l.add(j);
            j = line.indexOf(delimiter, j + 1);
        } while (j != -1);
        l.add(line.length());

        return l;
    }

    private static List<Integer> limits(CharSequence line, int delimiter) {
        List<Integer> l = new ArrayList<>();

        int j = -1;
        do {
            l.add(j);
            j = indexOf(line, delimiter, j + 1);
        } while (j != -1);
        l.add(line.length());<commit_msg>FastStringSplitter: harder, better, stronger<commit_after>/* 
 * Copyright (C) 2014 Information Retrieval Group at Universidad Autonoma
 * de Madrid, http://ir.ii.uam.es
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package es.uam.eps.ir.ranksys.core.util;

import gnu.trove.list.array.TIntArrayList;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
public class FastStringSplitter {

    public static CharSequence[] split(String line, int delimiter) {
        return split(line, delimiter, Integer.MAX_VALUE);
    }

    public static CharSequence[] split(String line, int delimiter, int n) {
        TIntArrayList l = limits(line, delimiter, n);

        CharSequence[] tokens = new CharSequence[l.size() - 1];
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = new StringSegment(line, l.getQuick(i) + 1, l.getQuick(i + 1));
        }

        return tokens;
    }

    public static CharSequence[] split(CharSequence line, int delimiter) {
        return split(line, delimiter, Integer.MAX_VALUE);
    }

    public static CharSequence[] split(CharSequence line, int delimiter, int n) {
        TIntArrayList l = limits(line, delimiter, n);

        CharSequence[] tokens = new CharSequence[l.size() - 1];
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = new StringSegment(line, l.getQuick(i) + 1, l.getQuick(i + 1));
        }

        return tokens;
    }

    private static TIntArrayList limits(String line, int delimiter, int n) {
        TIntArrayList l = new TIntArrayList();

        int j = -1;
        do {
            l.add(j);
            j = line.indexOf(delimiter, j + 1);
        } while (j != -1 && l.size() <= n - 1);
        l.add(line.length());

        return l;
    }

    private static TIntArrayList limits(CharSequence line, int delimiter, int n) {
        TIntArrayList l = new TIntArrayList();

        int j = -1;
        do {
            l.add(j);
            j = indexOf(line, delimiter, j + 1);
        } while (j != -1 && l.size() <= n - 1);
        l.add(line.length());
{'fraction_non_alphanumeric': 0.11855775106946424, 'fraction_numerical': 0.008148299042574863, 'mean_word_length': 2.507142857142857, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6003405', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1426, 'n_words': 516}