Skip to content

Commit

Permalink
Add Chase parser. (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Apr 23, 2023
1 parent ef0102f commit 7cd45ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/Tekkon/Tekkon_Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ public enum Tekkon {

// MARK: - Maps for Keyboard-to-Phonabet parsers

/// 追音排列專用處理陣列,但未包含全部的處理內容。
///
/// 在這裡將要用到的按鍵寫全,也只是為了方便做 validity check。
/// 這裡提前對複音按鍵做處理,然後再用程式判斷介母類型、據此判斷是否需要做複音切換。
static let mapChaseStaticKeys: [String: String] = [
"q": "", "a": "", "z": "", "w": "", "s": "", "x": "", "e": "",
"d": "", "c": "", "r": "˙", "f": "ˊ", "v": "ˇ", "t": "", "g": "",
"b": "", "y": "", "h": "", "n": "", "u": "", "j": "", "m": "",
"i": "", "k": "", ",": "", "o": "", "l": "", ".": "", "p": "",
";": "", "/": "", " ": "ˋ",
]

/// 標準大千排列專用處理陣列。
///
/// 威注音輸入法 macOS 版使用了 Ukelele 佈局來完成對諸如倚天傳統等其它注音鍵盤排列的支援。
Expand Down Expand Up @@ -617,4 +629,7 @@ public enum Tekkon {
"h": "", "i": "", "j": "", "k": "", "l": "", "m": "", "n": "", "o": "", "p": "", "q": "", "r": "",
"s": "", "t": "", "u": "", "v": "", "w": "", "x": "", "y": "", "z": "", " ": " ",
]

/// 追音排列專用處理陣列。
static let mapChase: [String: String] = [:]
}
3 changes: 3 additions & 0 deletions Sources/Tekkon/Tekkon_Phonabets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public extension Tekkon {

/// 定義注音排列的類型
enum MandarinParser: Int {
case ofChase = -1
case ofDachen = 0
case ofDachen26 = 1
case ofETen = 2
Expand All @@ -41,6 +42,8 @@ public extension Tekkon {

var name: String {
switch self {
case .ofChase:
return "Chase"
case .ofDachen:
return "Dachen"
case .ofDachen26:
Expand Down
6 changes: 6 additions & 0 deletions Sources/Tekkon/Tekkon_SyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public extension Tekkon {
/// 拼音組音區。
public var romajiBuffer: String = ""

/// 追音組音區。
public var chaseBuffer: String = ""

/// 注音排列種類。預設情況下是大千排列(Windows / macOS 預設注音排列)。
public var parser: MandarinParser = .ofDachen

Expand Down Expand Up @@ -131,6 +134,8 @@ public extension Tekkon {
if let scalar = UnicodeScalar(inputKey) {
let input = String(scalar)
switch parser {
case .ofChase:
return Tekkon.mapChaseStaticKeys[input] != nil
case .ofDachen:
return Tekkon.mapQwertyDachen[input] != nil
case .ofDachen26:
Expand Down Expand Up @@ -372,6 +377,7 @@ public extension Tekkon {
/// - key: 傳入的 String 訊號。
public mutating func translate(key: String = "") -> String {
switch parser {
case .ofChase: break // 追音單獨用另外的函式處理
case .ofDachen:
return Tekkon.mapQwertyDachen[key] ?? ""
case .ofDachen26:
Expand Down

0 comments on commit 7cd45ea

Please sign in to comment.