<commit_before>//
//  String.swift
//  ZXFoundation
//
//  Created by <NAME> on 9/8/16.
//  Copyright © 2016 ZX Ventures. All rights reserved.
//

import Foundation

extension String {
    
    /// String with quotes. Typically used for JSON.
    internal var quotes: String {
        return "\"\(self)\""
    }
    
    /// String with no quotes. Such as defining a type in JSON.
    internal var noQuotes: String {
        return self.replace("\"", withString: "")
    }
    
    /// String wrapped in braces. Such as a dictionary.
    internal var braces: String {
        return "{\(self)}"
    }
    
    fileprivate func replace(_ string: String, withString new: String) -> String {
        return self.replacingOccurrences(of: string, with: new, options: NSString.CompareOptions.literal, range: nil)
    }
}
<commit_msg>Add String extension for stripping trailing whitespace.<commit_after>//
//  String.swift
//  ZXFoundation
//
//  Created by <NAME> on 9/8/16.
//  Copyright © 2016 ZX Ventures. All rights reserved.
//

import Foundation

extension String {
    
    /// String with quotes. Typically used for JSON.
    public var quotes: String {
        return "\"\(self)\""
    }
    
    /// String with no quotes. Such as defining a type in JSON.
    public var noQuotes: String {
        return self.replace("\"", withString: "")
    }
    
    /// String wrapped in braces. Such as a dictionary.
    public var braces: String {
        return "{\(self)}"
    }
    
    /// String represented without any trailing whitespace.
    public var noTrailingWhitespace: String {
        
        /// Strips whitespace from a string recursively.
        func strip( _ str: String) -> String {
            guard str.characters.last == " " else { return str }
            let str = str.substring(to: str.index(before: str.endIndex))
            guard str.characters.last != " " else { return strip(str) }
            return str
        }
        
        return strip(self)
    }
    
    fileprivate func replace(_ string: String, withString new: String) -> String {
        return self.replacingOccurrences(of: string, with: new, options: NSString.CompareOptions.literal, range: nil)
    }
}

{'fraction_non_alphanumeric': 0.11323328785811733, 'fraction_numerical': 0.007276034561164165, 'mean_word_length': 2.142857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5706703', 'n_tokens_mistral': 644, 'n_tokens_neox': 615, 'n_words': 212}