8
8
9
9
#include < stdlib.h> /* atof */
10
10
11
+ #include " lldb/Host/Config.h"
11
12
#include " lldb/Host/StringConvert.h"
12
13
#include " lldb/Host/XML.h"
13
14
@@ -21,7 +22,7 @@ XMLDocument::XMLDocument() : m_document(nullptr) {}
21
22
XMLDocument::~XMLDocument () { Clear (); }
22
23
23
24
void XMLDocument::Clear () {
24
- #if defined(LIBXML2_DEFINED )
25
+ #if defined(LLDB_ENABLE_LIBXML2 )
25
26
if (m_document) {
26
27
xmlDocPtr doc = m_document;
27
28
m_document = nullptr ;
@@ -42,7 +43,7 @@ void XMLDocument::ErrorCallback(void *ctx, const char *format, ...) {
42
43
}
43
44
44
45
bool XMLDocument::ParseFile (const char *path) {
45
- #if defined(LIBXML2_DEFINED )
46
+ #if defined(LLDB_ENABLE_LIBXML2 )
46
47
Clear ();
47
48
xmlSetGenericErrorFunc ((void *)this , XMLDocument::ErrorCallback);
48
49
m_document = xmlParseFile (path);
@@ -53,7 +54,7 @@ bool XMLDocument::ParseFile(const char *path) {
53
54
54
55
bool XMLDocument::ParseMemory (const char *xml, size_t xml_length,
55
56
const char *url) {
56
- #if defined(LIBXML2_DEFINED )
57
+ #if defined(LLDB_ENABLE_LIBXML2 )
57
58
Clear ();
58
59
xmlSetGenericErrorFunc ((void *)this , XMLDocument::ErrorCallback);
59
60
m_document = xmlReadMemory (xml, (int )xml_length, url, nullptr , 0 );
@@ -63,7 +64,7 @@ bool XMLDocument::ParseMemory(const char *xml, size_t xml_length,
63
64
}
64
65
65
66
XMLNode XMLDocument::GetRootElement (const char *required_name) {
66
- #if defined(LIBXML2_DEFINED )
67
+ #if defined(LLDB_ENABLE_LIBXML2 )
67
68
if (IsValid ()) {
68
69
XMLNode root_node (xmlDocGetRootElement (m_document));
69
70
if (required_name) {
@@ -81,7 +82,7 @@ XMLNode XMLDocument::GetRootElement(const char *required_name) {
81
82
llvm::StringRef XMLDocument::GetErrors () const { return m_errors.GetString (); }
82
83
83
84
bool XMLDocument::XMLEnabled () {
84
- #if defined(LIBXML2_DEFINED )
85
+ #if defined(LLDB_ENABLE_LIBXML2 )
85
86
return true ;
86
87
#else
87
88
return false ;
@@ -99,7 +100,7 @@ XMLNode::~XMLNode() {}
99
100
void XMLNode::Clear () { m_node = nullptr ; }
100
101
101
102
XMLNode XMLNode::GetParent () const {
102
- #if defined(LIBXML2_DEFINED )
103
+ #if defined(LLDB_ENABLE_LIBXML2 )
103
104
if (IsValid ())
104
105
return XMLNode (m_node->parent );
105
106
else
@@ -110,7 +111,7 @@ XMLNode XMLNode::GetParent() const {
110
111
}
111
112
112
113
XMLNode XMLNode::GetSibling () const {
113
- #if defined(LIBXML2_DEFINED )
114
+ #if defined(LLDB_ENABLE_LIBXML2 )
114
115
if (IsValid ())
115
116
return XMLNode (m_node->next );
116
117
else
@@ -121,7 +122,7 @@ XMLNode XMLNode::GetSibling() const {
121
122
}
122
123
123
124
XMLNode XMLNode::GetChild () const {
124
- #if defined(LIBXML2_DEFINED )
125
+ #if defined(LLDB_ENABLE_LIBXML2 )
125
126
126
127
if (IsValid ())
127
128
return XMLNode (m_node->children );
@@ -135,7 +136,7 @@ XMLNode XMLNode::GetChild() const {
135
136
llvm::StringRef XMLNode::GetAttributeValue (const char *name,
136
137
const char *fail_value) const {
137
138
const char *attr_value = nullptr ;
138
- #if defined(LIBXML2_DEFINED )
139
+ #if defined(LLDB_ENABLE_LIBXML2 )
139
140
140
141
if (IsValid ())
141
142
attr_value = (const char *)xmlGetProp (m_node, (const xmlChar *)name);
@@ -152,7 +153,7 @@ llvm::StringRef XMLNode::GetAttributeValue(const char *name,
152
153
153
154
bool XMLNode::GetAttributeValueAsUnsigned (const char *name, uint64_t &value,
154
155
uint64_t fail_value, int base) const {
155
- #if defined(LIBXML2_DEFINED )
156
+ #if defined(LLDB_ENABLE_LIBXML2 )
156
157
llvm::StringRef str_value = GetAttributeValue (name, " " );
157
158
#else
158
159
llvm::StringRef str_value;
@@ -163,14 +164,14 @@ bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value,
163
164
}
164
165
165
166
void XMLNode::ForEachChildNode (NodeCallback const &callback) const {
166
- #if defined(LIBXML2_DEFINED )
167
+ #if defined(LLDB_ENABLE_LIBXML2 )
167
168
if (IsValid ())
168
169
GetChild ().ForEachSiblingNode (callback);
169
170
#endif
170
171
}
171
172
172
173
void XMLNode::ForEachChildElement (NodeCallback const &callback) const {
173
- #if defined(LIBXML2_DEFINED )
174
+ #if defined(LLDB_ENABLE_LIBXML2 )
174
175
XMLNode child = GetChild ();
175
176
if (child)
176
177
child.ForEachSiblingElement (callback);
@@ -179,15 +180,15 @@ void XMLNode::ForEachChildElement(NodeCallback const &callback) const {
179
180
180
181
void XMLNode::ForEachChildElementWithName (const char *name,
181
182
NodeCallback const &callback) const {
182
- #if defined(LIBXML2_DEFINED )
183
+ #if defined(LLDB_ENABLE_LIBXML2 )
183
184
XMLNode child = GetChild ();
184
185
if (child)
185
186
child.ForEachSiblingElementWithName (name, callback);
186
187
#endif
187
188
}
188
189
189
190
void XMLNode::ForEachAttribute (AttributeCallback const &callback) const {
190
- #if defined(LIBXML2_DEFINED )
191
+ #if defined(LLDB_ENABLE_LIBXML2 )
191
192
192
193
if (IsValid ()) {
193
194
for (xmlAttrPtr attr = m_node->properties ; attr != nullptr ;
@@ -210,7 +211,7 @@ void XMLNode::ForEachAttribute(AttributeCallback const &callback) const {
210
211
}
211
212
212
213
void XMLNode::ForEachSiblingNode (NodeCallback const &callback) const {
213
- #if defined(LIBXML2_DEFINED )
214
+ #if defined(LLDB_ENABLE_LIBXML2 )
214
215
215
216
if (IsValid ()) {
216
217
// iterate through all siblings
@@ -223,7 +224,7 @@ void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const {
223
224
}
224
225
225
226
void XMLNode::ForEachSiblingElement (NodeCallback const &callback) const {
226
- #if defined(LIBXML2_DEFINED )
227
+ #if defined(LLDB_ENABLE_LIBXML2 )
227
228
228
229
if (IsValid ()) {
229
230
// iterate through all siblings
@@ -241,7 +242,7 @@ void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const {
241
242
242
243
void XMLNode::ForEachSiblingElementWithName (
243
244
const char *name, NodeCallback const &callback) const {
244
- #if defined(LIBXML2_DEFINED )
245
+ #if defined(LLDB_ENABLE_LIBXML2 )
245
246
246
247
if (IsValid ()) {
247
248
// iterate through all siblings
@@ -269,7 +270,7 @@ void XMLNode::ForEachSiblingElementWithName(
269
270
}
270
271
271
272
llvm::StringRef XMLNode::GetName () const {
272
- #if defined(LIBXML2_DEFINED )
273
+ #if defined(LLDB_ENABLE_LIBXML2 )
273
274
if (IsValid ()) {
274
275
if (m_node->name )
275
276
return llvm::StringRef ((const char *)m_node->name );
@@ -280,7 +281,7 @@ llvm::StringRef XMLNode::GetName() const {
280
281
281
282
bool XMLNode::GetElementText (std::string &text) const {
282
283
text.clear ();
283
- #if defined(LIBXML2_DEFINED )
284
+ #if defined(LLDB_ENABLE_LIBXML2 )
284
285
if (IsValid ()) {
285
286
bool success = false ;
286
287
if (m_node->type == XML_ELEMENT_NODE) {
@@ -302,7 +303,7 @@ bool XMLNode::GetElementText(std::string &text) const {
302
303
bool XMLNode::GetElementTextAsUnsigned (uint64_t &value, uint64_t fail_value,
303
304
int base) const {
304
305
bool success = false ;
305
- #if defined(LIBXML2_DEFINED )
306
+ #if defined(LLDB_ENABLE_LIBXML2 )
306
307
if (IsValid ()) {
307
308
std::string text;
308
309
if (GetElementText (text))
@@ -316,7 +317,7 @@ bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value,
316
317
317
318
bool XMLNode::GetElementTextAsFloat (double &value, double fail_value) const {
318
319
bool success = false ;
319
- #if defined(LIBXML2_DEFINED )
320
+ #if defined(LLDB_ENABLE_LIBXML2 )
320
321
if (IsValid ()) {
321
322
std::string text;
322
323
if (GetElementText (text)) {
@@ -331,7 +332,7 @@ bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const {
331
332
}
332
333
333
334
bool XMLNode::NameIs (const char *name) const {
334
- #if defined(LIBXML2_DEFINED )
335
+ #if defined(LLDB_ENABLE_LIBXML2 )
335
336
336
337
if (IsValid ()) {
337
338
// In case we are looking for a nullptr name or an exact pointer match
@@ -347,7 +348,7 @@ bool XMLNode::NameIs(const char *name) const {
347
348
XMLNode XMLNode::FindFirstChildElementWithName (const char *name) const {
348
349
XMLNode result_node;
349
350
350
- #if defined(LIBXML2_DEFINED )
351
+ #if defined(LLDB_ENABLE_LIBXML2 )
351
352
ForEachChildElementWithName (
352
353
name, [&result_node](const XMLNode &node) -> bool {
353
354
result_node = node;
@@ -362,15 +363,15 @@ XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const {
362
363
bool XMLNode::IsValid () const { return m_node != nullptr ; }
363
364
364
365
bool XMLNode::IsElement () const {
365
- #if defined(LIBXML2_DEFINED )
366
+ #if defined(LLDB_ENABLE_LIBXML2 )
366
367
if (IsValid ())
367
368
return m_node->type == XML_ELEMENT_NODE;
368
369
#endif
369
370
return false ;
370
371
}
371
372
372
373
XMLNode XMLNode::GetElementForPath (const NamePath &path) {
373
- #if defined(LIBXML2_DEFINED )
374
+ #if defined(LLDB_ENABLE_LIBXML2 )
374
375
375
376
if (IsValid ()) {
376
377
if (path.empty ())
@@ -430,7 +431,7 @@ bool ApplePropertyList::GetValueAsString(const char *key,
430
431
431
432
XMLNode ApplePropertyList::GetValueNode (const char *key) const {
432
433
XMLNode value_node;
433
- #if defined(LIBXML2_DEFINED )
434
+ #if defined(LLDB_ENABLE_LIBXML2 )
434
435
435
436
if (IsValid ()) {
436
437
m_dict_node.ForEachChildElementWithName (
@@ -454,7 +455,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const {
454
455
bool ApplePropertyList::ExtractStringFromValueNode (const XMLNode &node,
455
456
std::string &value) {
456
457
value.clear ();
457
- #if defined(LIBXML2_DEFINED )
458
+ #if defined(LLDB_ENABLE_LIBXML2 )
458
459
if (node.IsValid ()) {
459
460
llvm::StringRef element_name = node.GetName ();
460
461
if (element_name == " true" || element_name == " false" ) {
@@ -470,7 +471,7 @@ bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node,
470
471
return false ;
471
472
}
472
473
473
- #if defined(LIBXML2_DEFINED )
474
+ #if defined(LLDB_ENABLE_LIBXML2 )
474
475
475
476
namespace {
476
477
@@ -532,7 +533,7 @@ StructuredData::ObjectSP CreatePlistValue(XMLNode node) {
532
533
533
534
StructuredData::ObjectSP ApplePropertyList::GetStructuredData () {
534
535
StructuredData::ObjectSP root_sp;
535
- #if defined(LIBXML2_DEFINED )
536
+ #if defined(LLDB_ENABLE_LIBXML2 )
536
537
if (IsValid ()) {
537
538
return CreatePlistValue (m_dict_node);
538
539
}
0 commit comments