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 ofSeigyou = 7
case ofFakeSeigyou = 8
case ofStarlight = 9
case ofHanyuPinyin = 100
case ofSecondaryPinyin = 101
case ofYalePinyin = 102
@ -74,6 +75,8 @@ public struct Tekkon {
return "FakeSeigyou"
case .ofSeigyou:
return "Seigyou"
case .ofStarlight:
return "Starlight"
case .ofHanyuPinyin:
return "HanyuPinyin"
case .ofSecondaryPinyin:
@ -334,6 +337,8 @@ public struct Tekkon {
return Tekkon.mapSeigyou[input] != nil
case .ofFakeSeigyou:
return Tekkon.mapFakeSeigyou[input] != nil
case .ofStarlight:
return Tekkon.mapStarlightStaticKeys[input] != nil
case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin:
return Tekkon.mapArayuruPinyin.contains(input)
}
@ -390,7 +395,10 @@ public struct Tekkon {
case "", "":
if vowel.value == "" { vowel = "" }
case "":
if "".contains(semivowel.value) { semivowel = "" }
if "ㄧㄩ".contains(semivowel.value) { thePhone = "" }
case "":
if "".contains(semivowel.value) { semivowel = "" }
case "", "":
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
@ -398,6 +406,8 @@ public struct Tekkon {
case "":
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 "", "", "", "":
if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() }
default: break
@ -537,12 +547,61 @@ public struct Tekkon {
return Tekkon.mapSeigyou[key] ?? ""
case .ofFakeSeigyou:
return Tekkon.mapFakeSeigyou[key] ?? ""
case .ofStarlight:
return handleStarlight(key: key)
case .ofHanyuPinyin, .ofSecondaryPinyin, .ofYalePinyin, .ofHualuoPinyin, .ofUniversalPinyin:
break //
}
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
}
//
if !consonant.isEmpty, incomingPhonabet.type == .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
}
default: break
}
}
//
commonFixWhenHandlingDynamicArrangeInputs(target: incomingPhonabet)
if "dfjk ".contains(key),
!consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty
@ -666,51 +700,7 @@ public struct Tekkon {
}
//
switch incomingPhonabet.type {
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
}
commonFixWhenHandlingDynamicArrangeInputs(target: incomingPhonabet)
if "dfjs ".contains(key) {
if !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty {
@ -749,6 +739,48 @@ public struct Tekkon {
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 "i": 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 "p": if vowel.isEmpty || vowel == "" { vowel = "" } else { vowel = "" }
case "q": if consonant.isEmpty || consonant == "" { consonant = "" } else { consonant = "" }
@ -781,7 +819,7 @@ public struct Tekkon {
} else if !semivowel.isEmpty {
vowel = ""
} else {
semivowel = ""
receiveKey(fromPhonabet: "ㄐㄑㄒ".contains(consonant.value) ? "" : "")
}
case "u":
if semivowel == "", vowel != "" {
@ -895,9 +933,11 @@ public struct Tekkon {
}
///
/// - Parameter target: 12345 調
/// - Parameters:
/// - target: 12345 調
/// - newToneOne:
/// - Returns:
static func cnvHanyuPinyinToPhona(target: String) -> String {
static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String {
if target.contains("_") { return target }
var result = target
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 }) {
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
}
@ -1371,6 +1411,17 @@ public struct Tekkon {
"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] = [
"'": "", ",": "", "-": "", ".": "", "/": "", "0": "", "1": "˙", "2": "ˊ", "3": "ˇ", "4": "ˋ", "7": "",