gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

hash.go (1984B)


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