Repo // Merge certain Swift extensions.
This commit is contained in:
parent
d2d8d4ab58
commit
ee8b8d9013
|
@ -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 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
// MARK: - Date Time Language Conversion Extension
|
||||||
|
|
||||||
private let tableMappingArabicNumeralsToChinese: [String: String] = [
|
private let tableMappingArabicNumeralsToChinese: [String: String] = [
|
||||||
|
|
|
@ -135,3 +135,20 @@ public struct AppProperty<Value> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue