* details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with this file; if not, see http://www.gnu.org/licenses/.
+ * along with this file; if not, see https://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
(c >= '0' && c <= '9') || c == '-' || c == '.';
}
+/* Allow characters used in element "paths"; see do_xml_path_walk() */
+static inline bool
+is_path_char(tchar c)
+{
+ return c == '/' || c == '[' || c == ']';
+}
+
bool
-xml_legal_name(const tchar *p)
+xml_legal_path(const tchar *p)
{
- if (!is_name_start_char(*p))
+ if (!is_name_start_char(*p) && !is_path_char(*p))
return false;
for (p = p + 1; *p; p++) {
- if (!is_name_char(*p))
+ if (!is_name_char(*p) && !is_path_char(*p))
return false;
}
return true;
xml_legal_value(const tchar *p)
{
for (; *p; p++) {
- if (*p < 0x20 && !is_whitespace(*p))
+ /* Careful: tchar can be signed. */
+ if (*p > 0 && *p < 0x20 && !is_whitespace(*p))
return false;
}
return true;
CHECK(*p == '<');
p++;
name_start = p;
- while (!is_whitespace(*p) && *p != '>' && *p != '\0')
+ while (!is_whitespace(*p) && *p != '>' && *p != '/' && *p != '\0')
p++;
name_len = p - name_start;
CHECK(name_len > 0);
xml_write(struct xml_out_buf *buf, const tchar *str, size_t len)
{
if (buf->count + len + 1 > buf->capacity) {
- size_t new_capacity = max(buf->capacity * 2, 4096);
+ size_t new_capacity = max3(buf->count + len + 1,
+ buf->capacity * 2, 4096);
tchar *new_buf = REALLOC(buf->buf,
new_capacity * sizeof(str[0]));
if (!new_buf) {