1
0
mirror of git://jb55.com/damus synced 2024-09-18 19:23:49 +00:00
damus/nostrdb/NdbTagElem.swift
William Casarin 58e2fb40ef iter: make safer by using NdbNote instead of unsafe pointers
If we have an owned note, we could lose track of the lifetime and then
crash. Let's make sure we always have an NdbNote instead
2023-07-22 17:19:47 -07:00

30 lines
649 B
Swift

//
// NdbTagElem.swift
// damus
//
// Created by William Casarin on 2023-07-21.
//
import Foundation
struct NdbTagElem {
private let note: NdbNote
private let tag: UnsafeMutablePointer<ndb_tag>
let index: Int32
init(note: NdbNote, tag: UnsafeMutablePointer<ndb_tag>, index: Int32) {
self.note = note
self.tag = tag
self.index = index
}
func matches_char(_ c: AsciiCharacter) -> Bool {
return ndb_tag_matches_char(note.note, tag, index, c.cchar) == 1
}
func string() -> String {
return String(cString: ndb_tag_str(note.note, tag, index), encoding: .utf8) ?? ""
}
}