hash.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. package svg
  2. // uses github.com/tdewolff/hasher
  3. //go:generate hasher -type=Hash -file=hash.go
  4. // Hash defines perfect hashes for a predefined list of strings
  5. type Hash uint32
  6. // Identifiers for the hashes associated with the text in the comments.
  7. const (
  8. A Hash = 0x101 // a
  9. Alignment_Baseline Hash = 0x2e12 // alignment-baseline
  10. BaseProfile Hash = 0xb // baseProfile
  11. Baseline_Shift Hash = 0x380e // baseline-shift
  12. Buffered_Rendering Hash = 0x5212 // buffered-rendering
  13. Clip Hash = 0x6404 // clip
  14. Clip_Path Hash = 0x6409 // clip-path
  15. Clip_Rule Hash = 0x8009 // clip-rule
  16. Color Hash = 0xd805 // color
  17. Color_Interpolation Hash = 0xd813 // color-interpolation
  18. Color_Interpolation_Filters Hash = 0xd81b // color-interpolation-filters
  19. Color_Profile Hash = 0x1f70d // color-profile
  20. Color_Rendering Hash = 0x2320f // color-rendering
  21. ContentScriptType Hash = 0xa011 // contentScriptType
  22. ContentStyleType Hash = 0xb110 // contentStyleType
  23. Cursor Hash = 0xc106 // cursor
  24. D Hash = 0x5901 // d
  25. Defs Hash = 0x36904 // defs
  26. Direction Hash = 0x30c09 // direction
  27. Display Hash = 0x9807 // display
  28. Dominant_Baseline Hash = 0x19211 // dominant-baseline
  29. Enable_Background Hash = 0x8811 // enable-background
  30. FeImage Hash = 0x14507 // feImage
  31. Fill Hash = 0xc904 // fill
  32. Fill_Opacity Hash = 0x33d0c // fill-opacity
  33. Fill_Rule Hash = 0xc909 // fill-rule
  34. Filter Hash = 0xec06 // filter
  35. Flood_Color Hash = 0xd20b // flood-color
  36. Flood_Opacity Hash = 0x1050d // flood-opacity
  37. Font Hash = 0x11404 // font
  38. Font_Family Hash = 0x1140b // font-family
  39. Font_Size Hash = 0x11f09 // font-size
  40. Font_Size_Adjust Hash = 0x11f10 // font-size-adjust
  41. Font_Stretch Hash = 0x1370c // font-stretch
  42. Font_Style Hash = 0x14c0a // font-style
  43. Font_Variant Hash = 0x1560c // font-variant
  44. Font_Weight Hash = 0x1620b // font-weight
  45. ForeignObject Hash = 0x16d0d // foreignObject
  46. G Hash = 0x1601 // g
  47. Glyph_Orientation_Horizontal Hash = 0x1d31c // glyph-orientation-horizontal
  48. Glyph_Orientation_Vertical Hash = 0x161a // glyph-orientation-vertical
  49. Height Hash = 0x6c06 // height
  50. Href Hash = 0x14204 // href
  51. Image Hash = 0x17a05 // image
  52. Image_Rendering Hash = 0x17a0f // image-rendering
  53. Kerning Hash = 0x1bc07 // kerning
  54. Letter_Spacing Hash = 0x90e // letter-spacing
  55. Lighting_Color Hash = 0x1ee0e // lighting-color
  56. Line Hash = 0x3c04 // line
  57. Marker Hash = 0x18906 // marker
  58. Marker_End Hash = 0x1890a // marker-end
  59. Marker_Mid Hash = 0x1a30a // marker-mid
  60. Marker_Start Hash = 0x1ad0c // marker-start
  61. Mask Hash = 0x1b904 // mask
  62. Metadata Hash = 0x1c308 // metadata
  63. Missing_Glyph Hash = 0x1cb0d // missing-glyph
  64. Opacity Hash = 0x10b07 // opacity
  65. Overflow Hash = 0x26208 // overflow
  66. Paint_Order Hash = 0x2ae0b // paint-order
  67. Path Hash = 0x6904 // path
  68. Pattern Hash = 0x20407 // pattern
  69. Pointer_Events Hash = 0x20b0e // pointer-events
  70. Points Hash = 0x22706 // points
  71. Polygon Hash = 0x24107 // polygon
  72. Polyline Hash = 0x24808 // polyline
  73. PreserveAspectRatio Hash = 0x25013 // preserveAspectRatio
  74. Rect Hash = 0x30e04 // rect
  75. Rx Hash = 0x4f02 // rx
  76. Ry Hash = 0xc602 // ry
  77. Script Hash = 0xf206 // script
  78. Shape_Rendering Hash = 0x2180f // shape-rendering
  79. Solid_Color Hash = 0x22c0b // solid-color
  80. Solid_Opacity Hash = 0x36c0d // solid-opacity
  81. Stop_Color Hash = 0x12d0a // stop-color
  82. Stop_Opacity Hash = 0x2740c // stop-opacity
  83. Stroke Hash = 0x28006 // stroke
  84. Stroke_Dasharray Hash = 0x28010 // stroke-dasharray
  85. Stroke_Dashoffset Hash = 0x29011 // stroke-dashoffset
  86. Stroke_Linecap Hash = 0x2a10e // stroke-linecap
  87. Stroke_Linejoin Hash = 0x2b90f // stroke-linejoin
  88. Stroke_Miterlimit Hash = 0x2c811 // stroke-miterlimit
  89. Stroke_Opacity Hash = 0x2d90e // stroke-opacity
  90. Stroke_Width Hash = 0x2e70c // stroke-width
  91. Style Hash = 0x15105 // style
  92. Svg Hash = 0x2f303 // svg
  93. Switch Hash = 0x2f606 // switch
  94. Symbol Hash = 0x2fc06 // symbol
  95. Text_Anchor Hash = 0x450b // text-anchor
  96. Text_Decoration Hash = 0x710f // text-decoration
  97. Text_Rendering Hash = 0xf70e // text-rendering
  98. Type Hash = 0x11004 // type
  99. Unicode_Bidi Hash = 0x3020c // unicode-bidi
  100. Use Hash = 0x31503 // use
  101. Vector_Effect Hash = 0x3180d // vector-effect
  102. Version Hash = 0x32507 // version
  103. ViewBox Hash = 0x32c07 // viewBox
  104. Viewport_Fill Hash = 0x3340d // viewport-fill
  105. Viewport_Fill_Opacity Hash = 0x33415 // viewport-fill-opacity
  106. Visibility Hash = 0x3490a // visibility
  107. White_Space Hash = 0x2690b // white-space
  108. Width Hash = 0x2ee05 // width
  109. Word_Spacing Hash = 0x3530c // word-spacing
  110. Writing_Mode Hash = 0x35f0c // writing-mode
  111. X Hash = 0x4701 // x
  112. X1 Hash = 0x5002 // x1
  113. X2 Hash = 0x33202 // x2
  114. Xml_Space Hash = 0x37909 // xml:space
  115. Y Hash = 0x1801 // y
  116. Y1 Hash = 0x9e02 // y1
  117. Y2 Hash = 0xc702 // y2
  118. )
  119. var HashMap = map[string]Hash{
  120. "a": A,
  121. "alignment-baseline": Alignment_Baseline,
  122. "baseProfile": BaseProfile,
  123. "baseline-shift": Baseline_Shift,
  124. "buffered-rendering": Buffered_Rendering,
  125. "clip": Clip,
  126. "clip-path": Clip_Path,
  127. "clip-rule": Clip_Rule,
  128. "color": Color,
  129. "color-interpolation": Color_Interpolation,
  130. "color-interpolation-filters": Color_Interpolation_Filters,
  131. "color-profile": Color_Profile,
  132. "color-rendering": Color_Rendering,
  133. "contentScriptType": ContentScriptType,
  134. "contentStyleType": ContentStyleType,
  135. "cursor": Cursor,
  136. "d": D,
  137. "defs": Defs,
  138. "direction": Direction,
  139. "display": Display,
  140. "dominant-baseline": Dominant_Baseline,
  141. "enable-background": Enable_Background,
  142. "feImage": FeImage,
  143. "fill": Fill,
  144. "fill-opacity": Fill_Opacity,
  145. "fill-rule": Fill_Rule,
  146. "filter": Filter,
  147. "flood-color": Flood_Color,
  148. "flood-opacity": Flood_Opacity,
  149. "font": Font,
  150. "font-family": Font_Family,
  151. "font-size": Font_Size,
  152. "font-size-adjust": Font_Size_Adjust,
  153. "font-stretch": Font_Stretch,
  154. "font-style": Font_Style,
  155. "font-variant": Font_Variant,
  156. "font-weight": Font_Weight,
  157. "foreignObject": ForeignObject,
  158. "g": G,
  159. "glyph-orientation-horizontal": Glyph_Orientation_Horizontal,
  160. "glyph-orientation-vertical": Glyph_Orientation_Vertical,
  161. "height": Height,
  162. "href": Href,
  163. "image": Image,
  164. "image-rendering": Image_Rendering,
  165. "kerning": Kerning,
  166. "letter-spacing": Letter_Spacing,
  167. "lighting-color": Lighting_Color,
  168. "line": Line,
  169. "marker": Marker,
  170. "marker-end": Marker_End,
  171. "marker-mid": Marker_Mid,
  172. "marker-start": Marker_Start,
  173. "mask": Mask,
  174. "metadata": Metadata,
  175. "missing-glyph": Missing_Glyph,
  176. "opacity": Opacity,
  177. "overflow": Overflow,
  178. "paint-order": Paint_Order,
  179. "path": Path,
  180. "pattern": Pattern,
  181. "pointer-events": Pointer_Events,
  182. "points": Points,
  183. "polygon": Polygon,
  184. "polyline": Polyline,
  185. "preserveAspectRatio": PreserveAspectRatio,
  186. "rect": Rect,
  187. "rx": Rx,
  188. "ry": Ry,
  189. "script": Script,
  190. "shape-rendering": Shape_Rendering,
  191. "solid-color": Solid_Color,
  192. "solid-opacity": Solid_Opacity,
  193. "stop-color": Stop_Color,
  194. "stop-opacity": Stop_Opacity,
  195. "stroke": Stroke,
  196. "stroke-dasharray": Stroke_Dasharray,
  197. "stroke-dashoffset": Stroke_Dashoffset,
  198. "stroke-linecap": Stroke_Linecap,
  199. "stroke-linejoin": Stroke_Linejoin,
  200. "stroke-miterlimit": Stroke_Miterlimit,
  201. "stroke-opacity": Stroke_Opacity,
  202. "stroke-width": Stroke_Width,
  203. "style": Style,
  204. "svg": Svg,
  205. "switch": Switch,
  206. "symbol": Symbol,
  207. "text-anchor": Text_Anchor,
  208. "text-decoration": Text_Decoration,
  209. "text-rendering": Text_Rendering,
  210. "type": Type,
  211. "unicode-bidi": Unicode_Bidi,
  212. "use": Use,
  213. "vector-effect": Vector_Effect,
  214. "version": Version,
  215. "viewBox": ViewBox,
  216. "viewport-fill": Viewport_Fill,
  217. "viewport-fill-opacity": Viewport_Fill_Opacity,
  218. "visibility": Visibility,
  219. "white-space": White_Space,
  220. "width": Width,
  221. "word-spacing": Word_Spacing,
  222. "writing-mode": Writing_Mode,
  223. "x": X,
  224. "x1": X1,
  225. "x2": X2,
  226. "xml:space": Xml_Space,
  227. "y": Y,
  228. "y1": Y1,
  229. "y2": Y2,
  230. }
  231. // String returns the text associated with the hash.
  232. func (i Hash) String() string {
  233. return string(i.Bytes())
  234. }
  235. // Bytes returns the text associated with the hash.
  236. func (i Hash) Bytes() []byte {
  237. start := uint32(i >> 8)
  238. n := uint32(i & 0xff)
  239. if start+n > uint32(len(_Hash_text)) {
  240. return []byte{}
  241. }
  242. return _Hash_text[start : start+n]
  243. }
  244. // 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.
  245. func ToHash(s []byte) Hash {
  246. if 3 < len(s) {
  247. return HashMap[string(s)]
  248. }
  249. h := uint32(_Hash_hash0)
  250. for i := 0; i < len(s); i++ {
  251. h ^= uint32(s[i])
  252. h *= 16777619
  253. }
  254. if i := _Hash_table[h&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  255. t := _Hash_text[i>>8 : i>>8+i&0xff]
  256. for i := 0; i < len(s); i++ {
  257. if t[i] != s[i] {
  258. goto NEXT
  259. }
  260. }
  261. return i
  262. }
  263. NEXT:
  264. if i := _Hash_table[(h>>16)&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  265. t := _Hash_text[i>>8 : i>>8+i&0xff]
  266. for i := 0; i < len(s); i++ {
  267. if t[i] != s[i] {
  268. return 0
  269. }
  270. }
  271. return i
  272. }
  273. return 0
  274. }
  275. const _Hash_hash0 = 0x2d0dfdc1
  276. const _Hash_maxLen = 28
  277. var _Hash_text = []byte("" +
  278. "baseProfiletter-spacinglyph-orientation-verticalignment-base" +
  279. "line-shiftext-anchorx1buffered-renderingclip-patheightext-de" +
  280. "corationclip-rulenable-backgroundisplay1contentScriptTypecon" +
  281. "tentStyleTypecursory2fill-ruleflood-color-interpolation-filt" +
  282. "erscriptext-renderingflood-opacitypefont-familyfont-size-adj" +
  283. "ustop-colorfont-stretchrefeImagefont-stylefont-variantfont-w" +
  284. "eightforeignObjectimage-renderingmarker-endominant-baselinem" +
  285. "arker-midmarker-startmaskerningmetadatamissing-glyph-orienta" +
  286. "tion-horizontalighting-color-profilepatternpointer-eventshap" +
  287. "e-renderingpointsolid-color-renderingpolygonpolylinepreserve" +
  288. "AspectRatioverflowhite-spacestop-opacitystroke-dasharraystro" +
  289. "ke-dashoffsetstroke-linecapaint-orderstroke-linejoinstroke-m" +
  290. "iterlimitstroke-opacitystroke-widthsvgswitchsymbolunicode-bi" +
  291. "directionusevector-effectversionviewBox2viewport-fill-opacit" +
  292. "yvisibilityword-spacingwriting-modefsolid-opacityxml:space")
  293. var _Hash_table = [1 << 7]Hash{
  294. 0x1: 0x2f303, // svg
  295. 0x2: 0x2f606, // switch
  296. 0x3: 0x18906, // marker
  297. 0x5: 0x1620b, // font-weight
  298. 0x6: 0x1801, // y
  299. 0x7: 0x33d0c, // fill-opacity
  300. 0x8: 0x2e70c, // stroke-width
  301. 0x9: 0x33415, // viewport-fill-opacity
  302. 0xa: 0x9807, // display
  303. 0xb: 0xb110, // contentStyleType
  304. 0xc: 0x30c09, // direction
  305. 0xd: 0x20407, // pattern
  306. 0xf: 0x1f70d, // color-profile
  307. 0x10: 0xc602, // ry
  308. 0x12: 0x1ad0c, // marker-start
  309. 0x13: 0x1050d, // flood-opacity
  310. 0x14: 0x36c0d, // solid-opacity
  311. 0x15: 0x90e, // letter-spacing
  312. 0x16: 0x17a05, // image
  313. 0x17: 0x1890a, // marker-end
  314. 0x18: 0x2c811, // stroke-miterlimit
  315. 0x19: 0x20b0e, // pointer-events
  316. 0x1a: 0x12d0a, // stop-color
  317. 0x1b: 0x1b904, // mask
  318. 0x1c: 0xc904, // fill
  319. 0x1d: 0xc909, // fill-rule
  320. 0x1f: 0x26208, // overflow
  321. 0x20: 0x1a30a, // marker-mid
  322. 0x21: 0x1bc07, // kerning
  323. 0x22: 0xa011, // contentScriptType
  324. 0x23: 0x4f02, // rx
  325. 0x24: 0x1560c, // font-variant
  326. 0x25: 0x3020c, // unicode-bidi
  327. 0x26: 0x2a10e, // stroke-linecap
  328. 0x27: 0xc106, // cursor
  329. 0x28: 0x25013, // preserveAspectRatio
  330. 0x29: 0x14507, // feImage
  331. 0x2a: 0x2e12, // alignment-baseline
  332. 0x2b: 0x33202, // x2
  333. 0x2c: 0x450b, // text-anchor
  334. 0x2d: 0x1d31c, // glyph-orientation-horizontal
  335. 0x2e: 0xf206, // script
  336. 0x2f: 0x3180d, // vector-effect
  337. 0x30: 0x1370c, // font-stretch
  338. 0x31: 0x36904, // defs
  339. 0x32: 0x29011, // stroke-dashoffset
  340. 0x33: 0x6c06, // height
  341. 0x34: 0xd81b, // color-interpolation-filters
  342. 0x36: 0x2ae0b, // paint-order
  343. 0x37: 0x19211, // dominant-baseline
  344. 0x38: 0x11404, // font
  345. 0x39: 0x24808, // polyline
  346. 0x3a: 0x32c07, // viewBox
  347. 0x3b: 0x4701, // x
  348. 0x3c: 0x11004, // type
  349. 0x3d: 0x28010, // stroke-dasharray
  350. 0x3e: 0x5002, // x1
  351. 0x3f: 0x5901, // d
  352. 0x42: 0x8811, // enable-background
  353. 0x43: 0x30e04, // rect
  354. 0x44: 0x2180f, // shape-rendering
  355. 0x46: 0x37909, // xml:space
  356. 0x47: 0x161a, // glyph-orientation-vertical
  357. 0x48: 0x31503, // use
  358. 0x49: 0x3490a, // visibility
  359. 0x4a: 0x16d0d, // foreignObject
  360. 0x4b: 0x710f, // text-decoration
  361. 0x4c: 0x15105, // style
  362. 0x4f: 0x17a0f, // image-rendering
  363. 0x50: 0x24107, // polygon
  364. 0x51: 0x5212, // buffered-rendering
  365. 0x52: 0x1601, // g
  366. 0x53: 0x1140b, // font-family
  367. 0x54: 0x14204, // href
  368. 0x55: 0xec06, // filter
  369. 0x56: 0x1c308, // metadata
  370. 0x57: 0x1ee0e, // lighting-color
  371. 0x58: 0xf70e, // text-rendering
  372. 0x59: 0x35f0c, // writing-mode
  373. 0x5a: 0x10b07, // opacity
  374. 0x5b: 0x9e02, // y1
  375. 0x5c: 0xd20b, // flood-color
  376. 0x5d: 0x2690b, // white-space
  377. 0x60: 0x101, // a
  378. 0x61: 0xb, // baseProfile
  379. 0x62: 0x14c0a, // font-style
  380. 0x63: 0x3340d, // viewport-fill
  381. 0x65: 0x8009, // clip-rule
  382. 0x67: 0x6904, // path
  383. 0x68: 0xd813, // color-interpolation
  384. 0x69: 0x2d90e, // stroke-opacity
  385. 0x6a: 0x2b90f, // stroke-linejoin
  386. 0x6b: 0x2ee05, // width
  387. 0x6d: 0x2320f, // color-rendering
  388. 0x6e: 0xc702, // y2
  389. 0x6f: 0x3c04, // line
  390. 0x70: 0x1cb0d, // missing-glyph
  391. 0x71: 0x2740c, // stop-opacity
  392. 0x72: 0x11f09, // font-size
  393. 0x73: 0x380e, // baseline-shift
  394. 0x74: 0x3530c, // word-spacing
  395. 0x75: 0x2fc06, // symbol
  396. 0x76: 0x11f10, // font-size-adjust
  397. 0x77: 0xd805, // color
  398. 0x79: 0x28006, // stroke
  399. 0x7b: 0x22706, // points
  400. 0x7c: 0x32507, // version
  401. 0x7d: 0x6409, // clip-path
  402. 0x7e: 0x22c0b, // solid-color
  403. 0x7f: 0x6404, // clip
  404. }