|
1 | 1 | package html |
2 | 2 |
|
3 | | -// generated by hasher -type=Hash -file=hash.go; DO NOT EDIT, except for adding more constants to the list and rerun go generate |
4 | | - |
5 | 3 | // uses github.com/tdewolff/hasher |
6 | 4 | //go:generate hasher -type=Hash -file=hash.go |
7 | 5 |
|
8 | 6 | // Hash defines perfect hashes for a predefined list of strings |
9 | 7 | type Hash uint32 |
10 | 8 |
|
11 | | -// Unique hash definitions to be used instead of strings |
| 9 | +// Identifiers for the hashes associated with the text in the comments. |
12 | 10 | const ( |
13 | 11 | Iframe Hash = 0x6 // iframe |
14 | 12 | Math Hash = 0x604 // math |
15 | | - Plaintext Hash = 0x1e09 // plaintext |
| 13 | + Plaintext Hash = 0x2109 // plaintext |
16 | 14 | Script Hash = 0xa06 // script |
17 | 15 | Style Hash = 0x1405 // style |
18 | 16 | Svg Hash = 0x1903 // svg |
19 | | - Textarea Hash = 0x2308 // textarea |
| 17 | + Textarea Hash = 0x2608 // textarea |
20 | 18 | Title Hash = 0xf05 // title |
21 | | - Xmp Hash = 0x1c03 // xmp |
| 19 | + Xml Hash = 0x1c03 // xml |
| 20 | + Xmp Hash = 0x1f03 // xmp |
22 | 21 | ) |
23 | 22 |
|
24 | | -// String returns the hash' name. |
| 23 | +//var HashMap = map[string]Hash{ |
| 24 | +// "iframe": Iframe, |
| 25 | +// "math": Math, |
| 26 | +// "plaintext": Plaintext, |
| 27 | +// "script": Script, |
| 28 | +// "style": Style, |
| 29 | +// "svg": Svg, |
| 30 | +// "textarea": Textarea, |
| 31 | +// "title": Title, |
| 32 | +// "xml": Xml, |
| 33 | +// "xmp": Xmp, |
| 34 | +//} |
| 35 | + |
| 36 | +// String returns the text associated with the hash. |
25 | 37 | func (i Hash) String() string { |
| 38 | + return string(i.Bytes()) |
| 39 | +} |
| 40 | + |
| 41 | +// Bytes returns the text associated with the hash. |
| 42 | +func (i Hash) Bytes() []byte { |
26 | 43 | start := uint32(i >> 8) |
27 | 44 | n := uint32(i & 0xff) |
28 | 45 | if start+n > uint32(len(_Hash_text)) { |
29 | | - return "" |
| 46 | + return []byte{} |
30 | 47 | } |
31 | 48 | return _Hash_text[start : start+n] |
32 | 49 | } |
33 | 50 |
|
34 | | -// ToHash returns the hash whose name is s. It returns zero if there is no |
35 | | -// such hash. It is case sensitive. |
| 51 | +// ToHash returns a hash Hash for a given []byte. Hash is a uint32 that is associated with the text in []byte. It returns zero if no match found. |
36 | 52 | func ToHash(s []byte) Hash { |
37 | 53 | if len(s) == 0 || len(s) > _Hash_maxLen { |
38 | 54 | return 0 |
39 | 55 | } |
| 56 | + //if 3 < len(s) { |
| 57 | + // return HashMap[string(s)] |
| 58 | + //} |
40 | 59 | h := uint32(_Hash_hash0) |
41 | 60 | for i := 0; i < len(s); i++ { |
42 | 61 | h ^= uint32(s[i]) |
@@ -64,18 +83,21 @@ NEXT: |
64 | 83 | return 0 |
65 | 84 | } |
66 | 85 |
|
67 | | -const _Hash_hash0 = 0x9acb0442 |
| 86 | +const _Hash_hash0 = 0xb4b790b3 |
68 | 87 | const _Hash_maxLen = 9 |
69 | | -const _Hash_text = "iframemathscriptitlestylesvgxmplaintextarea" |
| 88 | + |
| 89 | +var _Hash_text = []byte("" + |
| 90 | + "iframemathscriptitlestylesvgxmlxmplaintextarea") |
70 | 91 |
|
71 | 92 | var _Hash_table = [1 << 4]Hash{ |
72 | | - 0x0: 0x2308, // textarea |
73 | | - 0x2: 0x6, // iframe |
74 | | - 0x4: 0xf05, // title |
75 | | - 0x5: 0x1e09, // plaintext |
76 | | - 0x7: 0x1405, // style |
77 | | - 0x8: 0x604, // math |
78 | | - 0x9: 0xa06, // script |
79 | | - 0xa: 0x1903, // svg |
80 | | - 0xb: 0x1c03, // xmp |
| 93 | + 0x2: 0xa06, // script |
| 94 | + 0x3: 0xf05, // title |
| 95 | + 0x4: 0x1405, // style |
| 96 | + 0x5: 0x604, // math |
| 97 | + 0x6: 0x6, // iframe |
| 98 | + 0x8: 0x1c03, // xml |
| 99 | + 0x9: 0x2608, // textarea |
| 100 | + 0xc: 0x1f03, // xmp |
| 101 | + 0xe: 0x2109, // plaintext |
| 102 | + 0xf: 0x1903, // svg |
81 | 103 | } |
0 commit comments