2023-07-21 21:54:03 +00:00
|
|
|
//
|
|
|
|
// NdbTagIterators.swift
|
|
|
|
// damus
|
|
|
|
//
|
|
|
|
// Created by William Casarin on 2023-07-21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2023-07-23 04:12:53 +00:00
|
|
|
struct TagSequence: Sequence, IteratorProtocol {
|
2023-07-22 23:56:13 +00:00
|
|
|
let note: NdbNote
|
2023-07-21 21:54:03 +00:00
|
|
|
let tag: UnsafeMutablePointer<ndb_tag>
|
2023-07-23 04:12:53 +00:00
|
|
|
var index: Int32
|
2023-07-21 21:54:03 +00:00
|
|
|
|
2023-07-22 23:56:13 +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
|
|
|
|
}
|
|
|
|
|
2023-07-22 23:58:17 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|