#ifndef LY_XML_H_
#define LY_XML_H_
#include <stddef.h>
#include <stdint.h>
#include "log.h"
#include "set.h"
struct ly_ctx;
struct ly_in;
struct ly_out;
#define is_xmlws(c) (c == 0x20 || c == 0x9 || c == 0xa || c == 0xd)
#define is_xmlqnamestartchar(c) ((c >= 'a' && c <= 'z') || c == '_' || \
(c >= 'A' && c <= 'Z') || \
(c >= 0x370 && c <= 0x1fff && c != 0x37e ) || \
(c >= 0xc0 && c <= 0x2ff && c != 0xd7 && c != 0xf7) || c == 0x200c || \
c == 0x200d || (c >= 0x2070 && c <= 0x218f) || \
(c >= 0x2c00 && c <= 0x2fef) || (c >= 0x3001 && c <= 0xd7ff) || \
(c >= 0xf900 && c <= 0xfdcf) || (c >= 0xfdf0 && c <= 0xfffd) || \
(c >= 0x10000 && c <= 0xeffff))
#define is_xmlqnamechar(c) ((c >= 'a' && c <= 'z') || c == '_' || c == '-' || \
(c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || \
c == '.' || c == 0xb7 || (c >= 0x370 && c <= 0x1fff && c != 0x37e ) ||\
(c >= 0xc0 && c <= 0x2ff && c != 0xd7 && c != 0xf7) || c == 0x200c || \
c == 0x200d || (c >= 0x300 && c <= 0x36f) || \
(c >= 0x2070 && c <= 0x218f) || (c >= 0x203f && c <= 0x2040) || \
(c >= 0x2c00 && c <= 0x2fef) || (c >= 0x3001 && c <= 0xd7ff) || \
(c >= 0xf900 && c <= 0xfdcf) || (c >= 0xfdf0 && c <= 0xfffd) || \
(c >= 0x10000 && c <= 0xeffff))
struct lyxml_ns {
char *prefix;
char *uri;
uint32_t depth;
};
struct lyxml_elem {
const char *prefix;
const char *name;
uint32_t prefix_len;
uint32_t name_len;
};
enum LYXML_PARSER_STATUS {
LYXML_ELEMENT,
LYXML_ELEM_CLOSE,
LYXML_ELEM_CONTENT,
LYXML_ATTRIBUTE,
LYXML_ATTR_CONTENT,
LYXML_END
};
struct lyxml_ctx {
const struct ly_ctx *ctx;
struct ly_in *in;
enum LYXML_PARSER_STATUS status;
union {
const char *prefix;
const char *value;
};
union {
uint32_t prefix_len;
uint32_t value_len;
};
union {
const char *name;
ly_bool ws_only;
};
union {
uint32_t name_len;
ly_bool dynamic;
};
struct ly_set elements;
struct ly_set ns;
const char *b_current;
uint64_t b_line;
};
LY_ERR lyxml_ctx_new(const struct ly_ctx *ctx, struct ly_in *in, struct lyxml_ctx **xmlctx);
LY_ERR lyxml_ctx_next(struct lyxml_ctx *xmlctx);
LY_ERR lyxml_ctx_peek(struct lyxml_ctx *xmlctx, enum LYXML_PARSER_STATUS *next);
void lyxml_ns_rm(struct lyxml_ctx *xmlctx);
const struct lyxml_ns *lyxml_ns_get(const struct ly_set *ns_set, const char *prefix, uint32_t prefix_len);
LY_ERR lyxml_dump_text(struct ly_out *out, const char *text, ly_bool attribute);
void lyxml_ctx_free(struct lyxml_ctx *xmlctx);
LY_ERR lyxml_ctx_backup(struct lyxml_ctx *xmlctx, struct lyxml_ctx *backup);
void lyxml_ctx_restore(struct lyxml_ctx *xmlctx, struct lyxml_ctx *backup);
LY_ERR lyxml_value_compare(const struct ly_ctx *ctx1, const char *value1, void *val_prefix_data1,
const struct ly_ctx *ctx2, const char *value2, void *val_prefix_data2);
#endif