hash.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package html
  2. // generated by hasher -type=Hash -file=hash.go; DO NOT EDIT, except for adding more constants to the list and rerun go generate
  3. // uses github.com/tdewolff/hasher
  4. //go:generate hasher -type=Hash -file=hash.go
  5. // Hash defines perfect hashes for a predefined list of strings
  6. type Hash uint32
  7. // Unique hash definitions to be used instead of strings
  8. const (
  9. Iframe Hash = 0x6 // iframe
  10. Math Hash = 0x604 // math
  11. Plaintext Hash = 0x1e09 // plaintext
  12. Script Hash = 0xa06 // script
  13. Style Hash = 0x1405 // style
  14. Svg Hash = 0x1903 // svg
  15. Textarea Hash = 0x2308 // textarea
  16. Title Hash = 0xf05 // title
  17. Xmp Hash = 0x1c03 // xmp
  18. )
  19. // String returns the hash' name.
  20. func (i Hash) String() string {
  21. start := uint32(i >> 8)
  22. n := uint32(i & 0xff)
  23. if start+n > uint32(len(_Hash_text)) {
  24. return ""
  25. }
  26. return _Hash_text[start : start+n]
  27. }
  28. // ToHash returns the hash whose name is s. It returns zero if there is no
  29. // such hash. It is case sensitive.
  30. func ToHash(s []byte) Hash {
  31. if len(s) == 0 || len(s) > _Hash_maxLen {
  32. return 0
  33. }
  34. h := uint32(_Hash_hash0)
  35. for i := 0; i < len(s); i++ {
  36. h ^= uint32(s[i])
  37. h *= 16777619
  38. }
  39. if i := _Hash_table[h&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  40. t := _Hash_text[i>>8 : i>>8+i&0xff]
  41. for i := 0; i < len(s); i++ {
  42. if t[i] != s[i] {
  43. goto NEXT
  44. }
  45. }
  46. return i
  47. }
  48. NEXT:
  49. if i := _Hash_table[(h>>16)&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  50. t := _Hash_text[i>>8 : i>>8+i&0xff]
  51. for i := 0; i < len(s); i++ {
  52. if t[i] != s[i] {
  53. return 0
  54. }
  55. }
  56. return i
  57. }
  58. return 0
  59. }
  60. const _Hash_hash0 = 0x9acb0442
  61. const _Hash_maxLen = 9
  62. const _Hash_text = "iframemathscriptitlestylesvgxmplaintextarea"
  63. var _Hash_table = [1 << 4]Hash{
  64. 0x0: 0x2308, // textarea
  65. 0x2: 0x6, // iframe
  66. 0x4: 0xf05, // title
  67. 0x5: 0x1e09, // plaintext
  68. 0x7: 0x1405, // style
  69. 0x8: 0x604, // math
  70. 0x9: 0xa06, // script
  71. 0xa: 0x1903, // svg
  72. 0xb: 0x1c03, // xmp
  73. }