<commit_before>//
//  Premier+String.swift
//  PremierKit
//
//  Created by <NAME> on 20/09/2018.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation

extension String {

    /// Trim whitespace.
    public var trimmed: String {
        return self.trimmingCharacters(in: CharacterSet.whitespaces)
    }

    /// Truncate string after a given length if it is longer than the given length and add a text at the end when it overflows (ellipsis by default).
    public func truncated(at maxLength: Int, suffix: String? = nil) -> String {
        let value = self.trimmed
        if value.lengthOfBytes(using: .utf8) > maxLength {
            let index = self.index(self.startIndex, offsetBy: min(self.count, max(0, maxLength)))
            let truncated = String(value[..<index])
            if let suffix = suffix {
                return truncated + suffix
            }
            return truncated
        }
        return value
    }

    /// Email validation (based on https://emailregex.com/)
    func isEmail() -> Bool {
        let emailRegex = "(?:[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}" +
            "~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" +
            "x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\p{L}0-9](?:[a-" +
            "z0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?|\\[(?:(?:25[0-5" +
            "]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" +
            "9][0-9]?|[\\p{L}0-9-]*[\\p{L}0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" +
            "-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
        return validate(regex: emailRegex)
    }

    /// Validate string with a Regular Expression formula.
    func validate(regex: String) -> Bool {
        return NSPredicate(format: "SELF MATCHES %@", regex).evaluate(with: self)
    }

    /// String is not empty.
    public var isNotEmpty: Bool {
        return !isEmpty
    }

    /// String is blank.
    public var isBlank: Bool {
        return allSatisfy({ $0.isWhitespace })
    }

}

extension Optional where Wrapped == String {

    public var isBlank: Bool {
        return self?.isBlank ?? true
    }

}
<commit_msg>String: fix access level<commit_after>//
//  Premier+String.swift
//  PremierKit
//
//  Created by <NAME> on 20/09/2018.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation

extension String {

    /// Trim whitespace.
    public var trimmed: String {
        return self.trimmingCharacters(in: CharacterSet.whitespaces)
    }

    /// Truncate string after a given length if it is longer than the given length and add a text at the end when it overflows (ellipsis by default).
    public func truncated(at maxLength: Int, suffix: String? = nil) -> String {
        let value = self.trimmed
        if value.lengthOfBytes(using: .utf8) > maxLength {
            let index = self.index(self.startIndex, offsetBy: min(self.count, max(0, maxLength)))
            let truncated = String(value[..<index])
            if let suffix = suffix {
                return truncated + suffix
            }
            return truncated
        }
        return value
    }

    /// Email validation (based on https://emailregex.com/)
    public func isEmail() -> Bool {
        let emailRegex = "(?:[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}" +
            "~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" +
            "x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\p{L}0-9](?:[a-" +
            "z0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?|\\[(?:(?:25[0-5" +
            "]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" +
            "9][0-9]?|[\\p{L}0-9-]*[\\p{L}0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" +
            "-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
        return validate(regex: emailRegex)
    }

    /// Validate string with a Regular Expression formula.
    public func validate(regex: String) -> Bool {
        return NSPredicate(format: "SELF MATCHES %@", regex).evaluate(with: self)
    }

    /// String is not empty.
    public var isNotEmpty: Bool {
        return !isEmpty
    }

    /// String is blank.
    public var isBlank: Bool {
        return allSatisfy({ $0.isWhitespace })
    }

}

extension Optional where Wrapped == String {

    public var isBlank: Bool {
        return self?.isBlank ?? true
    }

}

{'fraction_non_alphanumeric': 0.23039754008346144, 'fraction_numerical': 0.048759059960465624, 'mean_word_length': 1.9609882964889467, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '939016', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1752, 'n_words': 327}