IME // Add UniChar.isPrintable()

This commit is contained in:
ShikiSuen 2022-05-18 00:09:06 +08:00
parent f11063fbb0
commit 82707e89b6
1 changed files with 14 additions and 1 deletions

View File

@ -364,7 +364,7 @@ extension String: LocalizedError {
}
}
// MARK: - Ensuring trailing slash of a string:
// MARK: - Ensuring trailing slash of a string
extension String {
mutating func ensureTrailingSlash() {
@ -373,3 +373,16 @@ extension String {
}
}
}
// MARK: - CharCode printability check
// Ref: https://forums.swift.org/t/57085/5
extension UniChar {
public func isPrintable() -> Bool {
guard Unicode.Scalar(UInt32(self)) != nil else {
struct NotAWholeScalar: Error {}
return false
}
return true
}
}