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
public var parser: MandarinParser = .ofDachen
///
public var phonabetCombinationCorrectionEnabled = false
/// 調
/// 調
/// 使.getComposition().value
@ -285,7 +288,9 @@ public struct Tekkon {
/// - Parameters:
/// - input: String
/// - 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)
receiveKey(fromString: input)
}
@ -379,15 +384,24 @@ public struct Tekkon {
/// - Parameters:
/// - fromPhonabet:
public mutating func receiveKey(fromPhonabet phonabet: String = "") {
let thePhone: Phonabet = .init(phonabet)
switch phonabet {
case "", "":
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
if "ㄅㄆㄇㄈ".contains(consonant.value), "ㄛㄥ".contains(vowel.value) { vowel.clear() }
case "", "", "", "":
if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() }
default: break
var thePhone: Phonabet = .init(phonabet)
if phonabetCombinationCorrectionEnabled {
switch phonabet {
case "", "":
if vowel.value == "" { vowel = "" }
case "":
if "ㄧㄩ".contains(semivowel.value) { thePhone = "" }
case "", "":
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
if "ㄋㄌ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
if "ㄅㄆㄇㄈ".contains(consonant.value), "ㄛㄥ".contains(vowel.value) { vowel.clear() }
if "ㄋㄌ".contains(consonant.value), "".contains(vowel.value) { vowel.clear() }
case "", "", "", "":
if ["ㄨㄛ", "ㄨㄥ"].contains(semivowel.value + vowel.value) { semivowel.clear() }
default: break
}
}
switch thePhone.type {
case .consonant: consonant = thePhone
@ -880,6 +894,23 @@ public struct Tekkon {
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 = [ //
[" ", "1"], ["ˊ", "2"], ["ˇ", "3"], ["ˋ", "4"], ["˙", "5"],