nostrdb: add initial swift integration

This commit is contained in:
William Casarin
2023-07-21 14:54:03 -07:00
parent dc7826c4e5
commit 61051ee853
7 changed files with 289 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
//
// AsciiCharacter.swift
// damus
//
// Created by William Casarin on 2023-07-21.
//
import Foundation
struct AsciiCharacter: ExpressibleByStringLiteral {
private let value: UInt8
var cchar: CChar {
return CChar(bitPattern: value)
}
init?(_ character: Character) {
guard let asciiValue = character.asciiValue, asciiValue < 128 else {
return nil
}
self.value = asciiValue
}
// MARK: - ExpressibleByStringLiteral conformance
init(stringLiteral value: StringLiteralType) {
guard value.count == 1, let character = value.first, let ascii = AsciiCharacter(character) else {
fatalError("Invalid ASCII character initialization.")
}
self = ascii
}
var character: Character {
return Character(UnicodeScalar(value))
}
}