Tekkon // v1.2.8 update.

This commit is contained in:
ShikiSuen 2022-07-28 22:32:54 +08:00
parent a4775acdad
commit ea0d4af280
1 changed files with 128 additions and 77 deletions

View File

@ -48,6 +48,7 @@ public struct Tekkon {
case ofMiTAC = 6 case ofMiTAC = 6
case ofSeigyou = 7 case ofSeigyou = 7
case ofFakeSeigyou = 8 case ofFakeSeigyou = 8
case ofStarlight = 9
case ofHanyuPinyin = 100 case ofHanyuPinyin = 100
case ofSecondaryPinyin = 101 case ofSecondaryPinyin = 101
case ofYalePinyin = 102 case ofYalePinyin = 102
@ -74,6 +75,8 @@ public struct Tekkon {
return "FakeSeigyou" return "FakeSeigyou"
case .ofSeigyou: case .ofSeigyou:
return "Seigyou" return "Seigyou"
case .ofStarlight:
return "Starlight"
case .ofHanyuPinyin: case .ofHanyuPinyin:
return "HanyuPinyin" return "HanyuPinyin"
case .ofSecondaryPinyin: case .ofSecondaryPinyin:
@ -334,6 +337,8 @@ public struct Tekkon {
return Tekkon.mapSeigyou[input] != nil return Tekkon.mapSeigyou[input] != nil
case .ofFakeSeigyou: case .ofFakeSeigyou:
return Tekkon.mapFakeSeigyou[input] != nil return Tekkon.mapFakeSeigyou[input] != nil
case .ofStarlight:
return Tekkon.mapStarlightStaticKeys[input] != nil
case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin: case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin:
return Tekkon.mapArayuruPinyin.contains(input) return Tekkon.mapArayuruPinyin.contains(input)
} }
@ -390,7 +395,10 @@ public struct Tekkon {
case "", "": case "", "":
if vowel.value == "" { vowel = "" } if vowel.value == "" { vowel = "" }
case "": case "":
if "".contains(semivowel.value) { semivowel = "" }
if "ㄧㄩ".contains(semivowel.value) { thePhone = "" } if "ㄧㄩ".contains(semivowel.value) { thePhone = "" }
case "":
if "".contains(semivowel.value) { semivowel = "" }
case "", "": case "", "":
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() } if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "": case "":
@ -398,6 +406,8 @@ public struct Tekkon {
case "": case "":
if "ㄅㄆㄇㄈ".contains(consonant.value), "ㄛㄥ".contains(vowel.value) { vowel.clear() } if "ㄅㄆㄇㄈ".contains(consonant.value), "ㄛㄥ".contains(vowel.value) { vowel.clear() }
if "ㄋㄌ".contains(consonant.value), "".contains(vowel.value) { vowel.clear() } if "ㄋㄌ".contains(consonant.value), "".contains(vowel.value) { vowel.clear() }
if "".contains(vowel.value) { vowel = "" }
if "".contains(vowel.value) { thePhone = "" }
case "", "", "", "": case "", "", "", "":
if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() } if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() }
default: break default: break
@ -537,12 +547,61 @@ public struct Tekkon {
return Tekkon.mapSeigyou[key] ?? "" return Tekkon.mapSeigyou[key] ?? ""
case .ofFakeSeigyou: case .ofFakeSeigyou:
return Tekkon.mapFakeSeigyou[key] ?? "" return Tekkon.mapFakeSeigyou[key] ?? ""
case .ofStarlight:
return handleStarlight(key: key)
case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin: case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin:
break // break //
} }
return "" return ""
} }
///
/// - Parameter incomingPhonabet: Phonabet
mutating func commonFixWhenHandlingDynamicArrangeInputs(target incomingPhonabet: Phonabet) {
//
switch incomingPhonabet.type {
case .semivowel:
switch consonant {
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
default: break
}
case .vowel:
if semivowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
}
default: break
}
}
/// ///
/// ///
/// ///
@ -577,33 +636,8 @@ public struct Tekkon {
default: break default: break
} }
// //
if !consonant.isEmpty, incomingPhonabet.type == .semivowel { commonFixWhenHandlingDynamicArrangeInputs(target: incomingPhonabet)
switch consonant {
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
default: break
}
}
if "dfjk ".contains(key), if "dfjk ".contains(key),
!consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty
@ -666,51 +700,7 @@ public struct Tekkon {
} }
// //
switch incomingPhonabet.type { commonFixWhenHandlingDynamicArrangeInputs(target: incomingPhonabet)
case .semivowel:
switch consonant {
case "": //
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
case "":
if intonation.isEmpty {
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
}
case "":
if intonation.isEmpty {
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
}
case "":
switch incomingPhonabet {
case "": consonant = "" //
case "": consonant = "" //
case "": consonant = "" //
default: break
}
default: break
}
case .vowel:
if semivowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
}
default: break
}
if "dfjs ".contains(key) { if "dfjs ".contains(key) {
if !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty { if !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty {
@ -749,6 +739,48 @@ public struct Tekkon {
return strReturn return strReturn
} }
///
///
///
/// - Parameters:
/// - key: String
mutating func handleStarlight(key: String) -> String {
var strReturn = Tekkon.mapStarlightStaticKeys[key] ?? ""
let incomingPhonabet = Phonabet(strReturn)
switch key {
case "e": return "ㄧㄩ".contains(semivowel.value) ? "" : ""
case "f": return vowel == "" || !isPronouncable ? "" : ""
case "g": return vowel == "" || !isPronouncable ? "" : ""
case "k": return vowel == "" || !isPronouncable ? "" : ""
case "l": return vowel == "" || !isPronouncable ? "" : ""
case "m": return vowel == "" || !isPronouncable ? "" : ""
case "n": return vowel == "" || !isPronouncable ? "" : ""
case "t": return vowel == "" || !isPronouncable ? "" : ""
default: break
}
//
commonFixWhenHandlingDynamicArrangeInputs(target: incomingPhonabet)
if "67890 ".contains(key) {
if !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
}
}
//
if "efgklmn".contains(key) { strReturn = "" }
//
return strReturn
}
/// ///
/// ///
/// ///
@ -765,7 +797,13 @@ public struct Tekkon {
case "b": if !consonant.isEmpty || !semivowel.isEmpty { vowel = "" } else { consonant = "" } case "b": if !consonant.isEmpty || !semivowel.isEmpty { vowel = "" } else { consonant = "" }
case "i": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" } case "i": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" }
case "l": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" } case "l": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" }
case "n": if !consonant.isEmpty || !semivowel.isEmpty { vowel = "" } else { consonant = "" } case "n":
if !consonant.isEmpty || !semivowel.isEmpty {
if consonant == "", semivowel.isEmpty, vowel.isEmpty { consonant.clear() }
vowel = ""
} else {
consonant = ""
}
case "o": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" } case "o": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" }
case "p": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" } case "p": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" }
case "q": if consonant.isEmpty || consonant == "" { consonant = "" } else { consonant = "" } case "q": if consonant.isEmpty || consonant == "" { consonant = "" } else { consonant = "" }
@ -781,7 +819,7 @@ public struct Tekkon {
} else if !semivowel.isEmpty { } else if !semivowel.isEmpty {
vowel = "" vowel = ""
} else { } else {
semivowel = "" receiveKey(fromPhonabet: "ㄐㄑㄒ".contains(consonant.value) ? "" : "")
} }
case "u": case "u":
if semivowel == "", vowel != "" { if semivowel == "", vowel != "" {
@ -895,9 +933,11 @@ public struct Tekkon {
} }
/// ///
/// - Parameter target: 12345 調 /// - Parameters:
/// - target: 12345 調
/// - newToneOne:
/// - Returns: /// - Returns:
static func cnvHanyuPinyinToPhona(target: String) -> String { static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String {
if target.contains("_") { return target } if target.contains("_") { return target }
var result = target var result = target
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) { for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
@ -906,7 +946,7 @@ public struct Tekkon {
} }
for key in Tekkon.mapArayuruPinyinIntonation.keys.sorted(by: { $0.count > $1.count }) { for key in Tekkon.mapArayuruPinyinIntonation.keys.sorted(by: { $0.count > $1.count }) {
guard let value = Tekkon.mapArayuruPinyinIntonation[key] else { continue } guard let value = Tekkon.mapArayuruPinyinIntonation[key] else { continue }
result = result.replacingOccurrences(of: key, with: (key == "1") ? "" : value) result = result.replacingOccurrences(of: key, with: (key == "1") ? newToneOne : value)
} }
return result return result
} }
@ -1371,6 +1411,17 @@ public struct Tekkon {
"w": "", "x": "", "y": "", "z": "", " ": " ", "w": "", "x": "", "y": "", "z": "", " ": " ",
] ]
///
///
/// 便 validity check
///
static let mapStarlightStaticKeys: [String: String] = [
"a": "", "b": "", "c": "", "d": "", "e": "", "f": "", "g": "", "h": "", "i": "", "j": "", "k": "",
"l": "", "m": "", "n": "", "o": "", "p": "", "q": "", "r": "", "s": "", "t": "", "u": "", "v": "",
"w": "", "x": "", "y": "", "z": "", " ": " ", "1": " ", "2": "ˊ", "3": "ˇ", "4": "ˋ", "5": "˙", "6": " ",
"7": "ˊ", "8": "ˇ", "9": "ˋ", "0": "˙",
]
/// ///
static let mapQwertyETenTraditional: [String: String] = [ static let mapQwertyETenTraditional: [String: String] = [
"'": "", ",": "", "-": "", ".": "", "/": "", "0": "", "1": "˙", "2": "ˊ", "3": "ˇ", "4": "ˋ", "7": "", "'": "", ",": "", "-": "", ".": "", "/": "", "0": "", "1": "˙", "2": "ˊ", "3": "ˇ", "4": "ˋ", "7": "",