Avoid designated initializer syntax for static array

Clang seems to allow this, but it's only for C, not C++
This commit is contained in:
Max Brunsfeld 2018-06-12 13:49:54 -07:00
parent 14ed7c8147
commit b4153cd431
1 changed files with 39 additions and 31 deletions

70
src/tag.h vendored
View File

@ -5,7 +5,6 @@ using std::string;
using std::unordered_map; using std::unordered_map;
enum TagType : char { enum TagType : char {
// Void tags
AREA, AREA,
BASE, BASE,
BASEFONT, BASEFONT,
@ -265,35 +264,41 @@ static const unordered_map<string, TagType> TAG_TYPES_BY_TAG_NAME = {
{"VIDEO", VIDEO}, {"VIDEO", VIDEO},
}; };
static const bool PARAGRAPH_CANNOT_CONTAIN[CUSTOM + 1] = { static const TagType TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS[] = {
[ADDRESS] = true, ADDRESS,
[ARTICLE] = true, ARTICLE,
[ASIDE] = true, ASIDE,
[BLOCKQUOTE] = true, BLOCKQUOTE,
[DETAILS] = true, DETAILS,
[DIV] = true, DIV,
[DL] = true, DL,
[FIELDSET] = true, FIELDSET,
[FIGCAPTION] = true, FIGCAPTION,
[FIGURE] = true, FIGURE,
[FOOTER] = true, FOOTER,
[FORM] = true, FORM,
[H1] = true, H1,
[H2] = true, H2,
[H3] = true, H3,
[H4] = true, H4,
[H5] = true, H5,
[H6] = true, H6,
[HEADER] = true, HEADER,
[HR] = true, HR,
[MAIN] = true, MAIN,
[NAV] = true, NAV,
[OL] = true, OL,
[P] = true, P,
[PRE] = true, PRE,
[SECTION] = true, SECTION,
}; };
static const TagType *TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS_END = (
TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS +
sizeof(TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS) /
sizeof(TagType)
);
struct Tag { struct Tag {
TagType type; TagType type;
string custom_tag_name; string custom_tag_name;
@ -323,7 +328,11 @@ struct Tag {
return child != DT && child != DD; return child != DT && child != DD;
case P: case P:
return !PARAGRAPH_CANNOT_CONTAIN[child]; return std::find(
TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS,
TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS_END,
tag.type
) == TAG_TYPES_NOT_ALLOWED_IN_PARAGRAPHS_END;
case COLGROUP: case COLGROUP:
return child == COL; return child == COL;
@ -348,12 +357,11 @@ struct Tag {
} }
} }
static Tag for_name(const string &name) { static inline Tag for_name(const string &name) {
auto type = TAG_TYPES_BY_TAG_NAME.find(name); auto type = TAG_TYPES_BY_TAG_NAME.find(name);
if (type != TAG_TYPES_BY_TAG_NAME.end()) { if (type != TAG_TYPES_BY_TAG_NAME.end()) {
return Tag { type->second, "" }; return Tag { type->second, "" };
} }
return Tag { CUSTOM, name }; return Tag { CUSTOM, name };
} }
}; };