Skip to content

Instantly share code, notes, and snippets.

@oisdk
Last active February 3, 2018 23:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisdk/742a3ce8690888696979c7ee9f4e8584 to your computer and use it in GitHub Desktop.
Save oisdk/742a3ce8690888696979c7ee9f4e8584 to your computer and use it in GitHub Desktop.
#if os(Linux)
import Glibc
#else
import Darwin
#endif
extension String {
func contains(s: String, caseSensitive: Bool = true) -> Bool {
if !caseSensitive { return lowercaseString.contains(s.lowercaseString) }
return characters
.indices
.lazy
.map(characters.suffixFrom)
.contains { tail in tail.startsWith(s.characters) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment