42 const char* attrName,
char* outBuf,
44 if (!xml || !tagName || !attrName || !outBuf || bufSize == 0)
return false;
45 const char* p = strstr(xml, tagName);
47 const char* tagEnd = strchr(p,
'>');
48 if (!tagEnd)
return false;
49 const char* attrPos = strstr(p, attrName);
50 if (attrPos && attrPos < tagEnd) {
54 p = strstr(p + 1, tagName);
76 char* outBuf,
size_t bufSize) {
77 if (!attrs || !attrName || !outBuf || bufSize == 0)
return false;
78 const char* attrPos = strstr(attrs, attrName);
79 if (!attrPos)
return false;
88 char* outBuf,
size_t bufSize) {
89 if (!attrPos || !outBuf || bufSize == 0)
return false;
90 memset(outBuf, 0, bufSize);
91 const char* q = strchr(attrPos,
'"');
93 if (boundary && q > boundary)
return false;
95 const char* qend = strchr(q,
'"');
96 if (!qend)
return false;
97 if (boundary && qend > boundary)
return false;
98 size_t vlen = (size_t)(qend - q);
99 size_t copyLen = vlen < (bufSize - 1) ? vlen : (bufSize - 1);
100 if (copyLen > 0) memcpy(outBuf, q, copyLen);
101 outBuf[copyLen] =
'\0';
133 const char* attrName,
int n,
134 char* outBuf,
size_t bufSize) {
135 if (!xml || !tagName || !attrName || n <= 0 || !outBuf || bufSize == 0)
return false;
136 char proto[256] = {0};
138 if (!ok || proto[0] ==
'\0')
return false;
141 const char* tokenStart = proto;
143 for (
size_t i = 0; proto[i] !=
'\0'; ++i) {
144 if (proto[i] ==
':') {
147 tokenStart = proto + i + 1;
153 if (!tokenStart || *tokenStart ==
'\0')
return false;
156 for (; tokenStart[j] !=
'\0' && tokenStart[j] !=
':' && j + 1 < bufSize; ++j) outBuf[j] = tokenStart[j];
158 return outBuf[0] !=
'\0';
Small utility to extract attributes from a start-tag in an XML fragment.
Definition: XMLAttributeParser.h:17
static bool extractQuotedValue(const char *attrPos, const char *boundary, char *outBuf, size_t bufSize)
Definition: XMLAttributeParser.h:87
static bool extractAttribute(const char *attrs, const char *attrName, char *outBuf, size_t bufSize)
Extract an attribute value directly from an attributes string.
Definition: XMLAttributeParser.h:75
static bool extractAttributeToken(const char *xml, const char *tagName, const char *attrName, int n, char *outBuf, size_t bufSize)
Extract the nth (1-based) colon-separated token from an attribute value located on the first occurren...
Definition: XMLAttributeParser.h:132
static bool extractAttribute(const char *xml, const char *tagName, const char *attrName, char *outBuf, size_t bufSize)
Find the first occurrence of a start-tag and extract an attribute value.
Definition: XMLAttributeParser.h:41
Definition: Allocator.h:13