//
//  CharacterSet+LinuxHack.swift
//  SwiftLint
//
//  Created by Marcelo Fabri on 12/25/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation

extension CharacterSet {
    func isSuperset(ofCharactersIn string: String) -> Bool {
        #if swift(>=4.0) || os(macOS)
            let otherSet = CharacterSet(charactersIn: string)
            return isSuperset(of: otherSet)
        #else
            // workaround for https://bugs.swift.org/browse/SR-3485
            let chars = Set(string.characters)
            for char in chars where !contains(char.unicodeScalar) {
                return false
            }

            return true
        #endif
    }
}

private extension Character {
    var unicodeScalar: UnicodeScalar {
        let characterString = String(self)
        let scalars = characterString.unicodeScalars

        return scalars[scalars.startIndex]
    }
}

//
//  CharacterSet+LinuxHack.swift
//  SwiftLint
//
//  Created by Marcelo Fabri on 12/25/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation

extension CharacterSet {
    func isSuperset(ofCharactersIn string: String) -> Bool {
        #if os(Linux)
            // workaround for https://bugs.swift.org/browse/SR-3485
            let chars = Set(string.characters)
            for char in chars where !contains(char.unicodeScalar) {
                return false
            }

            return true
        #else
            let otherSet = CharacterSet(charactersIn: string)
            return isSuperset(of: otherSet)
        #endif
    }
}

private extension Character {
    var unicodeScalar: UnicodeScalar {
        let characterString = String(self)
        let scalars = characterString.unicodeScalars

        return scalars[scalars.startIndex]
    }
}

--- 
+++ 
@@ -10,7 +10,10 @@
 
 extension CharacterSet {
     func isSuperset(ofCharactersIn string: String) -> Bool {
-        #if os(Linux)
+        #if swift(>=4.0) || os(macOS)
+            let otherSet = CharacterSet(charactersIn: string)
+            return isSuperset(of: otherSet)
+        #else
             // workaround for https://bugs.swift.org/browse/SR-3485
             let chars = Set(string.characters)
             for char in chars where !contains(char.unicodeScalar) {
@@ -18,9 +21,6 @@
             }
 
             return true
-        #else
-            let otherSet = CharacterSet(charactersIn: string)
-            return isSuperset(of: otherSet)
         #endif
     }
 }
Remove hack for SR-3485 when building with Swift 4
