begin work on new registry: api constants & tags

This commit is contained in:
Robin Voetter
2020-06-09 03:02:17 +02:00
parent c2974a16e6
commit 47c9bcb8a3
4 changed files with 243 additions and 13 deletions

View File

@@ -55,24 +55,29 @@ pub const Element = struct {
};
}
pub fn elements(self: *Element) ChildElementIterator {
return .{
.inner = self.children.iterator(0),
};
}
pub fn findChildByTag(self: *Element, tag: []const u8) ?*Element {
return self.findChildrenByTag(tag).next();
}
pub fn findChildrenByTag(self: *Element, tag: []const u8) FindChildrenByTagIterator {
return .{
.inner = self.children.iterator(0),
.inner = self.elements(),
.tag = tag
};
}
pub const FindChildrenByTagIterator = struct {
pub const ChildElementIterator = struct {
inner: ContentList.Iterator,
tag: []const u8,
pub fn next(self: *FindChildrenByTagIterator) ?*Element {
pub fn next(self: *ChildElementIterator) ?*Element {
while (self.inner.next()) |child| {
if (child.* != .Element or !mem.eql(u8, child.*.Element.tag, self.tag)) {
if (child.* != .Element) {
continue;
}
@@ -82,6 +87,23 @@ pub const Element = struct {
return null;
}
};
pub const FindChildrenByTagIterator = struct {
inner: ChildElementIterator,
tag: []const u8,
pub fn next(self: *FindChildrenByTagIterator) ?*Element {
while (self.inner.next()) |child| {
if (!mem.eql(u8, child.tag, self.tag)) {
continue;
}
return child;
}
return null;
}
};
};
pub const XmlDecl = struct {