Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure type everytime a Phonabet is self-replaced. #20

Merged
merged 1 commit into from
May 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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