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;
159 int findGt(
const char* s,
int start,
int len) {
161 bool inQuote =
false;
163 for (
int i = start + 1; i < len; ++i) {
165 if (!inQuote && (c ==
'"' || c ==
'\'')) {
168 }
else if (inQuote && c == qchar) {
170 }
else if (!inQuote && c ==
'>') {
210 int nameStart = lt + 1;
211 while (nameStart < gt && isspace((
unsigned char)s[nameStart])) nameStart++;
212 int nameEnd = nameStart;
213 while (nameEnd < gt && !isspace((
unsigned char)s[nameEnd]) &&
214 s[nameEnd] !=
'/' && s[nameEnd] !=
'>')
217 if (nameEnd > nameStart) {
220 int contentStart = gt + 1;
224 int attrStart = nameEnd;
228 while (back > lt && isspace((
unsigned char)s[back])) back--;
229 if (back > lt && s[back] ==
'/') attrEnd = back;
231 while (attrStart < attrEnd && isspace((
unsigned char)s[attrStart]))
233 while (attrEnd > attrStart && isspace((
unsigned char)s[attrEnd - 1]))
235 if (attrEnd > attrStart) {
245 if (lt + 4 < len && s[lt + 1] ==
'!' && s[lt + 2] ==
'-' &&
248 return end < 0 ? len : end + 3;
251 if (lt + 1 < len && s[lt + 1] ==
'?') {
253 return end < 0 ? len : end + 2;
262 Str& attributes,
int start,
int len) {
266 int ancCount = fullPath.
size() > 0 ? (int)fullPath.
size() - 1 : 0;
267 for (
int i = 0; i < ancCount; ++i) {
295 while (ts < te && isspace((
unsigned char)s[ts])) ts++;
296 while (te > ts && isspace((
unsigned char)s[te - 1])) te--;
308 int gt =
findGt(s, lt, len);
312 if (lt + 1 < len && s[lt + 1] ==
'/') {
324 bool selfClosing =
false;
326 while (back > lt && isspace((
unsigned char)s[back])) back--;
327 if (back > lt && s[back] ==
'/') selfClosing =
true;
331 if (selfClosing &&
path.size() > 0) {
357 while (ts < te && isspace((
unsigned char)s[ts])) ts++;
358 while (te > ts && isspace((
unsigned char)s[te - 1])) te--;
381 int gt =
findGt(s, lt, len);
385 if (lt + 1 < len && s[lt + 1] ==
'/') {
403 bool selfClosing =
false;
405 while (back > lt && isspace((
unsigned char)s[back])) back--;
406 if (back > lt && s[back] ==
'/') selfClosing =
true;
408 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:19
virtual bool isEmpty()
checks if the string is empty
Definition: StrView.h:383
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:275
virtual int length()
Definition: StrView.h:380
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:45
String implementation which keeps the data on the heap. We grow the allocated memory only if the copy...
Definition: Str.h:22
void clear() override
clears the string by setting the terminating 0 at the beginning
Definition: Str.h:163
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: Str.h:93
Vector implementation which provides the most important methods as defined by std::vector....
Definition: Vector.h:21
bool resize(int newSize, T value)
Definition: Vector.h:251
int size()
Definition: Vector.h:167
void push_back(T &&value)
Definition: Vector.h:171
void erase(Iterator it)
Definition: Vector.h:279
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:243
void do_parse()
Definition: XMLParser.h:282
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:197
Str node_name
Definition: XMLParser.h:137
Str empty_str
Definition: XMLParser.h:136
int parsePos
Definition: XMLParser.h:427
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 resetParser()
Fully reset parser state (parse position, path stack and content starts). Use this when the underlyin...
Definition: XMLParser.h:118
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:203
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:189
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:343
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:159
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:178
bool invokeCallback(Str &nodeName, Vector< Str > &fullPath, Str &text, Str &attributes, int start, int len)
Definition: XMLParser.h:261
Definition: Allocator.h:6