<commit_before>import Foundation

// demo at the bottom ⬇️⬇️⬇️

extension String {
    
    // search for consecutive characters as cohesive string
    func chars (string: String) -> [Int]? {
        var ints:[Int] = []
        let array = self.componentsSeparatedByString(string)
        var pointer = 0
        for item in array {
            ints.append(item.characters.count + pointer)
            pointer += item.characters.count + string.characters.count
        }
        let arr = Array(ints[0..<ints.count - 1])
        return arr.count > 0 ? arr : nil
    }
    
    // search for discrete characters
    func chars (characters: [Character]) -> [Int]? {
        var ints:[[Int]] = []
        var charsThusFar:[Character] = []
        for char in characters {
            if !charsThusFar.contains(char) {
                charsThusFar.append(char)
                if let charInts = chars(char) {
                    ints.append(charInts)
                }
            }
        }
        return ints.count > 0 ? ints.flatMap {$0}.sort() : nil
    }
    
    // search for individual characters
    func chars (character: Character) -> [Int]? {
        var ints:[Int] = []
        for (index, element) in self.characters.enumerate() {
            if element == character {
                ints.append(index)
            }
        }
        return ints.count > 0 ? ints : nil
    }
    
    // helper utility
    func indexOf(string: String) -> String.Index {
        return rangeOfString(string, options: .LiteralSearch, range: nil, locale: nil)?.startIndex ?? startIndex
    }
}
"🍣sashimi!!!🍣".chars("🍣")
"this is a sample".chars(" ")
"this is a sample".chars("is")
"this is a sample".chars(Array("is".characters))
"nofuckingmatch".chars(" ")


<commit_msg>added Zalgo example edited one other example<commit_after>import Foundation

// demo at the bottom ⬇️⬇️⬇️

extension String {
    
    // search for consecutive characters as cohesive string
    func chars (string: String) -> [Int]? {
        var ints:[Int] = []
        let array = self.componentsSeparatedByString(string)
        var pointer = 0
        for item in array {
            ints.append(item.characters.count + pointer)
            pointer += item.characters.count + string.characters.count
        }
        let arr = Array(ints[0..<ints.count - 1])
        return arr.count > 0 ? arr : nil
    }
    
    // search for discrete characters
    func chars (characters: [Character]) -> [Int]? {
        var ints:[[Int]] = []
        var charsThusFar:[Character] = []
        for char in characters {
            if !charsThusFar.contains(char) {
                charsThusFar.append(char)
                if let charInts = chars(char) {
                    ints.append(charInts)
                }
            }
        }
        return ints.count > 0 ? ints.flatMap {$0}.sort() : nil
    }
    
    // search for individual characters
    func chars (character: Character) -> [Int]? {
        var ints:[Int] = []
        for (index, element) in self.characters.enumerate() {
            if element == character {
                ints.append(index)
            }
        }
        return ints.count > 0 ? ints : nil
    }
    
    // helper utility
    func indexOf(string: String) -> String.Index {
        return rangeOfString(string, options: .LiteralSearch, range: nil, locale: nil)?.startIndex ?? startIndex
    }
}



"f̤̬͕̳͇̰̗̿͑̏̇̕̕͟͝ą͚͓͇̥̂́̽̍̕͢ņ͙͉̣̪̞͙͎͌́̄͂͐̕͟t̸̻̭̝̣̳̯̙͍̥̿̍̐͂̀̈́̓̀̚͜͠ą̸̣̥̫̠̤̝̓̇͊̒̊̂̉͜͟s̸̛̳̮̪͍̗̈̄̐̈͂̏̈͐ț̵͓̤̯͇̩̩͖̀͆̽̕͘͝ǐ̸̡̨̨̫̖̒̆̑̑̅͐̚ć̸̬͈̫͚̮͂̈̀́̍̏͑̈́͘ͅ-̴̼̪͙̮̗̀̓͗͐͗́̄͘͢ç̶̠̦̝̝̼̻̈̔̑͊̑̾͘̕ḥ̶̡̢̜͚͉̘̖̥͙̏̏͒̈̃͑͊̚͞â̴̯̱̳̼̲̭̐̄͛͌͟͠͡͠ỉ̷̢͚̰͇̗̲͇̅͛̀̀̾͢ͅn͇̣͓͍̑̇̔̀̇̽͊̈͐͜͢͠s̡̛̜͖͔͉̬͂̑̈̐͂̓͢á̵̛̛̺̹̘̤͈̮͇̫̈́͐͐͋͘͟͠w̦̗͇̱̥͓̖͉̯̥̉̔̾̽̽͋̋͛̚".chars("ç̶̠̦̝̝̼̻̈̔̑͊̑̾͘̕")



"🍣sashimi!!!🍣".chars("🍣")
"this is a sample".chars(" ")
"this is a sample".chars("is")
"this is a sample".chars(Array("is".characters))
"nomatchexists".chars(" ")



{'fraction_non_alphanumeric': 0.19548486403283735, 'fraction_numerical': 0.0035915854284248334, 'mean_word_length': 2.195901639344262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2387613', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1680, 'n_words': 271}