1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* Generated file, do not edit */
#ifndef CSSPROPS_H
#define CSSPROPS_H
#include <string.h>
typedef enum {
CSS_PROP_UNKNOWN,
CSS_PROP_COLOR,
CSS_PROP_DISPLAY,
CSS_PROP_FONT_FAMILY,
CSS_PROP_FONT_SIZE,
CSS_PROP_FONT_WEIGHT,
CSS_PROP_LINE_HEIGHT,
CSS_PROP_LIST_STYLE_TYPE,
CSS_PROP_MARGIN,
CSS_PROP_PADDING_LEFT,
CSS_PROP_TEXT_DECORATION,
} css_prop;
static const struct {
const char *name;
css_prop prop;
} css_prop_map[] = {
{ "color", CSS_PROP_COLOR },
{ "display", CSS_PROP_DISPLAY },
{ "font-family", CSS_PROP_FONT_FAMILY },
{ "font-size", CSS_PROP_FONT_SIZE },
{ "font-weight", CSS_PROP_FONT_WEIGHT },
{ "line-height", CSS_PROP_LINE_HEIGHT },
{ "list-style-type", CSS_PROP_LIST_STYLE_TYPE },
{ "margin", CSS_PROP_MARGIN },
{ "padding-left", CSS_PROP_PADDING_LEFT },
{ "text-decoration", CSS_PROP_TEXT_DECORATION },
};
static inline css_prop
str_to_css_prop(const char *name, size_t len)
{
int lo, hi, mid, cmp;
lo = 0;
hi = 10 - 1;
while (lo <= hi) {
mid = (lo + hi) / 2;
cmp = strncmp(name, css_prop_map[mid].name, len);
if (cmp == 0) {
if (css_prop_map[mid].name[len] == '\0')
return css_prop_map[mid].prop;
hi = mid - 1;
} else if (cmp < 0)
hi = mid - 1;
else
lo = mid + 1;
}
return CSS_PROP_UNKNOWN;
}
static inline const char *
css_prop_to_str(css_prop prop)
{
switch (prop) {
case CSS_PROP_UNKNOWN: return "unknown";
case CSS_PROP_COLOR: return "color";
case CSS_PROP_DISPLAY: return "display";
case CSS_PROP_FONT_FAMILY: return "font-family";
case CSS_PROP_FONT_SIZE: return "font-size";
case CSS_PROP_FONT_WEIGHT: return "font-weight";
case CSS_PROP_LINE_HEIGHT: return "line-height";
case CSS_PROP_LIST_STYLE_TYPE: return "list-style-type";
case CSS_PROP_MARGIN: return "margin";
case CSS_PROP_PADDING_LEFT: return "padding-left";
case CSS_PROP_TEXT_DECORATION: return "text-decoration";
default: return "unknown";
}
}
#endif /* CSSPROPS_H */
|