mirror of
git://jb55.com/damus
synced 2024-09-18 19:23:49 +00:00
ndb: add cchar constructors to AsciiCharacter
This will be used for the cchar iterator
This commit is contained in:
parent
23b5763a6b
commit
5c1043b4e5
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user