MCPcopy Create free account
hub / github.com/arvidn/libtorrent / xml_parse

Function xml_parse

src/xml_parse.cpp:41–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39namespace libtorrent {
40
41 void xml_parse(string_view input
42 , std::function<void(int, string_view, string_view)> callback)
43 {
44 char const* p = input.data();
45 char const* end = input.data() + input.size();
46 for (;p != end; ++p)
47 {
48 char const* start = p;
49 // look for tag start
50 for (; p != end && *p != '<'; ++p);
51
52 if (p != start)
53 {
54 callback(xml_string, {start, std::size_t(p - start)}, {});
55 }
56
57 if (p == end) break;
58
59 // skip '<'
60 ++p;
61 if (p != end && p + 8 < end && string_begins_no_case("![CDATA[", p))
62 {
63 // CDATA. match '![CDATA['
64 p += 8;
65 start = p;
66 while (p != end && !string_begins_no_case("]]>", p - 2)) ++p;
67
68 // parse error
69 if (p == end)
70 {
71 callback(xml_parse_error, "unexpected end of file", {});
72 break;
73 }
74
75 callback(xml_string, {start, std::size_t(p - start - 2)}, {});
76 continue;
77 }
78
79 // parse the name of the tag.
80 for (start = p; p != end && *p != '>' && !is_space(*p); ++p);
81
82 char const* tag_name_end = p;
83
84 // skip the attributes for now
85 for (; p != end && *p != '>'; ++p);
86
87 // parse error
88 if (p == end)
89 {
90 callback(xml_parse_error, "unexpected end of file", {});
91 break;
92 }
93
94 TORRENT_ASSERT(*p == '>');
95
96 char const* tag_end = p;
97 if (*start == '/')
98 {

Callers 7

LLVMFuzzerTestOneInputFunction · 0.85
test_parseFunction · 0.85
TORRENT_TESTFunction · 0.85
on_upnp_xmlMethod · 0.85
on_upnp_map_responseMethod · 0.85

Calls 6

callbackFunction · 0.85
string_begins_no_caseFunction · 0.85
is_spaceFunction · 0.85
minFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45

Tested by 2

test_parseFunction · 0.68
TORRENT_TESTFunction · 0.68