| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | #include "gate/encode/xml.hpp" | ||
| 29 | #include "gate/exceptions.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace enc | ||
| 34 | { | ||
| 35 | |||
| 36 | 2 | String Xml::encode(String const& plain) | |
| 37 | { | ||
| 38 | gate_string_t encoded; | ||
| 39 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result_t result = gate_xml_encode(plain.c_impl(), &encoded); |
| 40 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 41 | 4 | return String::createFrom(encoded); | |
| 42 | } | ||
| 43 | |||
| 44 | 1 | String Xml::decode(String const& xml) | |
| 45 | { | ||
| 46 | gate_string_t decoded; | ||
| 47 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_xml_decode(xml.c_impl(), &decoded); |
| 48 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 49 | 2 | return String::createFrom(decoded); | |
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | 5 | XmlNode::XmlNode() | |
| 55 | { | ||
| 56 | 5 | gate_mem_clear(&this->impl, sizeof(this->impl)); | |
| 57 | 5 | } | |
| 58 | |||
| 59 | 3 | XmlNode::XmlNode(enumint_t nodeType, String const& tag) | |
| 60 | { | ||
| 61 | 3 | result_t result = gate_xml_node_create(&this->impl, nodeType, tag.c_impl(), NULL, NULL, NULL); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_ERROR(result); |
| 63 | 3 | } | |
| 64 | |||
| 65 | |||
| 66 | 1 | XmlNode::XmlNode(gate_xml_node_t const* node) | |
| 67 | { | ||
| 68 | 1 | result_t result = gate_xml_node_create(&this->impl, node->node_type, &node->tag, | |
| 69 | &node->attributes, &node->child_nodes, &node->content); | ||
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 71 | 1 | } | |
| 72 | |||
| 73 | 1 | XmlNode::XmlNode(XmlNode const& src) | |
| 74 | { | ||
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_xml_node_duplicate(&this->impl, &src.impl)) |
| 76 | { | ||
| 77 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 78 | } | ||
| 79 | 1 | } | |
| 80 | |||
| 81 | 1 | XmlNode& XmlNode::operator=(XmlNode const& src) | |
| 82 | { | ||
| 83 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this != &src) |
| 84 | { | ||
| 85 | gate_xml_node_t new_node; | ||
| 86 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_xml_node_duplicate(&new_node, &src.impl)) |
| 87 | { | ||
| 88 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 89 | } | ||
| 90 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_xml_node_destroy(&this->impl); |
| 91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_mem_copy(&this->impl, &new_node, sizeof(new_node)); |
| 92 | } | ||
| 93 | 1 | return *this; | |
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | 20 | XmlNode::~XmlNode() noexcept | |
| 98 | { | ||
| 99 | 10 | gate_xml_node_destroy(&this->impl); | |
| 100 | 10 | } | |
| 101 | |||
| 102 | 3 | enumint_t XmlNode::getNodeType() const | |
| 103 | { | ||
| 104 | 3 | return this->impl.node_type; | |
| 105 | } | ||
| 106 | |||
| 107 | 3 | String XmlNode::getTag() const | |
| 108 | { | ||
| 109 | 3 | return String::duplicate(this->impl.tag); | |
| 110 | } | ||
| 111 | |||
| 112 | 1 | size_t XmlNode::getAttributeCount() const | |
| 113 | { | ||
| 114 | 1 | return gate_xml_node_attribute_count(&this->impl); | |
| 115 | } | ||
| 116 | |||
| 117 | 1 | String XmlNode::getAttribute(String const& name) const | |
| 118 | { | ||
| 119 | 1 | gate_string_t value = GATE_STRING_INIT_EMPTY; | |
| 120 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_xml_node_attribute_by_name(&this->impl, name.c_impl(), &value); |
| 121 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 122 | 2 | return String::createFrom(value); | |
| 123 | } | ||
| 124 | 1 | String XmlNode::getAttribute(String const& name, String const& altValue) const | |
| 125 | { | ||
| 126 | 1 | gate_string_t value = GATE_STRING_INIT_EMPTY; | |
| 127 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_xml_node_attribute_by_name(&this->impl, name.c_impl(), &value); |
| 128 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_FAILED(result)) |
| 129 | { | ||
| 130 | 1 | return altValue; | |
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | ✗ | return String::createFrom(value); | |
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | 1 | void XmlNode::getAttribute(size_t index, String& name, String& value) const | |
| 140 | { | ||
| 141 | 1 | gate_string_t str_name = GATE_STRING_INIT_EMPTY; | |
| 142 | 1 | gate_string_t str_value = GATE_STRING_INIT_EMPTY; | |
| 143 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_xml_node_attribute_by_index(&this->impl, index, &str_name, &str_value); |
| 144 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 145 | 1 | name = String::createFrom(str_name); | |
| 146 | 1 | value = String::createFrom(str_value); | |
| 147 | 1 | } | |
| 148 | 2 | gate_string_t const* XmlNode::getAttributePtr(String const& name) const | |
| 149 | { | ||
| 150 | 2 | return gate_xml_node_attribute_ptr_by_name(&this->impl, name.c_impl()); | |
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | 3 | size_t XmlNode::getChildrenCount() const | |
| 155 | { | ||
| 156 | 3 | return gate_xml_node_children_count(&this->impl); | |
| 157 | } | ||
| 158 | |||
| 159 | 5 | XmlNode XmlNode::getChild(size_t index) const | |
| 160 | { | ||
| 161 | 5 | XmlNode node; | |
| 162 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | result_t result = gate_xml_node_child(&this->impl, index, &node.impl); |
| 163 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(result); |
| 164 | 5 | return node; | |
| 165 | } | ||
| 166 | |||
| 167 | 2 | String XmlNode::getContent() const | |
| 168 | { | ||
| 169 | 2 | return String::duplicate(this->impl.content); | |
| 170 | } | ||
| 171 | |||
| 172 | 2 | void XmlNode::store(Stream const& storeStream) const | |
| 173 | { | ||
| 174 | 2 | result_t result = gate_xml_node_print(&this->impl, storeStream.c_impl(), 0); | |
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 176 | 2 | } | |
| 177 | |||
| 178 | 2 | String XmlNode::toString() const | |
| 179 | { | ||
| 180 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | StringStream ss; |
| 181 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | this->store(ss); |
| 182 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return ss.toString(); |
| 183 | } | ||
| 184 | |||
| 185 | 3 | gate_xml_node_t const* XmlNode::c_impl() const noexcept | |
| 186 | { | ||
| 187 | 3 | return &this->impl; | |
| 188 | } | ||
| 189 | |||
| 190 | 3 | gate_xml_node_t* XmlNode::c_impl() noexcept | |
| 191 | { | ||
| 192 | 3 | return &this->impl; | |
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | 1 | XmlDoc::XmlDoc() | |
| 199 | { | ||
| 200 | 1 | result_t result = gate_xml_doc_create(&this->impl, NULL); | |
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 202 | 1 | } | |
| 203 | |||
| 204 | 1 | XmlDoc::XmlDoc(XmlNode const& documentElement) | |
| 205 | { | ||
| 206 | 1 | result_t result = gate_xml_doc_create(&this->impl, documentElement.c_impl()); | |
| 207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 208 | 1 | } | |
| 209 | |||
| 210 | 1 | XmlDoc::XmlDoc(Stream& loadStream) | |
| 211 | { | ||
| 212 | 1 | result_t result = gate_xml_doc_load(&this->impl, loadStream.c_impl()); | |
| 213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 214 | 1 | } | |
| 215 | |||
| 216 | 8 | XmlDoc::XmlDoc(String const& loadText) | |
| 217 | { | ||
| 218 | 8 | result_t result = gate_xml_doc_load_text(&this->impl, loadText.c_impl()); | |
| 219 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | GATEXX_CHECK_EXCEPTION(result); |
| 220 | 1 | } | |
| 221 | |||
| 222 | 8 | XmlDoc::~XmlDoc() noexcept | |
| 223 | { | ||
| 224 | 4 | gate_xml_doc_destroy(&this->impl); | |
| 225 | 4 | } | |
| 226 | |||
| 227 | 1 | gate_xml_doc_t* XmlDoc::c_impl() noexcept | |
| 228 | { | ||
| 229 | 1 | return &this->impl; | |
| 230 | } | ||
| 231 | 1 | gate_xml_doc_t const* XmlDoc::c_impl() const noexcept | |
| 232 | { | ||
| 233 | 1 | return &this->impl; | |
| 234 | } | ||
| 235 | |||
| 236 | 1 | void XmlDoc::store(Stream& saveStream, size_t indentSpaces) | |
| 237 | { | ||
| 238 | 1 | result_t result = gate_xml_doc_store(&this->impl, saveStream.c_impl(), indentSpaces); | |
| 239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 240 | 1 | } | |
| 241 | |||
| 242 | 1 | String XmlDoc::toString(size_t indentSpaces) | |
| 243 | { | ||
| 244 | 1 | gate_string_t text = GATE_STRING_INIT_EMPTY; | |
| 245 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_xml_doc_store_text(&this->impl, &text, indentSpaces); |
| 246 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 247 | 2 | return String::createFrom(text); | |
| 248 | } | ||
| 249 | |||
| 250 | 1 | XmlNode XmlDoc::rootElement() | |
| 251 | { | ||
| 252 | 1 | gate_xml_node_t const* ptr_node = NULL; | |
| 253 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_xml_doc_root_element(&this->impl, &ptr_node); |
| 254 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 255 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return XmlNode(ptr_node); |
| 256 | } | ||
| 257 | |||
| 258 | 2 | void XmlDoc::addNode(XmlNode& parentNode, XmlNode const& childNode) | |
| 259 | { | ||
| 260 | 2 | result_t result = gate_xml_doc_add_node(&this->impl, parentNode.c_impl(), childNode.c_impl()); | |
| 261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 262 | 2 | } | |
| 263 | |||
| 264 | ✗ | void XmlDoc::removeNode(XmlNode& node, size_t index) | |
| 265 | { | ||
| 266 | ✗ | result_t result = gate_xml_doc_remove_node(&this->impl, node.c_impl(), index); | |
| 267 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 268 | ✗ | } | |
| 269 | |||
| 270 | ✗ | void XmlDoc::addAttribute(XmlNode& node, String const& name, String const& value) | |
| 271 | { | ||
| 272 | ✗ | result_t result = gate_xml_doc_add_attribute(&this->impl, node.c_impl(), name.c_impl(), value.c_impl()); | |
| 273 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 274 | ✗ | } | |
| 275 | |||
| 276 | ✗ | void XmlDoc::removeAttribute(XmlNode& node, String const& name) | |
| 277 | { | ||
| 278 | ✗ | result_t result = gate_xml_doc_remove_attribute(&this->impl, node.c_impl(), name.c_impl()); | |
| 279 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 280 | ✗ | } | |
| 281 | ✗ | void XmlDoc::setContent(XmlNode& node, String const& content) | |
| 282 | { | ||
| 283 | ✗ | result_t result = gate_xml_doc_set_node_content(&this->impl, node.c_impl(), content.c_impl()); | |
| 284 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 285 | ✗ | } | |
| 286 | |||
| 287 | |||
| 288 | } // end of namespace enc | ||
| 289 | } // end of namespace gate | ||
| 290 |