Tekkon // Nomenclature updates for future purposes.
This commit is contained in:
parent
2664509276
commit
ea725ed329
|
@ -32,7 +32,7 @@ extension vChewingLM {
|
||||||
let arrTarget = target.dropLast().dropFirst().split(separator: ",")
|
let arrTarget = target.dropLast().dropFirst().split(separator: ",")
|
||||||
guard arrTarget.count == 2 else { return target }
|
guard arrTarget.count == 2 else { return target }
|
||||||
var arrTarget0 = String(arrTarget[0]).lowercased()
|
var arrTarget0 = String(arrTarget[0]).lowercased()
|
||||||
arrTarget0.converToPhonabets()
|
arrTarget0.convertToPhonabets()
|
||||||
return "(\(arrTarget0),\(arrTarget[1]))"
|
return "(\(arrTarget0),\(arrTarget[1]))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ extension vChewingLM {
|
||||||
if !neta[0].isEmpty, !neta[1].isEmpty {
|
if !neta[0].isEmpty, !neta[1].isEmpty {
|
||||||
var theKey = shouldReverse ? String(neta[1]) : String(neta[0])
|
var theKey = shouldReverse ? String(neta[1]) : String(neta[0])
|
||||||
let theValue = $0
|
let theValue = $0
|
||||||
theKey.converToPhonabets()
|
theKey.convertToPhonabets()
|
||||||
rangeMap[theKey, default: []].append(theValue)
|
rangeMap[theKey, default: []].append(theValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
public mutating func converToPhonabets(newToneOne: String = "") {
|
public mutating func convertToPhonabets(newToneOne: String = "") {
|
||||||
if isEmpty || contains("_") || !isNotPureAlphanumerical { return }
|
if isEmpty || contains("_") || !isNotPureAlphanumerical { return }
|
||||||
for key in arrHanyuPinyinToPhonabets {
|
for key in arrHanyuPinyinToPhonabets {
|
||||||
self = replacingOccurrences(of: key.0, with: key.1)
|
self = replacingOccurrences(of: key.0, with: key.1)
|
||||||
|
|
|
@ -55,10 +55,10 @@ extension Tekkon {
|
||||||
switch isHanyuPinyin {
|
switch isHanyuPinyin {
|
||||||
case false: // 注音輸出的場合
|
case false: // 注音輸出的場合
|
||||||
let valReturnZhuyin = value.replacingOccurrences(of: " ", with: "")
|
let valReturnZhuyin = value.replacingOccurrences(of: " ", with: "")
|
||||||
return isTextBookStyle ? cnvZhuyinChainToTextbookReading(target: valReturnZhuyin) : valReturnZhuyin
|
return isTextBookStyle ? cnvZhuyinChainToTextbookReading(targetJoined: valReturnZhuyin) : valReturnZhuyin
|
||||||
case true: // 拼音輸出的場合
|
case true: // 拼音輸出的場合
|
||||||
let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(target: value)
|
let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: value)
|
||||||
return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(target: valReturnPinyin) : valReturnPinyin
|
return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: valReturnPinyin) : valReturnPinyin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ extension Tekkon {
|
||||||
|
|
||||||
/// 按需更新拼音組音區的內容顯示。
|
/// 按需更新拼音組音區的內容顯示。
|
||||||
mutating func updateRomajiBuffer() {
|
mutating func updateRomajiBuffer() {
|
||||||
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(target: consonant.value + semivowel.value + vowel.value)
|
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: consonant.value + semivowel.value + vowel.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 接受傳入的按鍵訊號時的處理,處理對象為 String。
|
/// 接受傳入的按鍵訊號時的處理,處理對象為 String。
|
||||||
|
|
|
@ -14,8 +14,8 @@ extension Tekkon {
|
||||||
/// 注音轉拼音,要求陰平必須是空格。
|
/// 注音轉拼音,要求陰平必須是空格。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - target: 傳入的 String 對象物件。
|
/// - target: 傳入的 String 對象物件。
|
||||||
public static func cnvPhonaToHanyuPinyin(target: String) -> String {
|
public static func cnvPhonaToHanyuPinyin(targetJoined: String) -> String {
|
||||||
var targetConverted = target
|
var targetConverted = targetJoined
|
||||||
for pair in arrPhonaToHanyuPinyin {
|
for pair in arrPhonaToHanyuPinyin {
|
||||||
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
|
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ extension Tekkon {
|
||||||
/// 漢語拼音數字標調式轉漢語拼音教科書格式,要求陰平必須是數字 1。
|
/// 漢語拼音數字標調式轉漢語拼音教科書格式,要求陰平必須是數字 1。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - target: 傳入的 String 對象物件。
|
/// - target: 傳入的 String 對象物件。
|
||||||
public static func cnvHanyuPinyinToTextbookStyle(target: String) -> String {
|
public static func cnvHanyuPinyinToTextbookStyle(targetJoined: String) -> String {
|
||||||
var targetConverted = target
|
var targetConverted = targetJoined
|
||||||
for pair in arrHanyuPinyinTextbookStyleConversionTable {
|
for pair in arrHanyuPinyinTextbookStyleConversionTable {
|
||||||
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
|
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ extension Tekkon {
|
||||||
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
|
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
|
||||||
/// - newSeparator: 新的讀音分隔符。
|
/// - newSeparator: 新的讀音分隔符。
|
||||||
/// - Returns: 經過轉換處理的讀音鏈。
|
/// - Returns: 經過轉換處理的讀音鏈。
|
||||||
public static func cnvZhuyinChainToTextbookReading(target: String, newSeparator: String = "-") -> String {
|
public static func cnvZhuyinChainToTextbookReading(targetJoined: String, newSeparator: String = "-") -> String {
|
||||||
var arrReturn: [String] = []
|
var arrReturn: [String] = []
|
||||||
for neta in target.split(separator: "-") {
|
for neta in targetJoined.split(separator: "-") {
|
||||||
var newString = String(neta)
|
var newString = String(neta)
|
||||||
if String(neta.reversed()[0]) == "˙" {
|
if String(neta.reversed()[0]) == "˙" {
|
||||||
newString = String(neta.dropLast())
|
newString = String(neta.dropLast())
|
||||||
|
@ -56,9 +56,9 @@ extension Tekkon {
|
||||||
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
|
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
|
||||||
/// - newSeparator: 新的讀音分隔符。
|
/// - newSeparator: 新的讀音分隔符。
|
||||||
/// - Returns: 經過轉換處理的讀音鏈。
|
/// - Returns: 經過轉換處理的讀音鏈。
|
||||||
public static func restoreToneOneInZhuyinKey(target: String, newSeparator: String = "-") -> String {
|
public static func restoreToneOneInZhuyinKey(targetJoined: String, newSeparator: String = "-") -> String {
|
||||||
var arrReturn: [String] = []
|
var arrReturn: [String] = []
|
||||||
for neta in target.split(separator: "-") {
|
for neta in targetJoined.split(separator: "-") {
|
||||||
var newNeta = String(neta)
|
var newNeta = String(neta)
|
||||||
if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") {
|
if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") {
|
||||||
newNeta += "1"
|
newNeta += "1"
|
||||||
|
@ -73,10 +73,10 @@ extension Tekkon {
|
||||||
/// - target: 要轉換的漢語拼音內容,要求必須帶有 12345 數字標調。
|
/// - target: 要轉換的漢語拼音內容,要求必須帶有 12345 數字標調。
|
||||||
/// - newToneOne: 對陰平指定新的標記。預設情況下該標記為空字串。
|
/// - newToneOne: 對陰平指定新的標記。預設情況下該標記為空字串。
|
||||||
/// - Returns: 轉換結果。
|
/// - Returns: 轉換結果。
|
||||||
public static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String {
|
public static func cnvHanyuPinyinToPhona(targetJoined: String, newToneOne: String = "") -> String {
|
||||||
/// 如果當前內容有任何除了半形英數內容以外的內容的話,就直接放棄轉換。
|
/// 如果當前內容有任何除了半形英數內容以外的內容的話,就直接放棄轉換。
|
||||||
if target.contains("_") || !target.isNotPureAlphanumerical { return target }
|
if targetJoined.contains("_") || !targetJoined.isNotPureAlphanumerical { return targetJoined }
|
||||||
var result = target
|
var result = targetJoined
|
||||||
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
|
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
|
||||||
guard let value = Tekkon.mapHanyuPinyin[key] else { continue }
|
guard let value = Tekkon.mapHanyuPinyin[key] else { continue }
|
||||||
result = result.replacingOccurrences(of: key, with: value)
|
result = result.replacingOccurrences(of: key, with: value)
|
||||||
|
|
|
@ -167,11 +167,11 @@ final class TekkonTestsBasic: XCTestCase {
|
||||||
XCTAssertEqual(composer.getComposition(), "ㄩㄝ")
|
XCTAssertEqual(composer.getComposition(), "ㄩㄝ")
|
||||||
|
|
||||||
// Testing tool functions
|
// Testing tool functions
|
||||||
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(target: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
|
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(targetJoined: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
|
||||||
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(target: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
|
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
|
||||||
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
|
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
|
||||||
// 測試這種情形:「如果傳入的字串不包含任何半形英數內容的話,那麼應該直接將傳入的字串原樣返回」。
|
// 測試這種情形:「如果傳入的字串不包含任何半形英數內容的話,那麼應該直接將傳入的字串原樣返回」。
|
||||||
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
|
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,11 +192,11 @@ extension IMEStateData {
|
||||||
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
|
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
|
||||||
{
|
{
|
||||||
// 恢復陰平標記->注音轉拼音->轉教科書式標調
|
// 恢復陰平標記->注音轉拼音->轉教科書式標調
|
||||||
neta = Tekkon.restoreToneOneInZhuyinKey(target: neta)
|
neta = Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta)
|
||||||
neta = Tekkon.cnvPhonaToHanyuPinyin(target: neta)
|
neta = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: neta)
|
||||||
neta = Tekkon.cnvHanyuPinyinToTextbookStyle(target: neta)
|
neta = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: neta)
|
||||||
} else {
|
} else {
|
||||||
neta = Tekkon.cnvZhuyinChainToTextbookReading(target: neta)
|
neta = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: neta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arrOutput.append(neta)
|
arrOutput.append(neta)
|
||||||
|
|
|
@ -308,9 +308,9 @@ extension InputHandler {
|
||||||
if !prefs.cassetteEnabled {
|
if !prefs.cassetteEnabled {
|
||||||
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
||||||
if !compositor.isEmpty {
|
if !compositor.isEmpty {
|
||||||
displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) // 恢復陰平標記
|
displayedText = Tekkon.restoreToneOneInZhuyinKey(targetJoined: displayedText) // 恢復陰平標記
|
||||||
}
|
}
|
||||||
displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) // 注音轉拼音
|
displayedText = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: displayedText) // 注音轉拼音
|
||||||
}
|
}
|
||||||
if prefs.showHanyuPinyinInCompositionBuffer {
|
if prefs.showHanyuPinyinInCompositionBuffer {
|
||||||
if compositor.isEmpty {
|
if compositor.isEmpty {
|
||||||
|
@ -340,12 +340,12 @@ extension InputHandler {
|
||||||
var key = node.keyArray.joined(separator: "\t")
|
var key = node.keyArray.joined(separator: "\t")
|
||||||
if !prefs.cassetteEnabled {
|
if !prefs.cassetteEnabled {
|
||||||
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
if prefs.inlineDumpPinyinInLieuOfZhuyin {
|
||||||
key = Tekkon.restoreToneOneInZhuyinKey(target: key) // 恢復陰平標記
|
key = Tekkon.restoreToneOneInZhuyinKey(targetJoined: key) // 恢復陰平標記
|
||||||
key = Tekkon.cnvPhonaToHanyuPinyin(target: key) // 注音轉拼音
|
key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) // 注音轉拼音
|
||||||
key = Tekkon.cnvHanyuPinyinToTextbookStyle(target: key) // 轉教科書式標調
|
key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 轉教科書式標調
|
||||||
key = key.replacingOccurrences(of: "\t", with: " ")
|
key = key.replacingOccurrences(of: "\t", with: " ")
|
||||||
} else {
|
} else {
|
||||||
key = Tekkon.cnvZhuyinChainToTextbookReading(target: key, newSeparator: " ")
|
key = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: key, newSeparator: " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ extension SessionCtl {
|
||||||
? theCandidate.0.joined(separator: separator)
|
? theCandidate.0.joined(separator: separator)
|
||||||
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
||||||
? Tekkon.cnvPhonaToHanyuPinyin(
|
? Tekkon.cnvPhonaToHanyuPinyin(
|
||||||
target: Tekkon.restoreToneOneInZhuyinKey(target: theCandidate.0.joined(separator: separator)))
|
targetJoined: Tekkon.restoreToneOneInZhuyinKey(
|
||||||
|
targetJoined: theCandidate.0.joined(separator: separator)))
|
||||||
: theCandidate.0.joined(separator: separator))
|
: theCandidate.0.joined(separator: separator))
|
||||||
result = "\(result)\u{17}(\(reading))"
|
result = "\(result)\u{17}(\(reading))"
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,7 @@ extension SessionCtl {
|
||||||
? neta.0.joined(separator: separator)
|
? neta.0.joined(separator: separator)
|
||||||
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
|
||||||
? Tekkon.cnvPhonaToHanyuPinyin(
|
? Tekkon.cnvPhonaToHanyuPinyin(
|
||||||
target: Tekkon.restoreToneOneInZhuyinKey(target: neta.0.joined(separator: separator)))
|
targetJoined: Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta.0.joined(separator: separator)))
|
||||||
: neta.0.joined(separator: separator))
|
: neta.0.joined(separator: separator))
|
||||||
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
|
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
|
||||||
if candidateString == prefix + netaShownWithPronunciation {
|
if candidateString == prefix + netaShownWithPronunciation {
|
||||||
|
|
Loading…
Reference in New Issue