Skip to content

Commit

Permalink
Make OpenCCBridge.shared a public static var
Browse files Browse the repository at this point in the history
This avoids a swiftc issue when compiling with `-O`.
  • Loading branch information
lukhnos committed Oct 3, 2023
1 parent ed8f301 commit 6112933
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ import OpenCC
/// Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass
/// in Swift in order to bridge the Swift classes into our Objective-C++ project.
public class OpenCCBridge: NSObject {
private static let shared = OpenCCBridge()

@objc public static let shared = OpenCCBridge()

private var converter: ChineseConverter?

private override init() {
override init() {
try? converter = ChineseConverter(options: .simplify)
super.init()
}

/// Converts to Simplified Chinese.
///
///
/// - Parameter string: Text in Traditional Chinese.
/// - Returns: Text in Simplified Chinese.
@objc public static func convertToSimplified(_ string: String) -> String? {
shared.converter?.convert(string)
@objc public func convertToSimplified(_ string: String) -> String? {
converter?.convert(string)
}
}
2 changes: 1 addition & 1 deletion Source/InputMethodController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ extension McBopomofoInputMethodController {
if Preferences.chineseConversionStyle == 1 {
return text
}
return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.convertToSimplified(text) ?? ""
return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.shared.convertToSimplified(text) ?? ""
}

let buffer = convertToSimplifiedChineseIfRequired(text)
Expand Down
2 changes: 1 addition & 1 deletion Source/LanguageModelManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ + (void)setupDataModelValueConverter
if (Preferences.chineseConversionEngine == 1) {
text = [VXHanConvert convertToSimplifiedFrom:text];
} else {
text = [OpenCCBridge convertToSimplified:text];
text = [[OpenCCBridge shared] convertToSimplified:text];
}
return std::string(text.UTF8String);
};
Expand Down

0 comments on commit 6112933

Please sign in to comment.