commit 5c1043b4e5f853f797947107cea2c5154654f544 parent 23b5763a6b705540ad22d09aa57a311f39bbf4b6 Author: William Casarin <jb55@jb55.com> Date: Sun, 23 Jul 2023 11:54:07 -0700 ndb: add cchar constructors to AsciiCharacter This will be used for the cchar iterator Diffstat:
M | nostrdb/AsciiCharacter.swift | | | 11 | ++++++++++- |
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/nostrdb/AsciiCharacter.swift b/nostrdb/AsciiCharacter.swift @@ -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