<commit_before>//
//  String+UT.swift
//
//  Created by <NAME> on 10/25/16.
//

import Foundation
import UIKit

extension String {
    
    public static var lineSeparator:String {
        get {
            return "\u{2028}"
        }
    }    
    
    public func truncateText(_ characters: Int) -> String {
        if self.characters.count <= characters {
            return self
        }
        
        let truncTitle = (self as NSString).substring(with: NSRange(location:0, length:characters))
        var trimmed = truncTitle.trimmingCharacters(in: CharacterSet.whitespaces)
        trimmed = trimmed + "..."
        
        return trimmed
    }
    
    public var glyphCount: Int {
        let richText = NSAttributedString(string: self)
        let line = CTLineCreateWithAttributedString(richText)
        return CTLineGetGlyphCount(line)
    }
    
    public var isSingleEmoji: Bool {
        return glyphCount == 1 && containsEmoji
    }
    
    public var containsEmoji: Bool {
        return unicodeScalars.map { $0 }.filter { $0.isEmoji }.count != 0
    }
    
    public var containsOnlyEmoji: Bool {
        return characters.count > 0 && characters.count == unicodeScalars.map { $0 }.filter { $0.isEmoji }.count
    }

    
    @available(iOS 9, *)
    public func createLink(_ link: String, fontSize: CGFloat, linkColor:UIColor = UIColor.defaultBlue) -> NSMutableAttributedString {
        let linkString = NSMutableAttributedString(string: self)
        let range = NSMakeRange(0, linkString.length)
        
        linkString.beginEditing()
        linkString.addAttribute(NSLinkAttributeName, value: link, range: range)
        linkString.addAttribute(NSForegroundColorAttributeName, value: linkColor, range: range)
        linkString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.styleNone.rawValue, range: range)
        linkString.endEditing()

        return linkString
    }
}



extension UnicodeScalar {
    
    var isEmoji: Bool {<commit_msg>String.isValidEmail<commit_after>//
//  String+UT.swift
//
//  Created by <NAME> on 10/25/16.
//

import Foundation
import UIKit

extension String {
    
    public static var lineSeparator:String {
        get {
            return "\u{2028}"
        }
    }    
    
    public func truncateText(_ characters: Int) -> String {
        if self.characters.count <= characters {
            return self
        }
        
        let truncTitle = (self as NSString).substring(with: NSRange(location:0, length:characters))
        var trimmed = truncTitle.trimmingCharacters(in: CharacterSet.whitespaces)
        trimmed = trimmed + "..."
        
        return trimmed
    }
    
    public var glyphCount: Int {
        let richText = NSAttributedString(string: self)
        let line = CTLineCreateWithAttributedString(richText)
        return CTLineGetGlyphCount(line)
    }
    
    public var isSingleEmoji: Bool {
        return glyphCount == 1 && containsEmoji
    }
    
    public var containsEmoji: Bool {
        return unicodeScalars.map { $0 }.filter { $0.isEmoji }.count != 0
    }
    
    public var containsOnlyEmoji: Bool {
        return characters.count > 0 && characters.count == unicodeScalars.map { $0 }.filter { $0.isEmoji }.count
    }

    public var isValidEmail: Bool {
        do {
        let regex = try NSRegularExpression(pattern: "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$", options: .caseInsensitive)
            return regex.firstMatch(in: self, options: NSRegularExpression.MatchingOptions.anchored, range:  NSMakeRange(0, self.characters.count)) != nil
        } catch {
            print(error)
        }
        return false
    }
    
    @available(iOS 9, *)
    public func createLink(_ link: String, fontSize: CGFloat, linkColor:UIColor = UIColor.defaultBlue) -> NSMutableAttributedString {
        let linkString = NSMutableAttributedString(string: self)
        let range = NSMakeRange(0, linkString.length)
        
        linkString.beginEditing()
        linkString.addAttribute(NSLinkAttributeName, value: link, range: range)
        linkString.addAttribute(NSForegroundColorAttributeName, value: linkColor, range: range)
        linkString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.styleNone.rawValue, range: range)
        linkString.endEditing()

        return linkString
    }
}



extension UnicodeScalar {
    
    var isEmoji: Bool {
{'fraction_non_alphanumeric': 0.10773664375969852, 'fraction_numerical': 0.013522500554200843, 'mean_word_length': 2.5058275058275057, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '214247', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1355, 'n_words': 295}