| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-03 18:14:07 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-04 03:11:54 UTC |
| parent | 5ff4adee330e08e05441083328eed7e79727fd24 |
| borogove/DataForm.hx | +2 | -1 |
| borogove/Html.hx | +2 | -2 |
| borogove/Stanza.hx | +12 | -17 |
diff --git a/borogove/DataForm.hx b/borogove/DataForm.hx index 9f9872f..a411611 100644 --- a/borogove/DataForm.hx +++ b/borogove/DataForm.hx @@ -102,7 +102,8 @@ abstract Field(Stanza) from Stanza to Stanza { } inline public function set_type(newType: String) { - return this.attr.set("type", newType); + this.attr.set("type", newType); + return newType; } public function get_datatype() { diff --git a/borogove/Html.hx b/borogove/Html.hx index 668c95d..432c9e5 100644 --- a/borogove/Html.hx +++ b/borogove/Html.hx @@ -146,7 +146,7 @@ class Html { final attrs = st.attr.keys(); if (["div", "span", "p", "br"].contains(st.name)) { - return attrs.length < 1 && !kids.exists(plain -> !plain); + return !attrs.hasNext() && !kids.exists(plain -> !plain); } return false; @@ -180,7 +180,7 @@ class Html { // We don't deeply sanitize but we can remove some obvious dumb stuff if (st.name == "style" || st.name == "script") return mkTxt(""); - final keys = st.attr.keys().filter(k -> !k.startsWith("on")); + final keys = { iterator: () -> st.attr.keys() }.array().filter(k -> !k.startsWith("on")); return f( st.name, keys, diff --git a/borogove/Stanza.hx b/borogove/Stanza.hx index 44f1953..5e6b2d7 100644 --- a/borogove/Stanza.hx +++ b/borogove/Stanza.hx @@ -3,9 +3,7 @@ package borogove; import haxe.DynamicAccess; import haxe.Exception; import haxe.ds.StringMap; -#if (!cpp && !js) import Xml; -#end enum Node { Element(stanza:Stanza); @@ -64,9 +62,10 @@ class StanzaError { } @:expose +@:access(Xml) class Stanza { public final name:String = null; - public final attr:DynamicAccess<String> = {}; + public final attr:haxe.ds.StringMap<String>; public var children(default, null):Array<Node> = []; private var last_added(null, null):Stanza; private var last_added_stack(null, null):Array<Stanza> = []; @@ -74,11 +73,13 @@ class Stanza { public function new(name:String, ?attr:DynamicAccess<String>, ?attrMap:haxe.ds.StringMap<String>) { this.name = name; - if(attr != null) { - this.attr = attr; - } if (attrMap != null) { - for (k => v in attrMap) this.attr.set(k, v); + this.attr = attrMap; + } else { + this.attr = new haxe.ds.StringMap(); + } + if(attr != null) { + for (k => v in attr) this.attr.set(k, v); } this.last_added = this; }; @@ -88,7 +89,7 @@ class Stanza { #if cpp return (serialized = borogove.streams.XmppStropheStream.serializeStanza(this)); - #elseif js + #elseif false final el = borogove.streams.XmppJsStream.convertFromStanza(this); return (serialized = el.toString()); #else @@ -133,18 +134,13 @@ class Stanza { return stanza; } - #if (!cpp && !js) @:allow(borogove) private static function fromXml(el:Xml):Stanza { if(el.nodeType == XmlType.Document) { return fromXml(el.firstElement()); } - var attrs: DynamicAccess<String> = {}; - for (a in el.attributes()) { - attrs.set(a, el.get(a)); - } - var stanza = new Stanza(el.nodeName, attrs); + var stanza = new Stanza(el.nodeName, el.attributeMap); for (child in el) { if(child.nodeType == XmlType.Element) { stanza.addChild(fromXml(child)); @@ -156,7 +152,6 @@ class Stanza { } return stanza; } - #end public function tag(name:String, ?attr:DynamicAccess<String>, ?attrMap:haxe.ds.StringMap<String>) { serialized = null; @@ -173,9 +168,9 @@ class Stanza { return this; } - public function textTag(tagName:String, textContent:String, ?attr:DynamicAccess<String>) { + public function textTag(tagName:String, textContent:String, ?attr:DynamicAccess<String>, ?attrMap:haxe.ds.StringMap<String>) { serialized = null; - this.last_added.addDirectChild(Element(new Stanza(tagName, attr ?? {}).text(textContent))); + this.last_added.addDirectChild(Element(new Stanza(tagName, attr, attrMap).text(textContent))); return this; }