CCBridge // +ensureCurrencyNumerals().

This commit is contained in:
ShikiSuen 2022-07-26 21:13:50 +08:00
parent 0f086b7dba
commit 78faf46771
1 changed files with 28 additions and 0 deletions

View File

@ -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.