git » sdk » commit 1028cd3

Stanza: Add parseXmlBool() helper

author Matthew Wild
2024-12-05 13:25:17 UTC
committer Matthew Wild
2024-12-05 13:27:47 UTC
parent 845bc30d760c79337c09c9bc92f1817601dc0d22

Stanza: Add parseXmlBool() helper

snikket/Stanza.hx +4 -0
test/TestStanza.hx +7 -0

diff --git a/snikket/Stanza.hx b/snikket/Stanza.hx
index b4ef9c7..dcce07d 100644
--- a/snikket/Stanza.hx
+++ b/snikket/Stanza.hx
@@ -350,6 +350,10 @@ class Stanza implements NodeInterface {
 			}
 		});
 	}
+
+	static public function parseXmlBool(x:String) {
+		return x == "true" || x == "1";
+	}
 }
 
 enum IqRequestType {
diff --git a/test/TestStanza.hx b/test/TestStanza.hx
index 210b795..a80d8fa 100644
--- a/test/TestStanza.hx
+++ b/test/TestStanza.hx
@@ -22,4 +22,11 @@ class TestStanza extends utest.Test {
         }
         Assert.equals(2, count);
     }
+
+    public function testParseXmlBool() {
+        Assert.equals(true, Stanza.parseXmlBool("true"));
+        Assert.equals(true, Stanza.parseXmlBool("1"));
+        Assert.equals(false, Stanza.parseXmlBool("false"));
+        Assert.equals(false, Stanza.parseXmlBool("0"));
+    }
 }