Skip to content

Commit

Permalink
Allow specifying converted tone1 in cnvHanyuPinyinToPhona(). (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Jul 22, 2022
1 parent 988ff6b commit 4eb6d89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Sources/Tekkon/TekkonSyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,11 @@ public struct Tekkon {
}

/// 該函式用來將漢語拼音轉為注音。
/// - Parameter target: 要轉換的漢語拼音內容,要求必須帶有 12345 數字標調。
/// - Parameters:
/// - target: 要轉換的漢語拼音內容,要求必須帶有 12345 數字標調。
/// - newToneOne: 對陰平指定新的標記。預設情況下該標記為空字串。
/// - Returns: 轉換結果。
static func cnvHanyuPinyinToPhona(target: String) -> String {
static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String {
if target.contains("_") { return target }
var result = target
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
Expand All @@ -906,7 +908,7 @@ public struct Tekkon {
}
for key in Tekkon.mapArayuruPinyinIntonation.keys.sorted(by: { $0.count > $1.count }) {
guard let value = Tekkon.mapArayuruPinyinIntonation[key] else { continue }
result = result.replacingOccurrences(of: key, with: value)
result = result.replacingOccurrences(of: key, with: (key == "1") ? newToneOne : value)
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/TekkonTests/TekkonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ final class TekkonTests: XCTestCase {
// Testing tool functions
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(target: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(target: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "jing3-gao4"), "ㄐㄧㄥˇ-ㄍㄠˋ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
}

func testHanyuinyinKeyReceivingAndCompositions() throws {
Expand Down

0 comments on commit 4eb6d89

Please sign in to comment.