Last active
February 2, 2019 01:01
-
-
Save leodabus/db13b9b8b84e108b046d03da8db3c54b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Swift 4.2.1 syntax | |
public struct SubstringMatchSource<S: StringProtocol> where S.Index == String.Index { | |
private let wrapped: S | |
public init(wrapping wrapped: S) { | |
self.wrapped = wrapped | |
} | |
public static func ~=<T: StringProtocol> (substring: T, source: SubstringMatchSource) -> Bool { | |
return source.wrapped.contains(substring) | |
} | |
} | |
extension StringProtocol where Index == String.Index { | |
var substrings: SubstringMatchSource<Self> { | |
return SubstringMatchSource(wrapping: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment