mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fixes #225 - Use a properly defined user agent
* Set a proper user agent * Add fallback when UA comes out nil * Remove unused Bundle extension * Return nil when asciification fails * Add whitespace handling and further emoji test case * Explicitly check if string is already in ASCII * Rename factory to builder * Use allSatisfy instead of reduce * Use key path syntax
This commit is contained in:
@@ -51,4 +51,22 @@ extension String {
|
||||
}
|
||||
return abs(hash)
|
||||
}
|
||||
|
||||
var isASCII: Bool {
|
||||
allSatisfy(\.isASCII)
|
||||
}
|
||||
|
||||
func asciified() -> String? {
|
||||
guard !isASCII else {
|
||||
return self
|
||||
}
|
||||
guard !canBeConverted(to: .ascii) else {
|
||||
return nil
|
||||
}
|
||||
let mutableString = NSMutableString(string: self)
|
||||
guard CFStringTransform(mutableString, nil, "Any-Latin; Latin-ASCII; [:^ASCII:] Remove" as CFString, false) else {
|
||||
return nil
|
||||
}
|
||||
return mutableString.trimmingCharacters(in: .whitespaces)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user