Tekkon // v1.2.6 update.

This commit is contained in:
ShikiSuen 2022-07-19 19:04:48 +08:00
parent 62e37af456
commit 62ea37d2ec
1 changed files with 41 additions and 10 deletions

View File

@ -221,6 +221,9 @@ public struct Tekkon {
/// Windows / macOS /// Windows / macOS
public var parser: MandarinParser = .ofDachen public var parser: MandarinParser = .ofDachen
///
public var phonabetCombinationCorrectionEnabled = false
/// 調 /// 調
/// 調 /// 調
/// 使.getComposition().value /// 使.getComposition().value
@ -285,7 +288,9 @@ public struct Tekkon {
/// - Parameters: /// - Parameters:
/// - input: String /// - input: String
/// - arrange: 使 /// - arrange: 使
public init(_ input: String = "", arrange parser: MandarinParser = .ofDachen) { /// - correction:
public init(_ input: String = "", arrange parser: MandarinParser = .ofDachen, correction: Bool = false) {
phonabetCombinationCorrectionEnabled = correction
ensureParser(arrange: parser) ensureParser(arrange: parser)
receiveKey(fromString: input) receiveKey(fromString: input)
} }
@ -379,16 +384,25 @@ public struct Tekkon {
/// - Parameters: /// - Parameters:
/// - fromPhonabet: /// - fromPhonabet:
public mutating func receiveKey(fromPhonabet phonabet: String = "") { public mutating func receiveKey(fromPhonabet phonabet: String = "") {
let thePhone: Phonabet = .init(phonabet) var thePhone: Phonabet = .init(phonabet)
if phonabetCombinationCorrectionEnabled {
switch phonabet { switch phonabet {
case "", "":
if vowel.value == "" { vowel = "" }
case "":
if "ㄧㄩ".contains(semivowel.value) { thePhone = "" }
case "", "": case "", "":
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() } if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
if "ㄋㄌ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
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() }
case "", "", "", "": case "", "", "", "":
if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() } if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() }
default: break default: break
} }
}
switch thePhone.type { switch thePhone.type {
case .consonant: consonant = thePhone case .consonant: consonant = thePhone
case .semivowel: semivowel = thePhone case .semivowel: semivowel = thePhone
@ -880,6 +894,23 @@ public struct Tekkon {
return arrReturn.joined(separator: newSeparator) return arrReturn.joined(separator: newSeparator)
} }
///
/// - Parameter target: 12345 調
/// - Returns:
static func cnvHanyuPinyinToPhona(target: String) -> String {
if target.contains("_") { 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 }
result = result.replacingOccurrences(of: key, with: value)
}
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: value)
}
return result
}
/// 調 /// 調
static let arrPhonaToHanyuPinyin = [ // static let arrPhonaToHanyuPinyin = [ //
[" ", "1"], ["ˊ", "2"], ["ˇ", "3"], ["ˋ", "4"], ["˙", "5"], [" ", "1"], ["ˊ", "2"], ["ˇ", "3"], ["ˋ", "4"], ["˙", "5"],