From 56bc45ce4d07a7a9a415e9dc8ad2f7c3f3c9e48d Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 2 Mar 2017 15:37:32 +0100 Subject: Initial commit --- vala-xmpp/src/core/stanza_attribute.vala | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 vala-xmpp/src/core/stanza_attribute.vala (limited to 'vala-xmpp/src/core/stanza_attribute.vala') diff --git a/vala-xmpp/src/core/stanza_attribute.vala b/vala-xmpp/src/core/stanza_attribute.vala new file mode 100644 index 00000000..3169e90e --- /dev/null +++ b/vala-xmpp/src/core/stanza_attribute.vala @@ -0,0 +1,29 @@ +namespace Xmpp.Core { +public class StanzaAttribute : StanzaEntry { + + public StanzaAttribute() {} + + public StanzaAttribute.build(string ns_uri, string name, string val) { + this.ns_uri = ns_uri; + this.name = name; + this.val = val; + } + + public string to_string() { + if (ns_uri == null) { + return @"$name='$val'"; + } else { + return @"{$ns_uri}:$name='$val'"; + } + } + + public string to_xml(NamespaceState? state_) throws XmlError { + NamespaceState state = state_ ?? new NamespaceState(); + if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) { + return @"$name='$val'"; + } else { + return "%s:%s='%s'".printf (state.find_name (ns_uri), name, val); + } + } +} +} -- cgit v1.2.3-70-g09d2