<commit_before>//
//  String.swift
//  Cent
//
//  Created by <NAME> on 6/30/14.
//  Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved.
//

import Foundation
import Dollar

public extension String {
    
    public var length: Int {
        get {
            return self.characters.count
        }
    }
    
    /// Get character at a subscript
    ///
    /// :param i Index for which the character is returned
    /// :return Character at index i
    public subscript(i: Int) -> Character? {
        if let char = Array(self.characters).get(i) {
            return char
        }
        return .None
    }

    /// Get character at a subscript
    ///
    /// :param i Index for which the character is returned
    /// :return Character at index i
    public subscript(pattern: String) -> String? {
        if let range = Regex(pattern).rangeOfFirstMatch(self).toRange() {
            return self[range]
        }
        return .None
    }

    /// Get substring using subscript notation and by passing a range
    ///
    /// :param range The range from which to start and end the substring
    /// :return Substring
    public subscript(range: Range<Int>) -> String {
        let start = startIndex.advancedBy(range.startIndex)
        let end = startIndex.advancedBy(range.endIndex)
        return self.substringWithRange(Range(start: start, end: end))
    }
    
    /// Get the start index of Charcter
    ///
    /// :return start index of .None if not found
    public func indexOf(char: Character) -> Int? {
        return self.indexOf(char.description)
    }
    
    /// Get the start index of string
    ///
    /// :return start index of .None if not found
    public func indexOf(str: String) -> Int? {
        return self.indexOfRegex(Regex.escapeStr(str))
    }
    
    /// Get the start index of regex pattern
    ///
    /// :return start index of .None if not found<commit_msg>Typo fix in Cent/String.swift documentation<commit_after>//
//  String.swift
//  Cent
//
//  Created by <NAME> on 6/30/14.
//  Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved.
//

import Foundation
import Dollar

public extension String {
    
    public var length: Int {
        get {
            return self.characters.count
        }
    }
    
    /// Get character at a subscript
    ///
    /// :param i Index for which the character is returned
    /// :return Character at index i
    public subscript(i: Int) -> Character? {
        if let char = Array(self.characters).get(i) {
            return char
        }
        return .None
    }

    /// Get character at a subscript
    ///
    /// :param i Index for which the character is returned
    /// :return Character at index i
    public subscript(pattern: String) -> String? {
        if let range = Regex(pattern).rangeOfFirstMatch(self).toRange() {
            return self[range]
        }
        return .None
    }

    /// Get substring using subscript notation and by passing a range
    ///
    /// :param range The range from which to start and end the substring
    /// :return Substring
    public subscript(range: Range<Int>) -> String {
        let start = startIndex.advancedBy(range.startIndex)
        let end = startIndex.advancedBy(range.endIndex)
        return self.substringWithRange(Range(start: start, end: end))
    }
    
    /// Get the start index of Character
    ///
    /// :return start index of .None if not found
    public func indexOf(char: Character) -> Int? {
        return self.indexOf(char.description)
    }
    
    /// Get the start index of string
    ///
    /// :return start index of .None if not found
    public func indexOf(str: String) -> Int? {
        return self.indexOfRegex(Regex.escapeStr(str))
    }
    
    /// Get the start index of regex pattern
    ///
    /// :return start index of .None if not found
{'fraction_non_alphanumeric': 0.10589151310667012, 'fraction_numerical': 0.004671684401764859, 'mean_word_length': 1.9174867524602575, 'pattern_counts': {'":': 0, '<': 7, '<?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': '316508', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1059, 'n_words': 383}