Skip to content

Commit

Permalink
Fix fundamental mistakes in handling dynamic layouts. (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Apr 12, 2023
1 parent 39ce1be commit ef0102f
Showing 1 changed file with 53 additions and 31 deletions.
84 changes: 53 additions & 31 deletions Sources/Tekkon/Tekkon_SyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ public extension Tekkon {
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: consonant.value + semivowel.value + vowel.value)
}

/// 自我變換單個注音資料值。
/// - Parameters:
/// - strOf: 要取代的內容。
/// - strWith: 要取代成的內容。
mutating func fixValue(_ strOf: String, _ strWith: String = "") {
let theOld = Phonabet(strOf)
if !strOf.isEmpty {
switch theOld.type {
case .consonant where consonant == theOld: consonant.clear()
case .semivowel where semivowel == theOld: semivowel.clear()
case .vowel where vowel == theOld: vowel.clear()
case .intonation where intonation == theOld: intonation.clear()
default: return
}
}
let theNew = Phonabet(strWith)
switch theNew.type {
case .consonant: consonant = theNew
case .semivowel: semivowel = theNew
case .vowel: vowel = theNew
case .intonation: intonation = theNew
case .null: return
}
}

/// 接受傳入的按鍵訊號時的處理,處理對象為 String。
/// 另有同名函式可處理 UniChar 訊號。
///
Expand Down Expand Up @@ -412,9 +437,9 @@ public extension Tekkon {
}
case .vowel:
if semivowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}
default: break
}
Expand Down Expand Up @@ -447,7 +472,7 @@ public extension Tekkon {
} else if consonant.isEmpty, semivowel == "" {
vowel = ""
} else if consonant.isEmpty {
vowel = ""
consonant = ""
} else {
vowel = ""
}
Expand All @@ -460,12 +485,12 @@ public extension Tekkon {
if "dfjk ".contains(key),
!consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty
{
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}

// 後置修正
Expand Down Expand Up @@ -522,24 +547,21 @@ public extension Tekkon {

if "dfjs ".contains(key) {
if !consonant.isEmpty, semivowel.isEmpty, vowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
}
if !consonant.isEmpty, vowel.isEmpty {
consonant.selfReplace("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}
if "ㄢㄣㄤㄥ".contains(vowel.value), semivowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}
if "ㄐㄑㄒ".contains(consonant.value), semivowel.isEmpty {
consonant.selfReplace("", "")
consonant.selfReplace("", "")
consonant.selfReplace("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}
if consonant == "", semivowel.isEmpty, vowel.isEmpty {
consonant.clear()
Expand Down Expand Up @@ -582,13 +604,13 @@ public extension Tekkon {

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("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
fixValue("", "")
}
}

Expand Down

0 comments on commit ef0102f

Please sign in to comment.