From ee8b8d90132a41c56c74e1186bc5fa7726fb5ac6 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 22 Oct 2022 13:35:07 +0800 Subject: [PATCH] Repo // Merge certain Swift extensions. --- .../LangModelAssembly/LMConsolidator.swift | 17 ----------------- .../LMInstantiator_DateTimeExtension.swift | 17 ----------------- .../Sources/SwiftExtension/SwiftExtension.swift | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMConsolidator.swift b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMConsolidator.swift index 2e90306b..6f1f44d8 100644 --- a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMConsolidator.swift +++ b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMConsolidator.swift @@ -145,20 +145,3 @@ extension vChewingLM { } } } - -// MARK: - String Extension - -extension String { - fileprivate mutating func regReplace(pattern: String, replaceWith: String = "") { - // Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914 - do { - let regex = try NSRegularExpression( - pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines] - ) - let range = NSRange(startIndex..., in: self) - self = regex.stringByReplacingMatches( - in: self, options: [], range: range, withTemplate: replaceWith - ) - } catch { return } - } -} diff --git a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator_DateTimeExtension.swift b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator_DateTimeExtension.swift index 2b5e5d48..87c62e9d 100644 --- a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator_DateTimeExtension.swift +++ b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator_DateTimeExtension.swift @@ -77,23 +77,6 @@ extension vChewingLM.LMInstantiator { } } -// MARK: - String Extension - -extension String { - fileprivate mutating func regReplace(pattern: String, replaceWith: String = "") { - // Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914 - do { - let regex = try NSRegularExpression( - pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines] - ) - let range = NSRange(startIndex..., in: self) - self = regex.stringByReplacingMatches( - in: self, options: [], range: range, withTemplate: replaceWith - ) - } catch { return } - } -} - // MARK: - Date Time Language Conversion Extension private let tableMappingArabicNumeralsToChinese: [String: String] = [ diff --git a/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftExtension.swift b/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftExtension.swift index 97edb83a..98843b46 100644 --- a/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftExtension.swift +++ b/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftExtension.swift @@ -135,3 +135,20 @@ public struct AppProperty { } } } + +// MARK: - String Extension + +extension String { + public mutating func regReplace(pattern: String, replaceWith: String = "") { + // Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914 + do { + let regex = try NSRegularExpression( + pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines] + ) + let range = NSRange(startIndex..., in: self) + self = regex.stringByReplacingMatches( + in: self, options: [], range: range, withTemplate: replaceWith + ) + } catch { return } + } +}