9#include "lldb/Host/Config.h"
12#include "llvm/ADT/StringExtras.h"
17#pragma mark-- XMLDocument
24#if LLDB_ENABLE_LIBXML2
38 va_start(args, format);
45#if LLDB_ENABLE_LIBXML2
49 xmlSetGenericErrorFunc(
nullptr,
nullptr);
56#if LLDB_ENABLE_LIBXML2
59 m_document = xmlReadMemory(xml, (
int)xml_length, url,
nullptr, 0);
60 xmlSetGenericErrorFunc(
nullptr,
nullptr);
66#if LLDB_ENABLE_LIBXML2
70 llvm::StringRef actual_name = root_node.
GetName();
71 if (actual_name == required_name)
84#if LLDB_ENABLE_LIBXML2
102#if LLDB_ENABLE_LIBXML2
113#if LLDB_ENABLE_LIBXML2
124#if LLDB_ENABLE_LIBXML2
136 const char *fail_value)
const {
137 std::string attr_value;
138#if LLDB_ENABLE_LIBXML2
140 xmlChar *value = xmlGetProp(
m_node, (
const xmlChar *)name);
142 attr_value = (
const char *)value;
147 attr_value = fail_value;
151 attr_value = fail_value;
157 uint64_t fail_value,
int base)
const {
163#if LLDB_ENABLE_LIBXML2
170#if LLDB_ENABLE_LIBXML2
179#if LLDB_ENABLE_LIBXML2
187#if LLDB_ENABLE_LIBXML2
190 for (xmlAttrPtr attr =
m_node->properties; attr !=
nullptr;
195 xmlNodePtr child = attr->children;
196 if (child->type == XML_TEXT_NODE) {
197 llvm::StringRef attr_value;
199 attr_value = llvm::StringRef((
const char *)child->content);
200 if (!callback(llvm::StringRef((
const char *)attr->name), attr_value))
210#if LLDB_ENABLE_LIBXML2
214 for (xmlNodePtr node =
m_node; node; node = node->next) {
223#if LLDB_ENABLE_LIBXML2
227 for (xmlNodePtr node =
m_node; node; node = node->next) {
229 if (node->type != XML_ELEMENT_NODE)
241#if LLDB_ENABLE_LIBXML2
245 for (xmlNodePtr node =
m_node; node; node = node->next) {
247 if (node->type != XML_ELEMENT_NODE)
253 if (strcmp((
const char *)node->name, name) != 0)
269#if LLDB_ENABLE_LIBXML2
272 return llvm::StringRef((
const char *)
m_node->name);
275 return llvm::StringRef();
280#if LLDB_ENABLE_LIBXML2
282 bool success =
false;
283 if (
m_node->type == XML_ELEMENT_NODE) {
285 for (xmlNodePtr node =
m_node->children; node !=
nullptr;
287 if (node->type == XML_TEXT_NODE) {
288 text.append((
const char *)node->content);
304 return GetElementText(text) && llvm::to_integer(text, value, base);
315#if LLDB_ENABLE_LIBXML2
319 if (
m_node->name == (
const xmlChar *)name)
322 return strcmp((
const char *)
m_node->name, name) == 0;
331#if LLDB_ENABLE_LIBXML2
333 name, [&result_node](
const XMLNode &node) ->
bool {
346#if LLDB_ENABLE_LIBXML2
348 return m_node->type == XML_ELEMENT_NODE;
354#if LLDB_ENABLE_LIBXML2
361 const size_t n = path.size();
362 for (
size_t i = 1; node && i < n; ++i)
372#pragma mark-- ApplePropertyList
377 : m_xml_doc(), m_dict_node() {
392 [
this](
const XMLNode &dict) ->
bool {
405 std::string &value)
const {
414#if LLDB_ENABLE_LIBXML2
418 "key", [key, &value_node](
const XMLNode &key_node) ->
bool {
419 std::string key_name;
421 if (key_name == key) {
422 value_node = key_node.GetSibling();
423 while (value_node && !value_node.IsElement())
424 value_node = value_node.GetSibling();
436 std::string &value) {
438#if LLDB_ENABLE_LIBXML2
440 llvm::StringRef element_name = node.
GetName();
441 if (element_name ==
"true" || element_name ==
"false") {
443 value = element_name.str();
445 }
else if (element_name ==
"dict" || element_name ==
"array")
454#if LLDB_ENABLE_LIBXML2
457 llvm::StringRef element_name = node.
GetName();
458 if (element_name ==
"array") {
459 std::shared_ptr<StructuredData::Array> array_sp(
462 array_sp->AddItem(CreatePlistValue(node));
466 }
else if (element_name ==
"dict") {
468 std::shared_ptr<StructuredData::Dictionary> dict_sp(
471 [&key_node, &dict_sp](
const XMLNode &node) ->
bool {
478 std::string key_name;
479 key_node.GetElementText(key_name);
480 dict_sp->AddItem(key_name, CreatePlistValue(node));
488 }
else if (element_name ==
"real") {
492 }
else if (element_name ==
"integer") {
496 }
else if ((element_name ==
"string") || (element_name ==
"data") ||
497 (element_name ==
"date")) {
502 }
else if (element_name ==
"true") {
504 }
else if (element_name ==
"false") {
513#if LLDB_ENABLE_LIBXML2
static bool ExtractStringFromValueNode(const XMLNode &node, std::string &value)
XMLNode GetValueNode(const char *key) const
bool GetValueAsString(const char *key, std::string &value) const
bool ParseFile(const char *path)
StructuredData::ObjectSP GetStructuredData()
llvm::StringRef GetErrors() const
llvm::StringRef GetString() const
size_t size_t PrintfVarArg(const char *format, va_list args)
size_t EOL()
Output and End of Line character to the stream.
std::shared_ptr< Object > ObjectSP
bool ParseFile(const char *path)
llvm::StringRef GetErrors() const
XMLNode GetRootElement(const char *required_name=nullptr)
bool ParseMemory(const char *xml, size_t xml_length, const char *url="untitled.xml")
static void ErrorCallback(void *ctx, const char *format,...)
XMLDocumentImpl m_document
void ForEachChildElement(NodeCallback const &callback) const
llvm::StringRef GetName() const
void ForEachChildNode(NodeCallback const &callback) const
XMLNode GetParent() const
XMLNode GetSibling() const
bool GetElementText(std::string &text) const
std::string GetAttributeValue(const char *name, const char *fail_value=nullptr) const
void ForEachSiblingNode(NodeCallback const &callback) const
XMLNode GetElementForPath(const NamePath &path)
void ForEachSiblingElement(NodeCallback const &callback) const
bool GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value=0, int base=0) const
bool GetAttributeValueAsUnsigned(const char *name, uint64_t &value, uint64_t fail_value=0, int base=0) const
bool NameIs(const char *name) const
void ForEachChildElementWithName(const char *name, NodeCallback const &callback) const
void ForEachSiblingElementWithName(const char *name, NodeCallback const &callback) const
XMLNode FindFirstChildElementWithName(const char *name) const
bool GetElementTextAsFloat(double &value, double fail_value=0.0) const
void ForEachAttribute(AttributeCallback const &callback) const
A class that represents a running process on the host machine.
std::function< bool(const XMLNode &node)> NodeCallback
std::vector< std::string > NamePath
std::function< bool(const llvm::StringRef &name, const llvm::StringRef &value)> AttributeCallback