1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

ndb: add cchar constructors to AsciiCharacter

This will be used for the cchar iterator
This commit is contained in:
William Casarin 2023-07-23 11:54:07 -07:00
parent 23b5763a6b
commit 5c1043b4e5

View File

@ -7,13 +7,22 @@
import Foundation
struct AsciiCharacter: ExpressibleByStringLiteral {
struct AsciiCharacter: ExpressibleByStringLiteral, Equatable, Hashable {
private let value: UInt8
var cchar: CChar {
return CChar(bitPattern: value)
}
var string: String {
return String(UnicodeScalar(UInt8(bitPattern: cchar)))
}
init?(_ cchar: CChar) {
guard cchar < 127 else { return nil }
self.value = UInt8(cchar)
}
init?(_ character: Character) {
guard let asciiValue = character.asciiValue, asciiValue < 128 else {
return nil