Build tag map with a static method instead of an initializer list

This commit is contained in:
Max Brunsfeld 2018-06-15 15:34:56 -07:00
parent 8e6d71bd54
commit 2a3ef3b7b1
1 changed files with 134 additions and 127 deletions

261
src/tag.h
View File

@ -136,133 +136,140 @@ enum TagType {
CUSTOM, CUSTOM,
}; };
static const unordered_map<string, TagType> TAG_TYPES_BY_TAG_NAME = {
{"AREA", AREA}, static const unordered_map<string, TagType> get_tag_map() {
{"BASE", BASE}, unordered_map<string, TagType> result;
{"BASEFONT", BASEFONT}, #define TAG(name) result[#name] = name
{"BGSOUND", BGSOUND}, TAG(AREA);
{"BR", BR}, TAG(BASE);
{"COL", COL}, TAG(BASEFONT);
{"COMMAND", COMMAND}, TAG(BGSOUND);
{"EMBED", EMBED}, TAG(BR);
{"FRAME", FRAME}, TAG(COL);
{"HR", HR}, TAG(COMMAND);
{"IMAGE", IMAGE}, TAG(EMBED);
{"IMG", IMG}, TAG(FRAME);
{"INPUT", INPUT}, TAG(HR);
{"ISINDEX", ISINDEX}, TAG(IMAGE);
{"KEYGEN", KEYGEN}, TAG(IMG);
{"LINK", LINK}, TAG(INPUT);
{"MENUITEM", MENUITEM}, TAG(ISINDEX);
{"META", META}, TAG(KEYGEN);
{"NEXTID", NEXTID}, TAG(LINK);
{"PARAM", PARAM}, TAG(MENUITEM);
{"SOURCE", SOURCE}, TAG(META);
{"TRACK", TRACK}, TAG(NEXTID);
{"WBR", WBR}, TAG(PARAM);
{"A", A}, TAG(SOURCE);
{"ABBR", ABBR}, TAG(TRACK);
{"ADDRESS", ADDRESS}, TAG(WBR);
{"ARTICLE", ARTICLE}, TAG(A);
{"ASIDE", ASIDE}, TAG(ABBR);
{"AUDIO", AUDIO}, TAG(ADDRESS);
{"B", B}, TAG(ARTICLE);
{"BDI", BDI}, TAG(ASIDE);
{"BDO", BDO}, TAG(AUDIO);
{"BLOCKQUOTE", BLOCKQUOTE}, TAG(B);
{"BODY", BODY}, TAG(BDI);
{"BUTTON", BUTTON}, TAG(BDO);
{"CANVAS", CANVAS}, TAG(BLOCKQUOTE);
{"CAPTION", CAPTION}, TAG(BODY);
{"CITE", CITE}, TAG(BUTTON);
{"CODE", CODE}, TAG(CANVAS);
{"COLGROUP", COLGROUP}, TAG(CAPTION);
{"DATA", DATA}, TAG(CITE);
{"DATALIST", DATALIST}, TAG(CODE);
{"DD", DD}, TAG(COLGROUP);
{"DEL", DEL}, TAG(DATA);
{"DETAILS", DETAILS}, TAG(DATALIST);
{"DFN", DFN}, TAG(DD);
{"DIALOG", DIALOG}, TAG(DEL);
{"DIV", DIV}, TAG(DETAILS);
{"DL", DL}, TAG(DFN);
{"DT", DT}, TAG(DIALOG);
{"EM", EM}, TAG(DIV);
{"FIELDSET", FIELDSET}, TAG(DL);
{"FIGCAPTION", FIGCAPTION}, TAG(DT);
{"FIGURE", FIGURE}, TAG(EM);
{"FOOTER", FOOTER}, TAG(FIELDSET);
{"FORM", FORM}, TAG(FIGCAPTION);
{"H1", H1}, TAG(FIGURE);
{"H2", H2}, TAG(FOOTER);
{"H3", H3}, TAG(FORM);
{"H4", H4}, TAG(H1);
{"H5", H5}, TAG(H2);
{"H6", H6}, TAG(H3);
{"HEAD", HEAD}, TAG(H4);
{"HEADER", HEADER}, TAG(H5);
{"HGROUP", HGROUP}, TAG(H6);
{"HTML", HTML}, TAG(HEAD);
{"I", I}, TAG(HEADER);
{"IFRAME", IFRAME}, TAG(HGROUP);
{"INS", INS}, TAG(HTML);
{"KBD", KBD}, TAG(I);
{"LABEL", LABEL}, TAG(IFRAME);
{"LEGEND", LEGEND}, TAG(INS);
{"LI", LI}, TAG(KBD);
{"MAIN", MAIN}, TAG(LABEL);
{"MAP", MAP}, TAG(LEGEND);
{"MARK", MARK}, TAG(LI);
{"MATH", MATH}, TAG(MAIN);
{"MENU", MENU}, TAG(MAP);
{"METER", METER}, TAG(MARK);
{"NAV", NAV}, TAG(MATH);
{"NOSCRIPT", NOSCRIPT}, TAG(MENU);
{"OBJECT", OBJECT}, TAG(METER);
{"OL", OL}, TAG(NAV);
{"OPTGROUP", OPTGROUP}, TAG(NOSCRIPT);
{"OPTION", OPTION}, TAG(OBJECT);
{"OUTPUT", OUTPUT}, TAG(OL);
{"P", P}, TAG(OPTGROUP);
{"PICTURE", PICTURE}, TAG(OPTION);
{"PRE", PRE}, TAG(OUTPUT);
{"PROGRESS", PROGRESS}, TAG(P);
{"Q", Q}, TAG(PICTURE);
{"RB", RB}, TAG(PRE);
{"RP", RP}, TAG(PROGRESS);
{"RT", RT}, TAG(Q);
{"RTC", RTC}, TAG(RB);
{"RUBY", RUBY}, TAG(RP);
{"S", S}, TAG(RT);
{"SAMP", SAMP}, TAG(RTC);
{"SCRIPT", SCRIPT}, TAG(RUBY);
{"SECTION", SECTION}, TAG(S);
{"SELECT", SELECT}, TAG(SAMP);
{"SLOT", SLOT}, TAG(SCRIPT);
{"SMALL", SMALL}, TAG(SECTION);
{"SPAN", SPAN}, TAG(SELECT);
{"STRONG", STRONG}, TAG(SLOT);
{"STYLE", STYLE}, TAG(SMALL);
{"SUB", SUB}, TAG(SPAN);
{"SUMMARY", SUMMARY}, TAG(STRONG);
{"SUP", SUP}, TAG(STYLE);
{"SVG", SVG}, TAG(SUB);
{"TABLE", TABLE}, TAG(SUMMARY);
{"TBODY", TBODY}, TAG(SUP);
{"TD", TD}, TAG(SVG);
{"TEMPLATE", TEMPLATE}, TAG(TABLE);
{"TEXTAREA", TEXTAREA}, TAG(TBODY);
{"TFOOT", TFOOT}, TAG(TD);
{"TH", TH}, TAG(TEMPLATE);
{"THEAD", THEAD}, TAG(TEXTAREA);
{"TIME", TIME}, TAG(TFOOT);
{"TITLE", TITLE}, TAG(TH);
{"TR", TR}, TAG(THEAD);
{"U", U}, TAG(TIME);
{"UL", UL}, TAG(TITLE);
{"VAR", VAR}, TAG(TR);
{"VIDEO", VIDEO}, TAG(U);
}; TAG(UL);
TAG(VAR);
TAG(VIDEO);
#undef TAG
return result;
}
static const unordered_map<string, TagType> TAG_TYPES_BY_TAG_NAME = get_tag_map();
static const TagType TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS[] = { static const TagType TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS[] = {
ADDRESS, ADDRESS,