Skip to content

Commit

Permalink
Update parameter names used in certain converters. (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Dec 8, 2022
1 parent 0088145 commit 1d25db1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 5 additions & 4 deletions Sources/Tekkon/Tekkon_SyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ extension Tekkon {
switch isHanyuPinyin {
case false: // 注音輸出的場合
let valReturnZhuyin = value.replacingOccurrences(of: " ", with: "")
return isTextBookStyle ? cnvZhuyinChainToTextbookReading(target: valReturnZhuyin) : valReturnZhuyin
return isTextBookStyle ? cnvZhuyinChainToTextbookReading(targetJoined: valReturnZhuyin) : valReturnZhuyin
case true: // 拼音輸出的場合
let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(target: value)
return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(target: valReturnPinyin) : valReturnPinyin
let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: value)
return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: valReturnPinyin) : valReturnPinyin
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ extension Tekkon {

/// 按需更新拼音組音區的內容顯示。
mutating func updateRomajiBuffer() {
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(target: consonant.value + semivowel.value + vowel.value)
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: consonant.value + semivowel.value + vowel.value)
}

/// 接受傳入的按鍵訊號時的處理,處理對象為 String。
Expand Down Expand Up @@ -217,6 +217,7 @@ extension Tekkon {
case "":
if "".contains(semivowel.value) { semivowel = "" }
case "", "":
if phonabet == "", semivowel.value == "" { semivowel = "" }
if "ㄅㄆㄇㄈ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
case "":
if "ㄋㄌ".contains(consonant.value), semivowel.value == "" { semivowel.clear() }
Expand Down
22 changes: 11 additions & 11 deletions Sources/Tekkon/Tekkon_Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension Tekkon {
/// 注音轉拼音,要求陰平必須是空格。
/// - Parameters:
/// - target: 傳入的 String 對象物件。
public static func cnvPhonaToHanyuPinyin(target: String) -> String {
var targetConverted = target
public static func cnvPhonaToHanyuPinyin(targetJoined: String) -> String {
var targetConverted = targetJoined
for pair in arrPhonaToHanyuPinyin {
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
}
Expand All @@ -25,8 +25,8 @@ extension Tekkon {
/// 漢語拼音數字標調式轉漢語拼音教科書格式,要求陰平必須是數字 1。
/// - Parameters:
/// - target: 傳入的 String 對象物件。
public static func cnvHanyuPinyinToTextbookStyle(target: String) -> String {
var targetConverted = target
public static func cnvHanyuPinyinToTextbookStyle(targetJoined: String) -> String {
var targetConverted = targetJoined
for pair in arrHanyuPinyinTextbookStyleConversionTable {
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
}
Expand All @@ -38,9 +38,9 @@ extension Tekkon {
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
/// - newSeparator: 新的讀音分隔符。
/// - Returns: 經過轉換處理的讀音鏈。
public static func cnvZhuyinChainToTextbookReading(target: String, newSeparator: String = "-") -> String {
public static func cnvZhuyinChainToTextbookReading(targetJoined: String, newSeparator: String = "-") -> String {
var arrReturn: [String] = []
for neta in target.split(separator: "-") {
for neta in targetJoined.split(separator: "-") {
var newString = String(neta)
if String(neta.reversed()[0]) == "˙" {
newString = String(neta.dropLast())
Expand All @@ -56,9 +56,9 @@ extension Tekkon {
/// - target: 要拿來做轉換處理的讀音鏈,以英文減號來分隔每個讀音。
/// - newSeparator: 新的讀音分隔符。
/// - Returns: 經過轉換處理的讀音鏈。
public static func restoreToneOneInZhuyinKey(target: String, newSeparator: String = "-") -> String {
public static func restoreToneOneInZhuyinKey(targetJoined: String, newSeparator: String = "-") -> String {
var arrReturn: [String] = []
for neta in target.split(separator: "-") {
for neta in targetJoined.split(separator: "-") {
var newNeta = String(neta)
if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") {
newNeta += "1"
Expand All @@ -73,10 +73,10 @@ extension Tekkon {
/// - target: 要轉換的漢語拼音內容,要求必須帶有 12345 數字標調。
/// - newToneOne: 對陰平指定新的標記。預設情況下該標記為空字串。
/// - 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 }
var result = target
if targetJoined.contains("_") || !targetJoined.isNotPureAlphanumerical { return targetJoined }
var result = targetJoined
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
guard let value = Tekkon.mapHanyuPinyin[key] else { continue }
result = result.replacingOccurrences(of: key, with: value)
Expand Down
8 changes: 4 additions & 4 deletions Tests/TekkonTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ final class TekkonTestsBasic: XCTestCase {
XCTAssertEqual(composer.getComposition(), "ㄩㄝ")

// Testing tool functions
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(target: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(target: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(targetJoined: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
// 測試這種情形:「如果傳入的字串不包含任何半形英數內容的話,那麼應該直接將傳入的字串原樣返回」。
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
}
}

Expand Down

0 comments on commit 1d25db1

Please sign in to comment.