Skip to content

Commit

Permalink
Add extensions to manipulate string collections
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianvarela committed Dec 5, 2016
1 parent 78562c9 commit 66a63fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Helpers/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ public extension String {
let endIndex = index(from: r.upperBound)
return substring(with: startIndex..<endIndex)
}

public func isMatched(by occurrences: [String]) -> Bool {
return occurrences.matchWith(occurrence: self)
}
}

public extension Sequence where Iterator.Element == String {
public func matchWith(occurrence: String) -> Bool {
return contains(where: { el in
return occurrence.range(of: el, options: [.diacriticInsensitive, .caseInsensitive], range: nil, locale: nil) != nil
})
}
}
7 changes: 6 additions & 1 deletion Test.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ let azzz4 = Time(timeString: "12:32")?.seconds
let acasa = azzz1 < azzz2

azzz1.toFormattedTimeString()
azzz1.toFormattedTimeString(showSeconds: true)
azzz1.toFormattedTimeString(showSeconds: true)


let cosas = ["Cróssfit", "baba", "caca", "culo"]
"voy a crossfit".isMatched(by: cosas)

0 comments on commit 66a63fa

Please sign in to comment.