1
0
mirror of git://jb55.com/damus synced 2024-09-18 19:23:49 +00:00
damus/nostrdb/NdbTagIterator.swift

42 lines
839 B
Swift
Raw Normal View History

2023-07-21 21:54:03 +00:00
//
// NdbTagIterators.swift
// damus
//
// Created by William Casarin on 2023-07-21.
//
import Foundation
struct TagSequence: Sequence, IteratorProtocol {
let note: NdbNote
2023-07-21 21:54:03 +00:00
let tag: UnsafeMutablePointer<ndb_tag>
var index: Int32
2023-07-21 21:54:03 +00:00
var count: UInt16 {
tag.pointee.count
}
2023-07-21 21:54:03 +00:00
mutating func next() -> NdbTagElem? {
guard index < tag.pointee.count else { return nil }
let el = NdbTagElem(note: note, tag: tag, index: index)
index += 1
return el
}
subscript(index: Int) -> NdbTagElem? {
if index >= tag.pointee.count {
return nil
}
return NdbTagElem(note: note, tag: tag, index: Int32(index))
}
2023-07-21 21:54:03 +00:00
}
func ndb_maybe_pointee<T>(_ p: UnsafeMutablePointer<T>!) -> T? {
guard p != nil else { return nil }
return p.pointee
}