Skip to content

Commit

Permalink
Ensure type everytime a Phonabet is self-replaced. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored May 18, 2022
1 parent e1d2c33 commit b586faa
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Sources/Tekkon/TekkonSyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,7 @@ public struct Tekkon {
if !input.isEmpty {
if allowedPhonabets.contains(String(input.reversed()[0])) {
valueStorage = String(input.reversed()[0])
if Tekkon.allowedConsonants.contains(value) {
type = .consonant
} else if Tekkon.allowedsemivowels.contains(value) {
type = .semivowel
} else if Tekkon.allowedVowels.contains(value) {
type = .vowel
} else if Tekkon.allowedIntonations.contains(value) {
type = .intonation
} else {
type = .null
valueStorage = ""
}
ensureType()
}
}
}
Expand All @@ -159,6 +148,23 @@ public struct Tekkon {
/// - strWith: 要取代成的內容。
mutating func selfReplace(_ strOf: String, _ strWith: String = "") {
valueStorage = valueStorage.replacingOccurrences(of: strOf, with: strWith)
ensureType()
}

/// 用來自動更新自身的屬性值的函數。
mutating func ensureType() {
if Tekkon.allowedConsonants.contains(value) {
type = .consonant
} else if Tekkon.allowedsemivowels.contains(value) {
type = .semivowel
} else if Tekkon.allowedVowels.contains(value) {
type = .vowel
} else if Tekkon.allowedIntonations.contains(value) {
type = .intonation
} else {
type = .null
valueStorage = ""
}
}

// MARK: - Misc Definitions
Expand Down

0 comments on commit b586faa

Please sign in to comment.