summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-26 13:55:31 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-26 13:55:31 +0300
commit59f72fa52bd560003af3c4635f92a885d1c07dbc (patch)
treea574aa7c8115bda94252bbd0587cf1158b49e1b3 /src/mir_core
parent1bf0fece31876c453bea93479e6d0d40bd8a564d (diff)
XmlFirstChild / XmlGetAttr - safe wrappers for tinyxml2
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/mir_core.def10
-rw-r--r--src/mir_core/src/mir_core64.def10
-rw-r--r--src/mir_core/src/tinyxml2_utils.cpp89
3 files changed, 109 insertions, 0 deletions
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index 91ca5b7dbd..6039b67290 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1420,3 +1420,13 @@ db_get_utfa @1631
?GetTextU@CCtrlBase@@QAEPADXZ @1633 NONAME
?BytesParsed@XMLDocument@tinyxml2@@QBEHXZ @1634 NONAME
TranslateU_LP @1635
+XmlAddAttr @1636
+XmlAddChild @1637
+XmlAddChildA @1638
+XmlAddChildI @1639
+XmlFirstChild @1640
+XmlGetAttr @1641
+XmlGetChildByTag @1642
+XmlGetChildCount @1643
+XmlGetChildInt @1644
+XmlGetChildText @1645
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 565fd9bedc..2d73dc7d91 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1420,3 +1420,13 @@ db_get_utfa @1631
?GetTextU@CCtrlBase@@QEAAPEADXZ @1633 NONAME
?BytesParsed@XMLDocument@tinyxml2@@QEBAHXZ @1634 NONAME
TranslateU_LP @1635
+XmlAddAttr @1636
+XmlAddChild @1637
+XmlAddChildA @1638
+XmlAddChildI @1639
+XmlFirstChild @1640
+XmlGetAttr @1641
+XmlGetChildByTag @1642
+XmlGetChildCount @1643
+XmlGetChildInt @1644
+XmlGetChildText @1645
diff --git a/src/mir_core/src/tinyxml2_utils.cpp b/src/mir_core/src/tinyxml2_utils.cpp
new file mode 100644
index 0000000000..087e9d0230
--- /dev/null
+++ b/src/mir_core/src/tinyxml2_utils.cpp
@@ -0,0 +1,89 @@
+
+#include "stdafx.h"
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(void) XmlAddAttr(TiXmlElement *hXml, const char *name, const char *value)
+{
+ if (hXml && value)
+ hXml->SetAttribute(name, value);
+}
+
+MIR_CORE_DLL(const char*) XmlGetAttr(const TiXmlElement *hXml, const char *pszName)
+{
+ return (hXml == nullptr) ? nullptr : hXml->Attribute(pszName);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(TiXmlElement*) XmlAddChild(TiXmlElement *hXml, const char *name)
+{
+ if (hXml == nullptr)
+ return nullptr;
+
+ auto *res = hXml->GetDocument()->NewElement(name);
+ hXml->InsertEndChild(res);
+ return res;
+}
+
+MIR_CORE_DLL(TiXmlElement*) XmlAddChildA(TiXmlElement *hXml, const char *name, const char *value)
+{
+ if (hXml == nullptr)
+ return nullptr;
+
+ auto *res = hXml->GetDocument()->NewElement(name);
+ if (value)
+ res->SetText(value);
+ hXml->InsertEndChild(res);
+ return res;
+}
+
+MIR_CORE_DLL(TiXmlElement*) XmlAddChildI(TiXmlElement *hXml, const char *name, int value)
+{
+ if (hXml == nullptr)
+ return nullptr;
+
+ auto *res = hXml->GetDocument()->NewElement(name);
+ if (value)
+ res->SetText(value);
+ hXml->InsertEndChild(res);
+ return res;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(const TiXmlElement*) XmlFirstChild(const TiXmlElement *hXml, const char *key)
+{
+ return (hXml) ? hXml->FirstChildElement(key) : nullptr;
+}
+
+MIR_CORE_DLL(const char*) XmlGetChildText(const TiXmlElement *hXml, const char *key)
+{
+ auto *pChild = XmlFirstChild(hXml, key);
+ return (pChild == nullptr) ? nullptr : pChild->GetText();
+}
+
+MIR_CORE_DLL(int) XmlGetChildInt(const TiXmlElement *hXml, const char *key)
+{
+ auto *pChild = XmlFirstChild(hXml, key);
+ return (pChild == nullptr) ? 0 : atoi(pChild->GetText());
+}
+
+MIR_CORE_DLL(const TiXmlElement*) XmlGetChildByTag(const TiXmlElement *hXml, const char *key, const char *attrName, const char *attrValue)
+{
+ for (auto *pChild : TiXmlFilter(hXml, key))
+ if (pChild->Attribute(attrName, attrValue))
+ return pChild;
+
+ return nullptr;
+}
+
+MIR_CORE_DLL(int) XmlGetChildCount(const TiXmlElement *hXml)
+{
+ int iCount = 0;
+ for (auto *it : TiXmlEnum(hXml)) {
+ UNREFERENCED_PARAMETER(it);
+ iCount++;
+ }
+ return iCount;
+}