48 Str& attributes,
int start,
int len,
void* ref),
49 bool textOnly =
false) {
79 Str& attributes,
int start,
int len,
void* ref)) {
150 int start,
int len,
void* ref) =
nullptr;
160 int findGt(
const char* s,
int start,
int len) {
162 bool inQuote =
false;
164 for (
int i = start + 1; i < len; ++i) {
166 if (!inQuote && (c ==
'"' || c ==
'\'')) {
169 }
else if (inQuote && c == qchar) {
171 }
else if (!inQuote && c ==
'>') {
185 if (start >= len)
return false;
187 if (next < 0) next = len;
188 for (
int i = start; i < next; ++i) {
189 if (!isspace((
unsigned char)s[i])) {
228 int nameStart = lt + 1;
229 while (nameStart < gt && isspace((
unsigned char)s[nameStart])) nameStart++;
230 int nameEnd = nameStart;
231 while (nameEnd < gt && !isspace((
unsigned char)s[nameEnd]) &&
232 s[nameEnd] !=
'/' && s[nameEnd] !=
'>')
235 if (nameEnd > nameStart) {
238 int contentStart = gt + 1;
242 int attrStart = nameEnd;
246 while (back > lt && isspace((
unsigned char)s[back])) back--;
247 if (back > lt && s[back] ==
'/') attrEnd = back;
249 while (attrStart < attrEnd && isspace((
unsigned char)s[attrStart]))
251 while (attrEnd > attrStart && isspace((
unsigned char)s[attrEnd - 1]))
253 if (attrEnd > attrStart) {
263 if (lt + 4 < len && s[lt + 1] ==
'!' && s[lt + 2] ==
'-' &&
266 return end < 0 ? len :
end + 3;
269 if (lt + 1 < len && s[lt + 1] ==
'?') {
271 return end < 0 ? len :
end + 2;
280 Str& attributes,
int start,
int len) {
284 int ancCount = fullPath.size() > 0 ? (int)fullPath.size() - 1 : 0;
285 for (
int i = 0; i < ancCount; ++i) {
288 ancestorPath.push_back(
Str(fullPath[i].c_str()));
313 while (ts < te && isspace((
unsigned char)s[ts])) ts++;
314 while (te > ts && isspace((
unsigned char)s[te - 1])) te--;
326 int gt =
findGt(s, lt, len);
330 if (lt + 1 < len && s[lt + 1] ==
'/') {
339 bool selfClosing =
false;
341 while (back > lt && isspace((
unsigned char)s[back])) back--;
342 if (back > lt && s[back] ==
'/') selfClosing =
true;
354 if (selfClosing &&
path.size() > 0) {
380 while (ts < te && isspace((
unsigned char)s[ts])) ts++;
381 while (te > ts && isspace((
unsigned char)s[te - 1])) te--;
404 int gt =
findGt(s, lt, len);
408 if (lt + 1 < len && s[lt + 1] ==
'/') {
421 bool selfClosing =
false;
423 while (back > lt && isspace((
unsigned char)s[back])) back--;
424 if (back > lt && s[back] ==
'/') selfClosing =
true;
433 if (selfClosing &&
path.size() > 0) {
445 if (selfClosing &&
path.size() > 0) {
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: StrView.h:18
virtual const char * c_str()
provides the string value as const char*
Definition: StrView.h:376
virtual int indexOf(const char c, int start=0)
Definition: StrView.h:274
virtual int length()
Definition: StrView.h:380
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:44
Heap-backed string utility used throughout tiny_dlna.
Definition: Str.h:27
bool isEmpty() const
True if empty.
Definition: Str.h:54
void copyFrom(const char *source, int len)
Copy from raw buffer with length.
Definition: Str.h:60
void clear()
Clear contents (size -> 0)
Definition: Str.h:93
void release()
Clear and shrink capacity to fit.
Definition: Str.h:161
Lightweight wrapper around std::vector with Arduino-friendly helpers and a pluggable allocator.
Definition: Vector.h:39
void reset()
Reset the container by clearing and shrinking capacity to fit.
Definition: Vector.h:83
iterator erase(size_t index)
Convenience overload to erase by index.
Definition: Vector.h:73
Lightweight streaming XML parser.
Definition: XMLParser.h:27
Str last_attributes
Definition: XMLParser.h:141
int handleCommentOrPI(int lt, const char *s, int len)
Definition: XMLParser.h:261
void do_parse()
Definition: XMLParser.h:300
void setCallback(void(*cb)(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref))
Set the callback to be invoked for parsed fragments.
Definition: XMLParser.h:78
Str txt
Definition: XMLParser.h:138
void setReportTextOnly(bool flag)
report only nodes with text
Definition: XMLParser.h:128
int handleEndTag(const char *s, int lt, int gt)
Definition: XMLParser.h:215
Str node_name
Definition: XMLParser.h:137
Str empty_str
Definition: XMLParser.h:136
int parsePos
Definition: XMLParser.h:460
void(* callback)(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref)
Definition: XMLParser.h:149
XMLParser(const char *xmlStr, void(*callback)(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref), bool textOnly=false)
Construct with XML buffer and callback.
Definition: XMLParser.h:46
void setXml(const char *xmlStr)
Set the XML buffer to parse.
Definition: XMLParser.h:68
void * reference
Definition: XMLParser.h:154
Vector< Str > path
Definition: XMLParser.h:135
void handleStartTag(const char *s, int lt, int gt)
Definition: XMLParser.h:221
StrView str_view
Definition: XMLParser.h:134
Str str
Definition: XMLParser.h:139
void emitTagSegment(const char *s, int lt, int gt)
Definition: XMLParser.h:207
Vector< int > contentStarts
Definition: XMLParser.h:151
void setReference(void *ref)
Attach an opaque user pointer to the parser instance.
Definition: XMLParser.h:60
bool do_parse_single()
Definition: XMLParser.h:366
void end()
Fully reset parser state (parse position, path stack and content starts). Use this when the underlyin...
Definition: XMLParser.h:118
bool report_text_only
Definition: XMLParser.h:142
void parse()
Parse the previously set XML buffer and invoke the callback.
Definition: XMLParser.h:90
int findGt(const char *s, int start, int len)
Definition: XMLParser.h:160
void resetParse()
Reset the internal parse position so subsequent parseSingle() calls start from the beginning of the b...
Definition: XMLParser.h:110
bool parseSingle()
Parse a single fragment (one callback invocation) from the previously set XML buffer.
Definition: XMLParser.h:104
int getParsePos()
Expose current parse position for incremental wrappers.
Definition: XMLParser.h:131
void emitTextSegment(const char *s, int ts, int te)
Definition: XMLParser.h:196
bool invokeCallback(Str &nodeName, Vector< Str > &fullPath, Str &text, Str &attributes, int start, int len)
Definition: XMLParser.h:279
bool hasNonWhitespaceTextAhead(const char *s, int gt, int len)
Definition: XMLParser.h:183
Definition: Allocator.h:13