<commit_before>//
//  StringExtensions.swift
//  Swiftility
//
//  Created by <NAME> on 9/16/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

// MARK: - Operations
extension String
{
    /// Get only String length
    public var length: Int { return self.characters.count }
    
    // MARK: - Subscript

    public subscript (i: Int) -> Character {
        return self[self.startIndex.advancedBy(i)]
    }
    
    public subscript (i: Int) -> String {
        return String(self[self.startIndex.advancedBy(i)])
    }
    
    public subscript (r: Range<Int>) -> String {
        get {
            let startIndex = self.startIndex.advancedBy(r.startIndex)
            let endIndex = startIndex.advancedBy(r.endIndex - r.startIndex)
            
            return self[startIndex..<endIndex]
        }
        
        set {
            let startIndex = self.startIndex.advancedBy(r.startIndex)
            let endIndex = startIndex.advancedBy(r.endIndex - r.startIndex)
            
            self.replaceRange(startIndex..<endIndex, with: newValue)
        }
    }
    
    public func trim(set: NSCharacterSet = .whitespaceAndNewlineCharacterSet()) -> String
    {
        return self.stringByTrimmingCharactersInSet(set)
    }

    public var words: [String] {
        var result = [String]()
        
        enumerateSubstringsInRange(startIndex..<endIndex, options: .ByWords) {
            (substring, substringRange, enclosingRange, stop) in
            
            if let substring = substring {
                result.append(substring)
            }
        }
        
        return result
    }
    
    public func inserting(string: String, index: Int) -> String
    {
        return String(self.characters.prefix(index)) + string + String(self.characters.suffix(self.characters.count - index))
    }

    public func URLEncoding() -> String?
    {
        guard let characters = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as? NSMutableCharacterSet else { return nil }
        
        characters.removeCharactersInString("&")
        
        guard let encodedString = self.stringByAddingPercentEncodingWithAllowedCharacters(characters) else { return nil }
        
        return encodedString
    }<commit_msg>Remove: String sub script range setter<commit_after>//
//  StringExtensions.swift
//  Swiftility
//
//  Created by <NAME> on 9/16/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

// MARK: - Operations
extension String
{
    /// Get only String length
    public var length: Int { return self.characters.count }
    
    // MARK: - Subscript

    public subscript (i: Int) -> Character {
        return self[self.startIndex.advancedBy(i)]
    }
    
    public subscript (i: Int) -> String {
        return String(self[self.startIndex.advancedBy(i)])
    }
    
    public subscript (r: Range<Int>) -> String {
        get {
            let startIndex = self.startIndex.advancedBy(r.startIndex)
            let endIndex = startIndex.advancedBy(r.endIndex - r.startIndex)
            
            return self[startIndex..<endIndex]
        }
    }
    
    public func trim(set: NSCharacterSet = .whitespaceAndNewlineCharacterSet()) -> String
    {
        return self.stringByTrimmingCharactersInSet(set)
    }

    public var words: [String] {
        var result = [String]()
        
        enumerateSubstringsInRange(startIndex..<endIndex, options: .ByWords) {
            (substring, substringRange, enclosingRange, stop) in
            
            if let substring = substring {
                result.append(substring)
            }
        }
        
        return result
    }
    
    public func inserting(string: String, index: Int) -> String
    {
        return String(self.characters.prefix(index)) + string + String(self.characters.suffix(self.characters.count - index))
    }

    public func URLEncoded() -> String?
    {
        guard let characters = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as? NSMutableCharacterSet else { return nil }
        
        characters.removeCharactersInString("&")
        
        guard let encodedString = self.stringByAddingPercentEncodingWithAllowedCharacters(characters) else { return nil }
        
        return encodedString
    }
{'fraction_non_alphanumeric': 0.09928090930178612, 'fraction_numerical': 0.0041753653444676405, 'mean_word_length': 2.142857142857143, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 21, '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': '1371594', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1187, 'n_words': 270}