/* Generated file, do not edit */ #ifndef TAGS_H #define TAGS_H #include typedef enum { TAG_UNKNOWN, TAG_TEXT, TAG_A, TAG_ARTICLE, TAG_BODY, TAG_DIV, TAG_FOOTER, TAG_H1, TAG_HEAD, TAG_HEADER, TAG_HTML, TAG_LI, TAG_LINK, TAG_META, TAG_P, TAG_TIME, TAG_TITLE, TAG_UL, } tag_type; static const struct { const char *name; tag_type tag; } tag_map[] = { { "a", TAG_A }, { "article", TAG_ARTICLE }, { "body", TAG_BODY }, { "div", TAG_DIV }, { "footer", TAG_FOOTER }, { "h1", TAG_H1 }, { "head", TAG_HEAD }, { "header", TAG_HEADER }, { "html", TAG_HTML }, { "li", TAG_LI }, { "link", TAG_LINK }, { "meta", TAG_META }, { "p", TAG_P }, { "time", TAG_TIME }, { "title", TAG_TITLE }, { "ul", TAG_UL }, }; static inline tag_type str_to_tag(const char *name, size_t len) { int lo, hi, mid, cmp; lo = 0; hi = 16 - 1; while (lo <= hi) { mid = (lo + hi) / 2; cmp = strncmp(name, tag_map[mid].name, len); if (cmp == 0) { if (tag_map[mid].name[len] == '\0') return tag_map[mid].tag; hi = mid - 1; } else if (cmp < 0) hi = mid - 1; else lo = mid + 1; } return TAG_UNKNOWN; } static inline const char * tag_to_str(tag_type tag) { switch (tag) { case TAG_UNKNOWN: return "unknown"; case TAG_TEXT: return "text"; case TAG_A: return "a"; case TAG_ARTICLE: return "article"; case TAG_BODY: return "body"; case TAG_DIV: return "div"; case TAG_FOOTER: return "footer"; case TAG_H1: return "h1"; case TAG_HEAD: return "head"; case TAG_HEADER: return "header"; case TAG_HTML: return "html"; case TAG_LI: return "li"; case TAG_LINK: return "link"; case TAG_META: return "meta"; case TAG_P: return "p"; case TAG_TIME: return "time"; case TAG_TITLE: return "title"; case TAG_UL: return "ul"; default: return "unknown"; } } #endif /* TAGS_H */