Skip to content

Commit

Permalink
Merge pull request #32 from AckeeCZ/string_remove_diacritics
Browse files Browse the repository at this point in the history
Add `string.removingDiacritics()`
  • Loading branch information
janmisar authored Sep 11, 2018
2 parents d28bf7f + 75d80b7 commit 636bafb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ACKategories/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ extension String {
public func trimmed(charactersIn string: String, from side: Side = .both) -> String {
return trimmed(characterSet: CharacterSet(charactersIn: string), from: side)
}

/// Removes diacritics from string using given locale
///
/// If no locale is given `Locale.current` is used
public func removingDiacritics(_ locale: Locale = Locale.current) -> String {
return folding(options: .diacriticInsensitive, locale: locale)
}
}

// MARK: - Deprecations
Expand Down
5 changes: 5 additions & 0 deletions Tests/StringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ final class StringTests: XCTestCase {
let string = paddedString.trimmed(charactersIn: "xy0", from: .both)
XCTAssertEqual(string, "a00bc")
}

func testDiacriticIsRemoved() {
let originalString = "ěščřžýáíéasdfghjkl"
XCTAssertEqual(originalString.removingDiacritics(), "escrzyaieasdfghjkl")
}
}

0 comments on commit 636bafb

Please sign in to comment.