Skip to content

Instantly share code, notes, and snippets.

@leodabus
Last active February 2, 2019 01:01
Show Gist options
  • Save leodabus/db13b9b8b84e108b046d03da8db3c54b to your computer and use it in GitHub Desktop.
Save leodabus/db13b9b8b84e108b046d03da8db3c54b to your computer and use it in GitHub Desktop.
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