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) {
51 const char* q = strchr(attrPos,
'"');
52 if (!q || q > tagEnd)
return false;
54 const char* qend = strchr(q,
'"');
55 if (!qend || qend > tagEnd)
return false;
56 size_t vlen = (size_t)(qend - q);
57 size_t copyLen = vlen < (bufSize - 1) ? vlen : (bufSize - 1);
58 if (copyLen > 0) memcpy(outBuf, q, copyLen);
59 outBuf[copyLen] =
'\0';
62 p = strstr(p + 1, tagName);
95 const char* attrName,
int n,
96 char* outBuf,
size_t bufSize) {
97 if (!xml || !tagName || !attrName || n <= 0 || !outBuf || bufSize == 0)
return false;
98 char proto[256] = {0};
100 if (!ok || proto[0] ==
'\0')
return false;
103 const char* tokenStart = proto;
105 for (
size_t i = 0; proto[i] !=
'\0'; ++i) {
106 if (proto[i] ==
':') {
109 tokenStart = proto + i + 1;
115 if (!tokenStart || *tokenStart ==
'\0')
return false;
118 for (; tokenStart[j] !=
'\0' && tokenStart[j] !=
':' && j + 1 < bufSize; ++j) outBuf[j] = tokenStart[j];
120 return outBuf[0] !=
'\0';
Small utility to extract attributes from a start-tag in an XML fragment.
Definition: XMLAttributeParser.h:17
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:94
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:6