Repo // Tekkon v1.2.9 update.

This commit is contained in:
ShikiSuen 2022-08-10 08:57:12 +08:00
parent f7e703dc57
commit 57f9daa5cb
1 changed files with 11 additions and 1 deletions

View File

@ -922,7 +922,8 @@ public struct Tekkon {
/// - newToneOne:
/// - Returns:
static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String {
if target.contains("_") { return target }
///
if target.contains("_") || !target.isNotPureAlphanumerical { return target }
var result = target
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
guard let value = Tekkon.mapHanyuPinyin[key] else { continue }
@ -1446,3 +1447,12 @@ public struct Tekkon {
"s": "", "t": "", "u": "", "v": "", "w": "", "x": "", "y": "", "z": "", " ": " ",
]
}
///
extension String {
fileprivate var isNotPureAlphanumerical: Bool {
let regex = ".*[^A-Za-z0-9].*"
let testString = NSPredicate(format: "SELF MATCHES %@", regex)
return testString.evaluate(with: self)
}
}