diff --git a/Source/3rdParty/HotenkaChineseConverter/HotenkaCCBridge.swift b/Source/3rdParty/HotenkaChineseConverter/HotenkaCCBridge.swift index 525a8ece..e9962b6f 100644 --- a/Source/3rdParty/HotenkaChineseConverter/HotenkaCCBridge.swift +++ b/Source/3rdParty/HotenkaChineseConverter/HotenkaCCBridge.swift @@ -27,6 +27,34 @@ import Foundation public class ChineseConverter { public static let shared = HotenkaChineseConverter.init(plistDir: mgrLangModel.getBundleDataPath("convdict")) + /// 漢字數字大寫轉換專用辭典,順序為:康熙、當代繁體中文、日文、簡體中文。 + private static let currencyNumeralDictTable: [String: (String, String, String, String)] = [ + "一": ("壹", "壹", "壹", "壹"), "二": ("貳", "貳", "弐", "贰"), "三": ("叄", "參", "参", "叁"), + "四": ("肆", "肆", "肆", "肆"), "五": ("伍", "伍", "伍", "伍"), "六": ("陸", "陸", "陸", "陆"), + "七": ("柒", "柒", "柒", "柒"), "八": ("捌", "捌", "捌", "捌"), "九": ("玖", "玖", "玖", "玖"), + "十": ("拾", "拾", "拾", "拾"), "百": ("佰", "佰", "佰", "佰"), "千": ("仟", "仟", "仟", "仟"), + "万": ("萬", "萬", "萬", "万"), "〇": ("零", "零", "零", "零"), + ] + + /// 將指定字串內的小寫漢字數字轉換為大寫,會對轉換對象進行直接修改操作。 + /// - Parameter target: 轉換對象。 + public static func ensureCurrencyNumerals(target: inout String) { + if !mgrPrefs.currencyNumeralsEnabled { return } + for key in currencyNumeralDictTable.keys { + guard let result = currencyNumeralDictTable[key] else { continue } + if IME.currentInputMode == InputMode.imeModeCHS { + target = target.replacingOccurrences(of: key, with: result.3) // Simplified Chinese + continue + } + switch (mgrPrefs.chineseConversionEnabled, mgrPrefs.shiftJISShinjitaiOutputEnabled) { + case (false, true), (true, true): target = target.replacingOccurrences(of: key, with: result.2) // JIS + case (true, false): target = target.replacingOccurrences(of: key, with: result.0) // KangXi + default: target = target.replacingOccurrences(of: key, with: result.1) // Contemporary + } + } + return + } + /// CrossConvert. /// /// - Parameter string: Text in Original Script.