MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / insert_next_element

Function insert_next_element

native/thirdpart/tinyxml2/tixml2ex.h:571–600  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

569
570
571 inline XMLElement * insert_next_element (XMLElement * sibling, const std::string & name, const attribute_list_t & attributes = {}, const std::string & text = ""s)
572 {
573 if (!sibling)
574 throw XmlException ("null element"s);
575
576 auto parent = sibling -> Parent();
577 if (!parent)
578 throw XmlException ("orphaned element"s);
579
580 XMLElement * element = parent -> GetDocument() -> NewElement (name .c_str());
581 if (!element)
582 throw XmlException ("unable to create element"s);
583
584 auto inserted = parent -> InsertAfterChild (sibling, element) != nullptr;
585 // todo: this block is identical to append_element(), make common code
586 if (inserted)
587 {
588 for (auto const & attr : attributes)
589 element -> SetAttribute (attr .Name() .c_str(), attr .Value() .c_str());
590 if (!text .empty())
591 element -> SetText (text .c_str());
592 return element;
593 }
594 else
595 {
596 parent -> GetDocument() -> DeleteNode (element);
597 throw XmlException ("unable to insert element"s);
598 }
599 // always returns valid XMLElement on success, failures are exceptions
600 }
601 }
602}

Callers

nothing calls this directly

Calls 10

XmlExceptionClass · 0.85
NewElementMethod · 0.80
InsertAfterChildMethod · 0.80
SetAttributeMethod · 0.80
emptyMethod · 0.80
SetTextMethod · 0.80
DeleteNodeMethod · 0.80
c_strMethod · 0.45
NameMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected