Various UI fixes

This commit is contained in:
Ilya Laktyushin
2019-09-03 15:22:39 +03:00
parent e94d3b72d0
commit eecae32d48
15 changed files with 2259 additions and 2172 deletions

View File

@@ -2,18 +2,36 @@ import Foundation
public enum ArabicNumeralStringType {
case western
case eastern
case arabic
case persian
}
public func normalizeArabicNumeralString(_ string: String, type: ArabicNumeralStringType) -> String {
var string = string
let numerals = ["٠": "0", "١": "1", "٢": "2", "٣": "3", "٤": "4", "٥": "5", "٦": "6", "٧": "7", "٨": "8", "٩": "9"]
for (easternNumeral, westernNumeral) in numerals {
let numerals = [
("0", "٠", "۰"),
("1", "١", "۱"),
("2", "٢", "۲"),
("3", "٣", "۳"),
("4", "٤", "۴"),
("5", "٥", "۵"),
("6", "٦", "۶"),
("7", "٧", "۷"),
("8", "٨", "۸"),
("9", "٩", "۹"),
]
for (western, arabic, persian) in numerals {
switch type {
case .western:
string = string.replacingOccurrences(of: easternNumeral, with: westernNumeral)
case .eastern:
string = string.replacingOccurrences(of: westernNumeral, with: easternNumeral)
string = string.replacingOccurrences(of: arabic, with: western)
string = string.replacingOccurrences(of: persian, with: western)
case .arabic:
string = string.replacingOccurrences(of: western, with: arabic)
string = string.replacingOccurrences(of: persian, with: arabic)
case .persian:
string = string.replacingOccurrences(of: western, with: persian)
string = string.replacingOccurrences(of: arabic, with: persian)
}
}