Skip to content

Commit

Permalink
Update XML
Browse files Browse the repository at this point in the history
  • Loading branch information
tong committed Jun 23, 2023
1 parent 1234069 commit 22e7961
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/xmpp/XML.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package xmpp;
import Xml;

@:access(Xml)
@:forward(attributes,children)
@:forward(attributes,children,addChild,removeChild)
abstract XML(Xml) from Xml to Xml {

public var parent(get,never):XML;
Expand Down Expand Up @@ -34,19 +34,17 @@ abstract XML(Xml) from Xml to Xml {
}

public var text(get,set):Text;

function get_text():Text
return switch type {
case XmlType.Element:
var c = this.firstChild();
final c = this.firstChild();
if (c == null) null else c.nodeValue;
default: null;

}
function set_text(v:Text):Text {
switch type {
case XmlType.Element:
var c = this.firstChild();
final c = this.firstChild();
if (c != null)
c.nodeValue = v;
else
Expand All @@ -58,7 +56,7 @@ abstract XML(Xml) from Xml to Xml {

public var elements(get,never):xmpp.XML.NodeIterator;
inline function get_elements():xmpp.XML.NodeIterator {
return this.elements();
return cast this.elements();
//return this.firstChild().elements();
}
// inline function set_elements(elements:xmpp.XML.NodeIterator):xmpp.XML.NodeIterator {
Expand All @@ -81,39 +79,42 @@ abstract XML(Xml) from Xml to Xml {

@:arrayAccess public inline function get(att:String):String
return this.get(att);
@:arrayAccess public inline function set(att:String, ?val:String):XML {
this.set(att, val);

@:arrayAccess public function set(att:String, ?value:String):XML {
if(value==null) return unset(att);
this.set(att, value);
return this;
}

public inline function is(xmlns: String) : Bool
return get('xmlns') == xmlns;

public inline function has(att: String):Bool
return this.exists(att);

//@:op(A==B)
public inline function is(xmlns: String) : Bool
return this.get('xmlns') == xmlns;

public inline function unset(att: String): XML {
this.remove(att);
return this;
}

//@:op(A + B)
public inline function append(e:XML):XML {
this.addChild(e);
return this;
}

public inline function addChild(x:XML):Void
this.addChild(x);

public inline function removeChild(x:XML):Bool
return this.removeChild(x);

public inline function insert(x:XML, pos = 0):XML {
this.insertChild(x, pos);
return this;
}

// public inline function addChild(x:XML):Void
// this.addChild(x);
//
// public inline function removeChild(x:XML):Bool
// return this.removeChild(x);


// @:arrayAccess public inline function getChildAt(i:Int):XML
// return this.children[i];

Expand Down Expand Up @@ -147,13 +148,14 @@ abstract XML(Xml) from Xml to Xml {
}

//@:from
public static inline function parse(s:String):XML {
public static inline function parse(str:String):XML {
//return fromXml(Xml.parse(s).firstElement());
var x : Xml = Xml.parse(s);
//trace(@:privateAccess cast(x.elements(), haxe.iterators.ArrayIterator<Dynamic>).array.length);
var x : Xml = Xml.parse(str);
return new XML(x);
}

/*
macro public static function markup(mu):ExprOf<xmpp.XML> {
return switch mu.expr {
case EMeta({name: ":markup"}, {expr: EConst(CString(s))}):
Expand All @@ -162,11 +164,13 @@ abstract XML(Xml) from Xml to Xml {
throw new haxe.macro.Expr.Error("not an xml literal", mu.pos);
}
}
*/
}

@:noDoc
@:forward(next,hasNext)
private abstract NodeIterator(Iterator<XML>) from Iterator<XML> to Iterator<XML> {
//private abstract NodeIterator(Iterator<XML>) from Iterator<XML> to Iterator<XML> {
private abstract NodeIterator(haxe.iterators.ArrayIterator<XML>) from haxe.iterators.ArrayIterator<XML> to haxe.iterators.ArrayIterator<XML> {

public var length(get,never) : Int;
inline function get_length() : Int
Expand Down

0 comments on commit 22e7961

Please sign in to comment.