<commit_before>//
//  NSColor+hex.swift
//  Tello
//
//  Created by Pirijan on 2014-07-08.
//  Copyright (c) 2014 pketh. All rights reserved.
//
//  ♥︎ https://github.com/pketh/NSColor-hex-Swift
//


import Cocoa

extension NSColor {
    class func fromHex(hexColor: String) -> NSColor {
        var hex = String()
        if hexColor.hasPrefix("#") {
            hex = hexColor[1]
        } else {
            hex = hexColor
        }

        func hexToCGFloat(color: String) -> CGFloat {
            var result: CUnsignedInt = 0
            var scanner: NSScanner = NSScanner.scannerWithString(color)
            scanner.scanHexInt(&result)
            var colorValue: CGFloat = CGFloat(result)
            return colorValue / 255
        }

        let redComponent = hexToCGFloat(hex[0...1]),
        greenComponent = hexToCGFloat(hex[2...3]),
        blueComponent = hexToCGFloat(hex[4...5])

        let color = NSColor(calibratedRed: redComponent, green: greenComponent, blue: blueComponent, alpha: 1)

        return color
    }
}

extension String {
    subscript (i: Int) -> String {
        return String(Array(self)[i])
    }
    subscript (r: Range<Int>) -> String {
        var start = advance(startIndex, r.startIndex)
            var end = advance(startIndex, r.endIndex)
            return substringWithRange(Range(start: start, end: end))
    }
}


// ## sample usage
// var hexColor = "#259B9A"
// NSColor.fromHex(hexColor)
// returns an NSColor object:
// `NSColor(calibratedRed: 0.8, green: 0.322, blue: 0.322, alpha: 1)`<commit_msg>Swift 2.0 and Xcode 7 Updates<commit_after>//
//  NSColor+hex.swift
//  Tello
//
//  Created by Pirijan on 2014-07-08.
//  Copyright (c) 2014 pketh. All rights reserved.
//
//  ♥︎ https://github.com/pketh/NSColor-hex-Swift
//


import Cocoa

extension NSColor {
    class func fromHex(hexColor: String) -> NSColor {
        var hex = String()
        if hexColor.hasPrefix("#") {
            hex = hexColor[1]
        } else {
            hex = hexColor
        }

        func hexToCGFloat(color: String) -> CGFloat {
            var result: CUnsignedInt = 0
            let scanner: NSScanner = NSScanner(string: color)
            scanner.scanHexInt(&result)
            let colorValue: CGFloat = CGFloat(result)
            return colorValue / 255
        }

        let redComponent = hexToCGFloat(hex[0...1]),
        greenComponent = hexToCGFloat(hex[2...3]),
        blueComponent = hexToCGFloat(hex[4...5])

        let color = NSColor(calibratedRed: redComponent, green: greenComponent, blue: blueComponent, alpha: 1)

        return color
    }
}

extension String {
    subscript (i: Int) -> String {
        return String(Array(arrayLiteral: self)[i])
    }
    subscript (r: Range<Int>) -> String {
        let start = startIndex.advancedBy(r.startIndex)
        let end = startIndex.advancedBy(r.endIndex)
        return substringWithRange(Range(start: start, end: end))
    }
}


// ## sample usage
// var hexColor = "#259B9A"
// NSColor.fromHex(hexColor)
// returns an NSColor object:
// `NSColor(calibratedRed: 0.8, green: 0.322, blue: 0.322, alpha: 1)`
{'fraction_non_alphanumeric': 0.12859884836852206, 'fraction_numerical': 0.025911708253358926, 'mean_word_length': 2.2572916666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7421407', 'n_tokens_mistral': 1067, 'n_tokens_neox': 999, 'n_words': 240}