From 1028cd3f41c58cab0c53d199ad13df5d6f2e4f2d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 5 Dec 2024 13:25:17 +0000 Subject: [PATCH] Stanza: Add parseXmlBool() helper --- snikket/Stanza.hx | 4 ++++ test/TestStanza.hx | 7 +++++++ 2 files changed, 11 insertions(+) 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")); + } }