nokolexbor 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (486) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nokolexbor/config.h +186 -0
  3. data/ext/nokolexbor/extconf.rb +131 -0
  4. data/ext/nokolexbor/libxml/HTMLparser.h +320 -0
  5. data/ext/nokolexbor/libxml/SAX2.h +173 -0
  6. data/ext/nokolexbor/libxml/chvalid.h +230 -0
  7. data/ext/nokolexbor/libxml/debugXML.h +217 -0
  8. data/ext/nokolexbor/libxml/dict.h +81 -0
  9. data/ext/nokolexbor/libxml/encoding.h +232 -0
  10. data/ext/nokolexbor/libxml/entities.h +153 -0
  11. data/ext/nokolexbor/libxml/globals.h +529 -0
  12. data/ext/nokolexbor/libxml/hash.h +236 -0
  13. data/ext/nokolexbor/libxml/list.h +137 -0
  14. data/ext/nokolexbor/libxml/parser.h +1264 -0
  15. data/ext/nokolexbor/libxml/parserInternals.h +641 -0
  16. data/ext/nokolexbor/libxml/pattern.h +100 -0
  17. data/ext/nokolexbor/libxml/threads.h +94 -0
  18. data/ext/nokolexbor/libxml/tree.h +1315 -0
  19. data/ext/nokolexbor/libxml/uri.h +94 -0
  20. data/ext/nokolexbor/libxml/valid.h +448 -0
  21. data/ext/nokolexbor/libxml/xmlIO.h +369 -0
  22. data/ext/nokolexbor/libxml/xmlautomata.h +146 -0
  23. data/ext/nokolexbor/libxml/xmlerror.h +919 -0
  24. data/ext/nokolexbor/libxml/xmlexports.h +79 -0
  25. data/ext/nokolexbor/libxml/xmlmemory.h +226 -0
  26. data/ext/nokolexbor/libxml/xmlregexp.h +222 -0
  27. data/ext/nokolexbor/libxml/xmlstring.h +140 -0
  28. data/ext/nokolexbor/libxml/xmlversion.h +526 -0
  29. data/ext/nokolexbor/libxml/xpath.h +575 -0
  30. data/ext/nokolexbor/libxml/xpathInternals.h +632 -0
  31. data/ext/nokolexbor/libxml/xpointer.h +137 -0
  32. data/ext/nokolexbor/libxml.h +76 -0
  33. data/ext/nokolexbor/memory.c +39 -0
  34. data/ext/nokolexbor/nl_document.c +51 -0
  35. data/ext/nokolexbor/nl_node.c +790 -0
  36. data/ext/nokolexbor/nl_node_set.c +368 -0
  37. data/ext/nokolexbor/nl_xpath_context.c +200 -0
  38. data/ext/nokolexbor/nokolexbor.c +63 -0
  39. data/ext/nokolexbor/nokolexbor.h +37 -0
  40. data/ext/nokolexbor/private/buf.h +70 -0
  41. data/ext/nokolexbor/private/dict.h +11 -0
  42. data/ext/nokolexbor/private/enc.h +17 -0
  43. data/ext/nokolexbor/private/error.h +21 -0
  44. data/ext/nokolexbor/private/globals.h +9 -0
  45. data/ext/nokolexbor/private/memory.h +9 -0
  46. data/ext/nokolexbor/private/parser.h +27 -0
  47. data/ext/nokolexbor/private/string.h +9 -0
  48. data/ext/nokolexbor/private/threads.h +50 -0
  49. data/ext/nokolexbor/private/tree.h +18 -0
  50. data/ext/nokolexbor/private/xpath.h +7 -0
  51. data/ext/nokolexbor/timsort.h +601 -0
  52. data/ext/nokolexbor/xml_SAX2.c +80 -0
  53. data/ext/nokolexbor/xml_buf.c +363 -0
  54. data/ext/nokolexbor/xml_chvalid.c +334 -0
  55. data/ext/nokolexbor/xml_dict.c +1264 -0
  56. data/ext/nokolexbor/xml_encoding.c +124 -0
  57. data/ext/nokolexbor/xml_error.c +134 -0
  58. data/ext/nokolexbor/xml_globals.c +1085 -0
  59. data/ext/nokolexbor/xml_hash.c +1141 -0
  60. data/ext/nokolexbor/xml_memory.c +203 -0
  61. data/ext/nokolexbor/xml_parser.c +127 -0
  62. data/ext/nokolexbor/xml_parserInternals.c +338 -0
  63. data/ext/nokolexbor/xml_pattern.c +2375 -0
  64. data/ext/nokolexbor/xml_string.c +1051 -0
  65. data/ext/nokolexbor/xml_threads.c +881 -0
  66. data/ext/nokolexbor/xml_tree.c +148 -0
  67. data/ext/nokolexbor/xml_xpath.c +14743 -0
  68. data/lib/nokolexbor/attribute.rb +18 -0
  69. data/lib/nokolexbor/document.rb +6 -0
  70. data/lib/nokolexbor/node.rb +264 -0
  71. data/lib/nokolexbor/node_set.rb +124 -0
  72. data/lib/nokolexbor/version.rb +5 -0
  73. data/lib/nokolexbor/xpath_context.rb +14 -0
  74. data/lib/nokolexbor.rb +17 -0
  75. data/patches/0001-lexbor-support-text-pseudo-element.patch +137 -0
  76. data/patches/0002-lexbor-match-id-class-case-sensitive.patch +22 -0
  77. data/patches/0003-lexbor-attach-template-content-to-self.patch +13 -0
  78. data/vendor/lexbor/CMakeLists.txt +331 -0
  79. data/vendor/lexbor/config.cmake +890 -0
  80. data/vendor/lexbor/feature.cmake +134 -0
  81. data/vendor/lexbor/source/lexbor/core/array.c +208 -0
  82. data/vendor/lexbor/source/lexbor/core/array.h +100 -0
  83. data/vendor/lexbor/source/lexbor/core/array_obj.c +216 -0
  84. data/vendor/lexbor/source/lexbor/core/array_obj.h +134 -0
  85. data/vendor/lexbor/source/lexbor/core/avl.c +442 -0
  86. data/vendor/lexbor/source/lexbor/core/avl.h +82 -0
  87. data/vendor/lexbor/source/lexbor/core/base.h +86 -0
  88. data/vendor/lexbor/source/lexbor/core/bst.c +468 -0
  89. data/vendor/lexbor/source/lexbor/core/bst.h +108 -0
  90. data/vendor/lexbor/source/lexbor/core/bst_map.c +238 -0
  91. data/vendor/lexbor/source/lexbor/core/bst_map.h +87 -0
  92. data/vendor/lexbor/source/lexbor/core/config.cmake +12 -0
  93. data/vendor/lexbor/source/lexbor/core/conv.c +203 -0
  94. data/vendor/lexbor/source/lexbor/core/conv.h +53 -0
  95. data/vendor/lexbor/source/lexbor/core/core.h +35 -0
  96. data/vendor/lexbor/source/lexbor/core/def.h +57 -0
  97. data/vendor/lexbor/source/lexbor/core/diyfp.c +153 -0
  98. data/vendor/lexbor/source/lexbor/core/diyfp.h +258 -0
  99. data/vendor/lexbor/source/lexbor/core/dobject.c +187 -0
  100. data/vendor/lexbor/source/lexbor/core/dobject.h +92 -0
  101. data/vendor/lexbor/source/lexbor/core/dtoa.c +404 -0
  102. data/vendor/lexbor/source/lexbor/core/dtoa.h +28 -0
  103. data/vendor/lexbor/source/lexbor/core/fs.h +60 -0
  104. data/vendor/lexbor/source/lexbor/core/hash.c +476 -0
  105. data/vendor/lexbor/source/lexbor/core/hash.h +218 -0
  106. data/vendor/lexbor/source/lexbor/core/in.c +267 -0
  107. data/vendor/lexbor/source/lexbor/core/in.h +172 -0
  108. data/vendor/lexbor/source/lexbor/core/lexbor.h +35 -0
  109. data/vendor/lexbor/source/lexbor/core/mem.c +228 -0
  110. data/vendor/lexbor/source/lexbor/core/mem.h +141 -0
  111. data/vendor/lexbor/source/lexbor/core/mraw.c +428 -0
  112. data/vendor/lexbor/source/lexbor/core/mraw.h +114 -0
  113. data/vendor/lexbor/source/lexbor/core/perf.h +45 -0
  114. data/vendor/lexbor/source/lexbor/core/plog.c +73 -0
  115. data/vendor/lexbor/source/lexbor/core/plog.h +102 -0
  116. data/vendor/lexbor/source/lexbor/core/print.c +168 -0
  117. data/vendor/lexbor/source/lexbor/core/print.h +39 -0
  118. data/vendor/lexbor/source/lexbor/core/sbst.h +59 -0
  119. data/vendor/lexbor/source/lexbor/core/serialize.c +27 -0
  120. data/vendor/lexbor/source/lexbor/core/serialize.h +32 -0
  121. data/vendor/lexbor/source/lexbor/core/shs.c +118 -0
  122. data/vendor/lexbor/source/lexbor/core/shs.h +82 -0
  123. data/vendor/lexbor/source/lexbor/core/str.c +617 -0
  124. data/vendor/lexbor/source/lexbor/core/str.h +247 -0
  125. data/vendor/lexbor/source/lexbor/core/str_res.h +369 -0
  126. data/vendor/lexbor/source/lexbor/core/strtod.c +326 -0
  127. data/vendor/lexbor/source/lexbor/core/strtod.h +28 -0
  128. data/vendor/lexbor/source/lexbor/core/types.h +39 -0
  129. data/vendor/lexbor/source/lexbor/core/utils.c +43 -0
  130. data/vendor/lexbor/source/lexbor/core/utils.h +36 -0
  131. data/vendor/lexbor/source/lexbor/css/base.h +44 -0
  132. data/vendor/lexbor/source/lexbor/css/config.cmake +2 -0
  133. data/vendor/lexbor/source/lexbor/css/css.h +25 -0
  134. data/vendor/lexbor/source/lexbor/css/log.c +336 -0
  135. data/vendor/lexbor/source/lexbor/css/log.h +103 -0
  136. data/vendor/lexbor/source/lexbor/css/node.h +29 -0
  137. data/vendor/lexbor/source/lexbor/css/parser.c +473 -0
  138. data/vendor/lexbor/source/lexbor/css/parser.h +368 -0
  139. data/vendor/lexbor/source/lexbor/css/selectors/base.h +48 -0
  140. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.c +91 -0
  141. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.h +66 -0
  142. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_const.h +109 -0
  143. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_res.h +302 -0
  144. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.c +279 -0
  145. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.h +85 -0
  146. data/vendor/lexbor/source/lexbor/css/selectors/selector.c +927 -0
  147. data/vendor/lexbor/source/lexbor/css/selectors/selector.h +200 -0
  148. data/vendor/lexbor/source/lexbor/css/selectors/selectors.c +340 -0
  149. data/vendor/lexbor/source/lexbor/css/selectors/selectors.h +137 -0
  150. data/vendor/lexbor/source/lexbor/css/selectors/state.c +1718 -0
  151. data/vendor/lexbor/source/lexbor/css/selectors/state.h +79 -0
  152. data/vendor/lexbor/source/lexbor/css/stylesheet.h +37 -0
  153. data/vendor/lexbor/source/lexbor/css/syntax/anb.c +443 -0
  154. data/vendor/lexbor/source/lexbor/css/syntax/anb.h +45 -0
  155. data/vendor/lexbor/source/lexbor/css/syntax/base.h +33 -0
  156. data/vendor/lexbor/source/lexbor/css/syntax/parser.c +9 -0
  157. data/vendor/lexbor/source/lexbor/css/syntax/parser.h +25 -0
  158. data/vendor/lexbor/source/lexbor/css/syntax/res.h +48 -0
  159. data/vendor/lexbor/source/lexbor/css/syntax/state.c +2603 -0
  160. data/vendor/lexbor/source/lexbor/css/syntax/state.h +140 -0
  161. data/vendor/lexbor/source/lexbor/css/syntax/state_res.h +273 -0
  162. data/vendor/lexbor/source/lexbor/css/syntax/syntax.c +67 -0
  163. data/vendor/lexbor/source/lexbor/css/syntax/token.c +618 -0
  164. data/vendor/lexbor/source/lexbor/css/syntax/token.h +298 -0
  165. data/vendor/lexbor/source/lexbor/css/syntax/token_res.h +68 -0
  166. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.c +30 -0
  167. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.h +58 -0
  168. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.c +278 -0
  169. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.h +121 -0
  170. data/vendor/lexbor/source/lexbor/dom/base.h +32 -0
  171. data/vendor/lexbor/source/lexbor/dom/collection.c +97 -0
  172. data/vendor/lexbor/source/lexbor/dom/collection.h +112 -0
  173. data/vendor/lexbor/source/lexbor/dom/config.cmake +3 -0
  174. data/vendor/lexbor/source/lexbor/dom/dom.h +29 -0
  175. data/vendor/lexbor/source/lexbor/dom/exception.c +18 -0
  176. data/vendor/lexbor/source/lexbor/dom/exception.h +73 -0
  177. data/vendor/lexbor/source/lexbor/dom/interface.c +110 -0
  178. data/vendor/lexbor/source/lexbor/dom/interface.h +88 -0
  179. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.c +445 -0
  180. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.h +152 -0
  181. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_const.h +62 -0
  182. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_res.h +143 -0
  183. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.c +55 -0
  184. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.h +38 -0
  185. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.c +110 -0
  186. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.h +51 -0
  187. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.c +64 -0
  188. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.h +42 -0
  189. data/vendor/lexbor/source/lexbor/dom/interfaces/document.c +536 -0
  190. data/vendor/lexbor/source/lexbor/dom/interfaces/document.h +243 -0
  191. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.c +36 -0
  192. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.h +36 -0
  193. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.c +125 -0
  194. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.h +108 -0
  195. data/vendor/lexbor/source/lexbor/dom/interfaces/element.c +1411 -0
  196. data/vendor/lexbor/source/lexbor/dom/interfaces/element.h +319 -0
  197. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.c +32 -0
  198. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.h +34 -0
  199. data/vendor/lexbor/source/lexbor/dom/interfaces/node.c +661 -0
  200. data/vendor/lexbor/source/lexbor/dom/interfaces/node.h +192 -0
  201. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.c +87 -0
  202. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.h +66 -0
  203. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.c +36 -0
  204. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.h +44 -0
  205. data/vendor/lexbor/source/lexbor/dom/interfaces/text.c +63 -0
  206. data/vendor/lexbor/source/lexbor/dom/interfaces/text.h +42 -0
  207. data/vendor/lexbor/source/lexbor/encoding/base.h +218 -0
  208. data/vendor/lexbor/source/lexbor/encoding/big5.c +42839 -0
  209. data/vendor/lexbor/source/lexbor/encoding/config.cmake +12 -0
  210. data/vendor/lexbor/source/lexbor/encoding/const.h +65 -0
  211. data/vendor/lexbor/source/lexbor/encoding/decode.c +3193 -0
  212. data/vendor/lexbor/source/lexbor/encoding/decode.h +370 -0
  213. data/vendor/lexbor/source/lexbor/encoding/encode.c +1931 -0
  214. data/vendor/lexbor/source/lexbor/encoding/encode.h +377 -0
  215. data/vendor/lexbor/source/lexbor/encoding/encoding.c +252 -0
  216. data/vendor/lexbor/source/lexbor/encoding/encoding.h +475 -0
  217. data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +53883 -0
  218. data/vendor/lexbor/source/lexbor/encoding/gb18030.c +47905 -0
  219. data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +159 -0
  220. data/vendor/lexbor/source/lexbor/encoding/jis0208.c +22477 -0
  221. data/vendor/lexbor/source/lexbor/encoding/jis0212.c +15787 -0
  222. data/vendor/lexbor/source/lexbor/encoding/multi.h +53 -0
  223. data/vendor/lexbor/source/lexbor/encoding/range.c +71 -0
  224. data/vendor/lexbor/source/lexbor/encoding/range.h +34 -0
  225. data/vendor/lexbor/source/lexbor/encoding/res.c +222 -0
  226. data/vendor/lexbor/source/lexbor/encoding/res.h +34 -0
  227. data/vendor/lexbor/source/lexbor/encoding/single.c +13748 -0
  228. data/vendor/lexbor/source/lexbor/encoding/single.h +116 -0
  229. data/vendor/lexbor/source/lexbor/html/base.h +44 -0
  230. data/vendor/lexbor/source/lexbor/html/config.cmake +3 -0
  231. data/vendor/lexbor/source/lexbor/html/encoding.c +574 -0
  232. data/vendor/lexbor/source/lexbor/html/encoding.h +106 -0
  233. data/vendor/lexbor/source/lexbor/html/html.h +107 -0
  234. data/vendor/lexbor/source/lexbor/html/interface.c +165 -0
  235. data/vendor/lexbor/source/lexbor/html/interface.h +186 -0
  236. data/vendor/lexbor/source/lexbor/html/interface_res.h +4449 -0
  237. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.c +36 -0
  238. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.h +34 -0
  239. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.c +36 -0
  240. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.h +34 -0
  241. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.c +36 -0
  242. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.h +34 -0
  243. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.c +36 -0
  244. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.h +34 -0
  245. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.c +36 -0
  246. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.h +34 -0
  247. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.c +36 -0
  248. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.h +34 -0
  249. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.c +36 -0
  250. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.h +34 -0
  251. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.c +36 -0
  252. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.h +34 -0
  253. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.c +36 -0
  254. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.h +34 -0
  255. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.c +36 -0
  256. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.h +34 -0
  257. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.c +36 -0
  258. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.h +34 -0
  259. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.c +36 -0
  260. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.h +34 -0
  261. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.c +36 -0
  262. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.h +34 -0
  263. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.c +36 -0
  264. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.h +34 -0
  265. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.c +36 -0
  266. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.h +34 -0
  267. data/vendor/lexbor/source/lexbor/html/interfaces/document.c +444 -0
  268. data/vendor/lexbor/source/lexbor/html/interfaces/document.h +256 -0
  269. data/vendor/lexbor/source/lexbor/html/interfaces/element.c +64 -0
  270. data/vendor/lexbor/source/lexbor/html/interfaces/element.h +54 -0
  271. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.c +36 -0
  272. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.h +34 -0
  273. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.c +36 -0
  274. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.h +34 -0
  275. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.c +36 -0
  276. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.h +34 -0
  277. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.c +36 -0
  278. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.h +34 -0
  279. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.c +36 -0
  280. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.h +34 -0
  281. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.c +36 -0
  282. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.h +34 -0
  283. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.c +36 -0
  284. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.h +34 -0
  285. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.c +36 -0
  286. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.h +34 -0
  287. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.c +36 -0
  288. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.h +34 -0
  289. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.c +36 -0
  290. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.h +34 -0
  291. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.c +36 -0
  292. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.h +34 -0
  293. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.c +36 -0
  294. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.h +34 -0
  295. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.c +36 -0
  296. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.h +34 -0
  297. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.c +36 -0
  298. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.h +34 -0
  299. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.c +36 -0
  300. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.h +34 -0
  301. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.c +36 -0
  302. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.h +34 -0
  303. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.c +36 -0
  304. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.h +34 -0
  305. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.c +36 -0
  306. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.h +34 -0
  307. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.c +36 -0
  308. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.h +34 -0
  309. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.c +36 -0
  310. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.h +34 -0
  311. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.c +36 -0
  312. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.h +34 -0
  313. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.c +36 -0
  314. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.h +34 -0
  315. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.c +36 -0
  316. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.h +34 -0
  317. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.c +36 -0
  318. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.h +34 -0
  319. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.c +36 -0
  320. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.h +34 -0
  321. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.c +36 -0
  322. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.h +34 -0
  323. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.c +36 -0
  324. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.h +34 -0
  325. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.c +36 -0
  326. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.h +34 -0
  327. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.c +36 -0
  328. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.h +34 -0
  329. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.c +36 -0
  330. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.h +34 -0
  331. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.c +36 -0
  332. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.h +34 -0
  333. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.c +36 -0
  334. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.h +34 -0
  335. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.c +36 -0
  336. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.h +34 -0
  337. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.c +36 -0
  338. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.h +34 -0
  339. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.c +36 -0
  340. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.h +34 -0
  341. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.c +36 -0
  342. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.h +34 -0
  343. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.c +36 -0
  344. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.h +34 -0
  345. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.c +36 -0
  346. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.h +34 -0
  347. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.c +36 -0
  348. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.h +34 -0
  349. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.c +36 -0
  350. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.h +34 -0
  351. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.c +36 -0
  352. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.h +34 -0
  353. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.c +36 -0
  354. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.h +34 -0
  355. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.c +36 -0
  356. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.h +34 -0
  357. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.c +36 -0
  358. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.h +34 -0
  359. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.c +36 -0
  360. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.h +34 -0
  361. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.c +36 -0
  362. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.h +34 -0
  363. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.c +36 -0
  364. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.h +34 -0
  365. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.c +46 -0
  366. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.h +38 -0
  367. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.c +36 -0
  368. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.h +34 -0
  369. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.c +36 -0
  370. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.h +34 -0
  371. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.c +133 -0
  372. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.h +42 -0
  373. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.c +36 -0
  374. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.h +34 -0
  375. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.c +36 -0
  376. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.h +34 -0
  377. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.c +36 -0
  378. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.h +34 -0
  379. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.c +36 -0
  380. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.h +34 -0
  381. data/vendor/lexbor/source/lexbor/html/interfaces/window.c +36 -0
  382. data/vendor/lexbor/source/lexbor/html/interfaces/window.h +34 -0
  383. data/vendor/lexbor/source/lexbor/html/node.c +14 -0
  384. data/vendor/lexbor/source/lexbor/html/node.h +67 -0
  385. data/vendor/lexbor/source/lexbor/html/parser.c +469 -0
  386. data/vendor/lexbor/source/lexbor/html/parser.h +170 -0
  387. data/vendor/lexbor/source/lexbor/html/serialize.c +1510 -0
  388. data/vendor/lexbor/source/lexbor/html/serialize.h +93 -0
  389. data/vendor/lexbor/source/lexbor/html/tag.h +103 -0
  390. data/vendor/lexbor/source/lexbor/html/tag_res.h +2262 -0
  391. data/vendor/lexbor/source/lexbor/html/token.c +386 -0
  392. data/vendor/lexbor/source/lexbor/html/token.h +130 -0
  393. data/vendor/lexbor/source/lexbor/html/token_attr.c +44 -0
  394. data/vendor/lexbor/source/lexbor/html/token_attr.h +67 -0
  395. data/vendor/lexbor/source/lexbor/html/tokenizer/error.c +28 -0
  396. data/vendor/lexbor/source/lexbor/html/tokenizer/error.h +141 -0
  397. data/vendor/lexbor/source/lexbor/html/tokenizer/res.h +4956 -0
  398. data/vendor/lexbor/source/lexbor/html/tokenizer/state.c +2171 -0
  399. data/vendor/lexbor/source/lexbor/html/tokenizer/state.h +225 -0
  400. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.c +489 -0
  401. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.h +27 -0
  402. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.c +1654 -0
  403. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.h +27 -0
  404. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.c +303 -0
  405. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.h +32 -0
  406. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.c +311 -0
  407. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.h +32 -0
  408. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.c +1209 -0
  409. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.h +32 -0
  410. data/vendor/lexbor/source/lexbor/html/tokenizer.c +499 -0
  411. data/vendor/lexbor/source/lexbor/html/tokenizer.h +343 -0
  412. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.c +241 -0
  413. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.h +117 -0
  414. data/vendor/lexbor/source/lexbor/html/tree/error.c +26 -0
  415. data/vendor/lexbor/source/lexbor/html/tree/error.h +114 -0
  416. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_body.c +62 -0
  417. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_frameset.c +63 -0
  418. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_body.c +82 -0
  419. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_frameset.c +88 -0
  420. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_head.c +222 -0
  421. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_head.c +144 -0
  422. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_html.c +166 -0
  423. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/foreign_content.c +358 -0
  424. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_body.c +1974 -0
  425. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_caption.c +158 -0
  426. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_cell.c +187 -0
  427. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_column_group.c +194 -0
  428. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_frameset.c +149 -0
  429. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head.c +374 -0
  430. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head_noscript.c +121 -0
  431. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_row.c +211 -0
  432. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select.c +341 -0
  433. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select_in_table.c +115 -0
  434. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table.c +451 -0
  435. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_body.c +208 -0
  436. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_text.c +127 -0
  437. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_template.c +189 -0
  438. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/initial.c +411 -0
  439. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/text.c +61 -0
  440. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode.h +135 -0
  441. data/vendor/lexbor/source/lexbor/html/tree/open_elements.c +251 -0
  442. data/vendor/lexbor/source/lexbor/html/tree/open_elements.h +105 -0
  443. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.c +10 -0
  444. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.h +100 -0
  445. data/vendor/lexbor/source/lexbor/html/tree.c +1726 -0
  446. data/vendor/lexbor/source/lexbor/html/tree.h +431 -0
  447. data/vendor/lexbor/source/lexbor/html/tree_res.h +111 -0
  448. data/vendor/lexbor/source/lexbor/ns/base.h +32 -0
  449. data/vendor/lexbor/source/lexbor/ns/config.cmake +2 -0
  450. data/vendor/lexbor/source/lexbor/ns/const.h +37 -0
  451. data/vendor/lexbor/source/lexbor/ns/ns.c +154 -0
  452. data/vendor/lexbor/source/lexbor/ns/ns.h +66 -0
  453. data/vendor/lexbor/source/lexbor/ns/res.h +97 -0
  454. data/vendor/lexbor/source/lexbor/ports/posix/config.cmake +11 -0
  455. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/fs.c +236 -0
  456. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/memory.c +33 -0
  457. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/perf.c +158 -0
  458. data/vendor/lexbor/source/lexbor/ports/windows_nt/config.cmake +18 -0
  459. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/fs.c +239 -0
  460. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/memory.c +33 -0
  461. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/perf.c +81 -0
  462. data/vendor/lexbor/source/lexbor/selectors/base.h +30 -0
  463. data/vendor/lexbor/source/lexbor/selectors/config.cmake +2 -0
  464. data/vendor/lexbor/source/lexbor/selectors/selectors.c +1591 -0
  465. data/vendor/lexbor/source/lexbor/selectors/selectors.h +71 -0
  466. data/vendor/lexbor/source/lexbor/tag/base.h +32 -0
  467. data/vendor/lexbor/source/lexbor/tag/config.cmake +2 -0
  468. data/vendor/lexbor/source/lexbor/tag/const.h +225 -0
  469. data/vendor/lexbor/source/lexbor/tag/res.h +562 -0
  470. data/vendor/lexbor/source/lexbor/tag/tag.c +144 -0
  471. data/vendor/lexbor/source/lexbor/tag/tag.h +123 -0
  472. data/vendor/lexbor/source/lexbor/utils/base.h +32 -0
  473. data/vendor/lexbor/source/lexbor/utils/config.cmake +2 -0
  474. data/vendor/lexbor/source/lexbor/utils/http.c +534 -0
  475. data/vendor/lexbor/source/lexbor/utils/http.h +90 -0
  476. data/vendor/lexbor/source/lexbor/utils/utils.h +15 -0
  477. data/vendor/lexbor/source/lexbor/utils/warc.c +817 -0
  478. data/vendor/lexbor/source/lexbor/utils/warc.h +126 -0
  479. data/vendor/lexbor/utils/lexbor/css/selectors/pseudo.py +231 -0
  480. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/const.h +21 -0
  481. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/res.h +26 -0
  482. data/vendor/lexbor/utils/lexbor/css/syntax/definitions.py +49 -0
  483. data/vendor/lexbor/utils/lexbor/css/syntax/token_res.py +54 -0
  484. data/vendor/lexbor/utils/lexbor/css/syntax/tokenizer_code_map.py +36 -0
  485. data/vendor/lexbor/version +1 -0
  486. metadata +542 -0
@@ -0,0 +1,1591 @@
1
+ /*
2
+ * Copyright (C) 2021 Alexander Borisov
3
+ *
4
+ * Author: Alexander Borisov <borisov@lexbor.com>
5
+ */
6
+
7
+ #include "lexbor/selectors/selectors.h"
8
+
9
+ #include <math.h>
10
+
11
+
12
+ static lxb_selectors_entry_t *
13
+ lxb_selectors_find_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root,
14
+ lxb_selectors_entry_t *entry,
15
+ lxb_css_selector_t *selector,
16
+ lxb_selectors_cb_f cb, void *ctx);
17
+
18
+ static lxb_selectors_entry_child_t *
19
+ lxb_selectors_next(lxb_selectors_t *selectors, lxb_dom_node_t *root,
20
+ lxb_selectors_entry_child_t *child,
21
+ lxb_css_selector_list_t *list,
22
+ lxb_selectors_cb_f cb, void *ctx);
23
+
24
+ static lxb_selectors_entry_child_t *
25
+ lxb_selectors_current(lxb_selectors_t *selectors, lxb_dom_node_t *root,
26
+ lxb_selectors_entry_child_t *child,
27
+ lxb_css_selector_list_t *list,
28
+ lxb_selectors_cb_f cb, void *ctx);
29
+
30
+ static lxb_selectors_entry_t *
31
+ lxb_selectors_next_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root,
32
+ lxb_selectors_entry_t *entry,
33
+ lxb_css_selector_t *selector,
34
+ lxb_selectors_cb_f cb, void *ctx);
35
+
36
+ static lxb_status_t
37
+ lxb_selectors_find_by(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
38
+ lxb_dom_node_t *root, lxb_dom_node_t *node,
39
+ lxb_css_selector_t *selector, lxb_selectors_cb_f cb, void *ctx);
40
+
41
+ static bool
42
+ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
43
+ lxb_css_selector_t *selector, lxb_dom_node_t *node);
44
+
45
+ static bool
46
+ lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src,
47
+ bool quirks);
48
+
49
+ static bool
50
+ lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node);
51
+
52
+ static bool
53
+ lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors,
54
+ lxb_css_selector_t *selector,
55
+ lxb_dom_node_t *node,
56
+ lxb_selectors_entry_t *entry);
57
+
58
+ static bool
59
+ lxb_selectors_pseudo_element(lxb_selectors_t *selectors,
60
+ lxb_css_selector_t *selector,
61
+ lxb_dom_node_t *node);
62
+
63
+ static bool
64
+ lxb_selectors_pseudo_element_function(lxb_selectors_t *selectors,
65
+ lxb_css_selector_t *selector,
66
+ lxb_dom_node_t *node);
67
+
68
+ static bool
69
+ lxb_selectors_pseudo_class_disabled(lxb_dom_node_t *node);
70
+
71
+ static bool
72
+ lxb_selectors_pseudo_class_first_child(lxb_dom_node_t *node);
73
+
74
+ static bool
75
+ lxb_selectors_pseudo_class_first_of_type(lxb_dom_node_t *node);
76
+
77
+ static bool
78
+ lxb_selectors_pseudo_class_last_child(lxb_dom_node_t *node);
79
+
80
+ static bool
81
+ lxb_selectors_pseudo_class_last_of_type(lxb_dom_node_t *node);
82
+
83
+ static bool
84
+ lxb_selectors_pseudo_class_read_write(lxb_dom_node_t *node);
85
+
86
+ static lxb_status_t
87
+ lxb_selectors_first_match(lxb_dom_node_t *node,
88
+ lxb_css_selector_specificity_t *spec, void *ctx);
89
+
90
+
91
+ lxb_selectors_t *
92
+ lxb_selectors_create(void)
93
+ {
94
+ return lexbor_calloc(1, sizeof(lxb_selectors_t));
95
+ }
96
+
97
+ lxb_status_t
98
+ lxb_selectors_init(lxb_selectors_t *selectors)
99
+ {
100
+ lxb_status_t status;
101
+
102
+ if (selectors == NULL) {
103
+ return LXB_STATUS_ERROR_INCOMPLETE_OBJECT;
104
+ }
105
+
106
+ selectors->objs = lexbor_dobject_create();
107
+ status = lexbor_dobject_init(selectors->objs,
108
+ 128, sizeof(lxb_selectors_entry_t));
109
+ if (status != LXB_STATUS_OK) {
110
+ return status;
111
+ }
112
+
113
+ selectors->chld = lexbor_dobject_create();
114
+ status = lexbor_dobject_init(selectors->chld,
115
+ 32, sizeof(lxb_selectors_entry_child_t));
116
+ if (status != LXB_STATUS_OK) {
117
+ return status;
118
+ }
119
+
120
+ return LXB_STATUS_OK;
121
+ }
122
+
123
+ void
124
+ lxb_selectors_clean(lxb_selectors_t *selectors)
125
+ {
126
+ lexbor_dobject_clean(selectors->objs);
127
+ lexbor_dobject_clean(selectors->chld);
128
+ }
129
+
130
+ lxb_selectors_t *
131
+ lxb_selectors_destroy(lxb_selectors_t *selectors, bool self_destroy)
132
+ {
133
+ if (selectors == NULL) {
134
+ return NULL;
135
+ }
136
+
137
+ selectors->objs = lexbor_dobject_destroy(selectors->objs, true);
138
+ selectors->chld = lexbor_dobject_destroy(selectors->chld, true);
139
+
140
+ if (self_destroy) {
141
+ return lexbor_free(selectors);
142
+ }
143
+
144
+ return selectors;
145
+ }
146
+
147
+
148
+ lxb_inline lxb_dom_node_t *
149
+ lxb_selectors_descendant(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
150
+ lxb_css_selector_t *selector, lxb_dom_node_t *root,
151
+ lxb_dom_node_t *node)
152
+ {
153
+ do {
154
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT &&
155
+ lxb_selectors_match(selectors, entry, selector, node))
156
+ {
157
+ return node;
158
+ }
159
+
160
+ if (node->first_child != NULL) {
161
+ node = node->first_child;
162
+ }
163
+ else {
164
+ while (node != root && node->next == NULL) {
165
+ node = node->parent;
166
+ }
167
+
168
+ if (node == root) {
169
+ return NULL;
170
+ }
171
+
172
+ node = node->next;
173
+ }
174
+ }
175
+ while (true);
176
+ }
177
+
178
+ lxb_inline lxb_dom_node_t *
179
+ lxb_selectors_descendant_next(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
180
+ lxb_css_selector_t *selector, lxb_dom_node_t *root,
181
+ lxb_dom_node_t *node)
182
+ {
183
+ do {
184
+ if (node->first_child != NULL) {
185
+ node = node->first_child;
186
+ }
187
+ else {
188
+ while (node != root && node->next == NULL) {
189
+ node = node->parent;
190
+ }
191
+
192
+ if (node == root) {
193
+ return NULL;
194
+ }
195
+
196
+ node = node->next;
197
+ }
198
+
199
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT &&
200
+ lxb_selectors_match(selectors, entry, selector, node))
201
+ {
202
+ return node;
203
+ }
204
+ }
205
+ while (true);
206
+ }
207
+
208
+ lxb_inline lxb_dom_node_t *
209
+ lxb_selectors_close(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
210
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
211
+ {
212
+ if (lxb_selectors_match(selectors, entry, selector, node)) {
213
+ return node;
214
+ }
215
+
216
+ return NULL;
217
+ }
218
+
219
+ lxb_inline lxb_dom_node_t *
220
+ lxb_selectors_child(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
221
+ lxb_css_selector_t *selector, lxb_dom_node_t *root,
222
+ lxb_dom_node_t *node)
223
+ {
224
+ node = root->first_child;
225
+
226
+ while (node != NULL) {
227
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT &&
228
+ lxb_selectors_match(selectors, entry, selector, node))
229
+ {
230
+ return node;
231
+ }
232
+
233
+ node = node->next;
234
+ }
235
+
236
+ return NULL;
237
+ }
238
+
239
+ lxb_inline lxb_dom_node_t *
240
+ lxb_selectors_child_next(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
241
+ lxb_css_selector_t *selector, lxb_dom_node_t *root,
242
+ lxb_dom_node_t *node)
243
+ {
244
+ node = node->next;
245
+
246
+ while (node != NULL) {
247
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT &&
248
+ lxb_selectors_match(selectors, entry, selector, node))
249
+ {
250
+ return node;
251
+ }
252
+
253
+ node = node->next;
254
+ }
255
+
256
+ return NULL;
257
+ }
258
+
259
+ lxb_inline lxb_dom_node_t *
260
+ lxb_selectors_sibling(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
261
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
262
+ {
263
+ node = node->next;
264
+
265
+ do {
266
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) {
267
+ if (lxb_selectors_match(selectors, entry, selector, node)) {
268
+ return node;
269
+ }
270
+
271
+ return NULL;
272
+ }
273
+
274
+ node = node->next;
275
+ }
276
+ while (node != NULL);
277
+
278
+ return NULL;
279
+ }
280
+
281
+ lxb_inline lxb_dom_node_t *
282
+ lxb_selectors_following(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
283
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
284
+ {
285
+ node = node->next;
286
+
287
+ while (node != NULL) {
288
+ if (node->type == LXB_DOM_NODE_TYPE_ELEMENT &&
289
+ lxb_selectors_match(selectors, entry, selector, node))
290
+ {
291
+ return node;
292
+ }
293
+
294
+ node = node->next;
295
+ }
296
+
297
+ return NULL;
298
+ }
299
+
300
+ lxb_inline bool
301
+ lxb_selectors_anb_calc(lxb_css_selector_anb_of_t *anb, size_t index)
302
+ {
303
+ double num;
304
+
305
+ if (anb->anb.a == 0) {
306
+ if (anb->anb.b >= 0 && anb->anb.b == index) {
307
+ return true;
308
+ }
309
+ }
310
+ else {
311
+ num = ((double) index - (double) anb->anb.b) / (double) anb->anb.a;
312
+
313
+ if (num >= 0.0f && (num - trunc(num)) == 0.0f) {
314
+ return true;
315
+ }
316
+ }
317
+
318
+ return false;
319
+ }
320
+
321
+ lxb_status_t
322
+ lxb_selectors_find(lxb_selectors_t *selectors, lxb_dom_node_t *root,
323
+ lxb_css_selector_list_t *list, lxb_selectors_cb_f cb, void *ctx)
324
+ {
325
+ lxb_selectors_entry_t *child;
326
+
327
+ while (list != NULL) {
328
+ child = lxb_selectors_next_by_selector(selectors, root, NULL,
329
+ list->first, cb, ctx);
330
+ if (child == NULL) {
331
+ return LXB_STATUS_ERROR;
332
+ }
333
+
334
+ list = list->next;
335
+ }
336
+
337
+ lxb_selectors_clean(selectors);
338
+
339
+ return LXB_STATUS_OK;
340
+ }
341
+
342
+ static lxb_selectors_entry_t *
343
+ lxb_selectors_find_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root,
344
+ lxb_selectors_entry_t *entry,
345
+ lxb_css_selector_t *selector,
346
+ lxb_selectors_cb_f cb, void *ctx)
347
+ {
348
+ lxb_status_t status;
349
+ lxb_dom_node_t *node = root, *base = root;
350
+
351
+ if (entry == NULL) {
352
+ entry = lexbor_dobject_calloc(selectors->objs);
353
+ if (entry == NULL) {
354
+ return NULL;
355
+ }
356
+
357
+ entry->selector = selector;
358
+ }
359
+
360
+ switch (selector->combinator) {
361
+ case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT:
362
+ node = lxb_selectors_descendant(selectors, entry, selector,
363
+ base, node);
364
+ break;
365
+
366
+ case LXB_CSS_SELECTOR_COMBINATOR_CLOSE:
367
+ node = lxb_selectors_close(selectors, entry, selector, node);
368
+ break;
369
+
370
+ case LXB_CSS_SELECTOR_COMBINATOR_CHILD:
371
+ node = lxb_selectors_child(selectors, entry, selector, base, node);
372
+ break;
373
+
374
+ case LXB_CSS_SELECTOR_COMBINATOR_SIBLING:
375
+ node = lxb_selectors_sibling(selectors, entry, selector, base);
376
+ break;
377
+
378
+ case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING:
379
+ node = lxb_selectors_following(selectors, entry, selector, node);
380
+ break;
381
+
382
+ case LXB_CSS_SELECTOR_COMBINATOR_CELL:
383
+ default:
384
+ return NULL;
385
+ }
386
+
387
+ status = lxb_selectors_find_by(selectors, entry, root, node, selector,
388
+ cb, ctx);
389
+ if (status != LXB_STATUS_OK) {
390
+ return NULL;
391
+ }
392
+
393
+ return entry;
394
+ }
395
+
396
+ static lxb_selectors_entry_child_t *
397
+ lxb_selectors_next(lxb_selectors_t *selectors, lxb_dom_node_t *root,
398
+ lxb_selectors_entry_child_t *child,
399
+ lxb_css_selector_list_t *list,
400
+ lxb_selectors_cb_f cb, void *ctx)
401
+ {
402
+ lxb_selectors_entry_child_t *chld_root = child;
403
+
404
+ if (list == NULL) {
405
+ return NULL;
406
+ }
407
+
408
+ if (child == NULL) {
409
+ child = lexbor_dobject_calloc(selectors->chld);
410
+ if (child == NULL) {
411
+ goto failed;
412
+ }
413
+
414
+ chld_root = child;
415
+ }
416
+
417
+ do {
418
+ child->entry = lxb_selectors_next_by_selector(selectors, root,
419
+ child->entry, list->first,
420
+ cb, ctx);
421
+ if (child->entry == NULL) {
422
+ return NULL;
423
+ }
424
+
425
+ if (list->next == NULL) {
426
+ return chld_root;
427
+ }
428
+
429
+ if (child->next == NULL) {
430
+ child->next = lexbor_dobject_calloc(selectors->chld);
431
+ if (child->next == NULL) {
432
+ goto failed;
433
+ }
434
+ }
435
+
436
+ child = child->next;
437
+ list = list->next;
438
+ }
439
+ while (true);
440
+
441
+ return chld_root;
442
+
443
+ failed:
444
+
445
+ selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION;
446
+
447
+ return NULL;
448
+ }
449
+
450
+ static lxb_selectors_entry_child_t *
451
+ lxb_selectors_current(lxb_selectors_t *selectors, lxb_dom_node_t *root,
452
+ lxb_selectors_entry_child_t *child,
453
+ lxb_css_selector_list_t *list,
454
+ lxb_selectors_cb_f cb, void *ctx)
455
+ {
456
+ lxb_selectors_entry_child_t *chld_root = child;
457
+
458
+ if (list == NULL) {
459
+ return NULL;
460
+ }
461
+
462
+ if (child == NULL) {
463
+ child = lexbor_dobject_calloc(selectors->chld);
464
+ if (child == NULL) {
465
+ goto failed;
466
+ }
467
+
468
+ chld_root = child;
469
+ }
470
+
471
+ do {
472
+ child->entry = lxb_selectors_find_by_selector(selectors, root,
473
+ child->entry, list->first,
474
+ cb, ctx);
475
+ if (child->entry == NULL) {
476
+ return NULL;
477
+ }
478
+
479
+ if (list->next == NULL) {
480
+ return chld_root;
481
+ }
482
+
483
+ if (child->next == NULL) {
484
+ child->next = lexbor_dobject_calloc(selectors->chld);
485
+ if (child->next == NULL) {
486
+ goto failed;
487
+ }
488
+ }
489
+
490
+ child = child->next;
491
+ list = list->next;
492
+ }
493
+ while (true);
494
+
495
+ return chld_root;
496
+
497
+ failed:
498
+
499
+ selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION;
500
+
501
+ return NULL;
502
+ }
503
+
504
+ static lxb_selectors_entry_t *
505
+ lxb_selectors_next_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root,
506
+ lxb_selectors_entry_t *entry,
507
+ lxb_css_selector_t *selector,
508
+ lxb_selectors_cb_f cb, void *ctx)
509
+ {
510
+ lxb_status_t status;
511
+ lxb_dom_node_t *node = root, *base = root;
512
+
513
+ if (entry == NULL) {
514
+ entry = lexbor_dobject_calloc(selectors->objs);
515
+ if (entry == NULL) {
516
+ selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION;
517
+ return NULL;
518
+ }
519
+
520
+ entry->selector = selector;
521
+ }
522
+
523
+ switch (selector->combinator) {
524
+ case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT:
525
+ node = lxb_selectors_descendant_next(selectors, entry, selector,
526
+ base, node);
527
+ break;
528
+
529
+ case LXB_CSS_SELECTOR_COMBINATOR_CLOSE:
530
+ node = lxb_selectors_close(selectors, entry, selector, node);
531
+ break;
532
+
533
+ case LXB_CSS_SELECTOR_COMBINATOR_CHILD:
534
+ node = lxb_selectors_child(selectors, entry, selector, base, node);
535
+ break;
536
+
537
+ case LXB_CSS_SELECTOR_COMBINATOR_SIBLING:
538
+ node = lxb_selectors_sibling(selectors, entry, selector, base);
539
+ break;
540
+
541
+ case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING:
542
+ node = lxb_selectors_following(selectors, entry, selector, node);
543
+ break;
544
+
545
+ case LXB_CSS_SELECTOR_COMBINATOR_CELL:
546
+ default:
547
+ selectors->status = LXB_STATUS_ERROR;
548
+ return NULL;
549
+ }
550
+
551
+ status = lxb_selectors_find_by(selectors, entry, root, node, selector,
552
+ cb, ctx);
553
+ if (status != LXB_STATUS_OK) {
554
+ return NULL;
555
+ }
556
+
557
+ return entry;
558
+ }
559
+
560
+ static lxb_status_t
561
+ lxb_selectors_find_by(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
562
+ lxb_dom_node_t *root, lxb_dom_node_t *node,
563
+ lxb_css_selector_t *selector, lxb_selectors_cb_f cb, void *ctx)
564
+ {
565
+ lxb_status_t status;
566
+ lxb_selectors_entry_t *next;
567
+ lxb_dom_node_t *base = root;
568
+
569
+ do {
570
+ if (node == NULL) {
571
+ if (entry->prev == NULL) {
572
+ return LXB_STATUS_OK;
573
+ }
574
+
575
+ do {
576
+ entry = entry->prev;
577
+ selector = entry->selector;
578
+ }
579
+ while (entry->prev != NULL
580
+ && selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE);
581
+
582
+ if (selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) {
583
+ return LXB_STATUS_OK;
584
+ }
585
+
586
+ node = entry->node;
587
+ base = (entry->prev != NULL) ? entry->prev->node : root;
588
+
589
+ goto next;
590
+ }
591
+
592
+ if (selector->next == NULL) {
593
+ status = cb(node, NULL, ctx);
594
+ if (status != LXB_STATUS_OK) {
595
+ if (status == LXB_STATUS_STOP) {
596
+ return LXB_STATUS_OK;
597
+ }
598
+
599
+ return status;
600
+ }
601
+
602
+ if (selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) {
603
+ while (entry->prev != NULL
604
+ && entry->selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE)
605
+ {
606
+ entry = entry->prev;
607
+ }
608
+
609
+ selector = entry->selector;
610
+ node = entry->node;
611
+ }
612
+
613
+ base = (entry->prev != NULL) ? entry->prev->node : root;
614
+
615
+ goto next;
616
+ }
617
+
618
+ base = node;
619
+ entry->node = node;
620
+
621
+ if (entry->next == NULL) {
622
+ next = lexbor_dobject_calloc(selectors->objs);
623
+ if (next == NULL) {
624
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
625
+ }
626
+
627
+ next->selector = selector->next;
628
+ next->prev = entry;
629
+ entry->next = next;
630
+ entry = next;
631
+ }
632
+ else {
633
+ entry = entry->next;
634
+ }
635
+
636
+ selector = entry->selector;
637
+
638
+ switch (selector->combinator) {
639
+ case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT:
640
+ node = lxb_selectors_descendant_next(selectors, entry, selector,
641
+ base, node);
642
+ break;
643
+
644
+ case LXB_CSS_SELECTOR_COMBINATOR_CLOSE:
645
+ node = lxb_selectors_close(selectors, entry, selector, node);
646
+ break;
647
+
648
+ case LXB_CSS_SELECTOR_COMBINATOR_CHILD:
649
+ node = lxb_selectors_child(selectors, entry, selector,
650
+ base, node);
651
+ break;
652
+
653
+ case LXB_CSS_SELECTOR_COMBINATOR_SIBLING:
654
+ node = lxb_selectors_sibling(selectors, entry, selector, node);
655
+ break;
656
+
657
+ case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING:
658
+ node = lxb_selectors_following(selectors, entry,
659
+ selector, node);
660
+ break;
661
+
662
+ case LXB_CSS_SELECTOR_COMBINATOR_CELL:
663
+ default:
664
+ return LXB_STATUS_ERROR;
665
+ }
666
+
667
+ continue;
668
+
669
+ next:
670
+
671
+ switch (selector->combinator) {
672
+ case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT:
673
+ node = lxb_selectors_descendant_next(selectors, entry, selector,
674
+ base, node);
675
+ break;
676
+
677
+ case LXB_CSS_SELECTOR_COMBINATOR_CLOSE:
678
+ node = lxb_selectors_close(selectors, entry, selector, node);
679
+ break;
680
+
681
+ case LXB_CSS_SELECTOR_COMBINATOR_CHILD:
682
+ node = lxb_selectors_child_next(selectors, entry, selector,
683
+ base, node);
684
+ break;
685
+
686
+ case LXB_CSS_SELECTOR_COMBINATOR_SIBLING:
687
+ node = NULL;
688
+ break;
689
+
690
+ case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING:
691
+ node = lxb_selectors_following(selectors, entry,
692
+ selector, node);
693
+ break;
694
+
695
+ case LXB_CSS_SELECTOR_COMBINATOR_CELL:
696
+ default:
697
+ return LXB_STATUS_ERROR;
698
+ }
699
+ }
700
+ while (true);
701
+
702
+ return LXB_STATUS_OK;
703
+ }
704
+
705
+ static bool
706
+ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
707
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
708
+ {
709
+ bool res, ins;
710
+ const lexbor_str_t *trg, *src;
711
+ lxb_tag_id_t tag_id;
712
+ lxb_dom_attr_t *dom_attr;
713
+ lxb_dom_element_t *element;
714
+ const lxb_dom_attr_data_t *attr_data;
715
+ lxb_css_selector_attribute_t *attr;
716
+
717
+ static const lexbor_str_t lxb_blank_str = {
718
+ .data = (lxb_char_t *) "",
719
+ .length = 0
720
+ };
721
+
722
+ switch (selector->type) {
723
+ case LXB_CSS_SELECTOR_TYPE_ANY:
724
+ return true;
725
+
726
+ case LXB_CSS_SELECTOR_TYPE_ELEMENT:
727
+ if (entry->id == 0) {
728
+ tag_id = lxb_tag_id_by_name(node->owner_document->tags,
729
+ selector->name.data, selector->name.length);
730
+ if (tag_id == LXB_TAG__UNDEF) {
731
+ return false;
732
+ }
733
+
734
+ entry->id = tag_id;
735
+ }
736
+
737
+ if (node->local_name == entry->id) {
738
+ return true;
739
+ }
740
+
741
+ break;
742
+
743
+ case LXB_CSS_SELECTOR_TYPE_ID:
744
+ element = lxb_dom_interface_element(node);
745
+
746
+ if (element->attr_id == NULL || element->attr_id->value == NULL) {
747
+ return false;
748
+ }
749
+
750
+ trg = element->attr_id->value;
751
+ src = &selector->name;
752
+
753
+ if (trg->length == src->length
754
+ && lexbor_str_data_ncasecmp(trg->data, src->data, src->length))
755
+ {
756
+ return true;
757
+ }
758
+
759
+ return false;
760
+
761
+ case LXB_CSS_SELECTOR_TYPE_CLASS:
762
+ element = lxb_dom_interface_element(node);
763
+
764
+ if (element->attr_class == NULL || element->attr_class->value == NULL) {
765
+ return false;
766
+ }
767
+
768
+ return lxb_selectors_match_class(element->attr_class->value,
769
+ &selector->name, true);
770
+
771
+ case LXB_CSS_SELECTOR_TYPE_ATTRIBUTE:
772
+ element = lxb_dom_interface_element(node);
773
+ attr = &selector->u.attribute;
774
+
775
+ if (entry->id == 0) {
776
+ attr_data = lxb_dom_attr_data_by_local_name(node->owner_document->attrs,
777
+ selector->name.data, selector->name.length);
778
+ if (attr_data == NULL) {
779
+ return false;
780
+ }
781
+
782
+ entry->id = attr_data->attr_id;
783
+ }
784
+
785
+ dom_attr = lxb_dom_element_attr_by_id(element, entry->id);
786
+ if (dom_attr == NULL) {
787
+ return false;
788
+ }
789
+
790
+ trg = dom_attr->value;
791
+ src = &attr->value;
792
+
793
+ if (src->data == NULL) {
794
+ return true;
795
+ }
796
+
797
+ if (trg == NULL) {
798
+ trg = &lxb_blank_str;
799
+ }
800
+
801
+ ins = attr->modifier == LXB_CSS_SELECTOR_MODIFIER_I;
802
+
803
+ switch (attr->match) {
804
+ case LXB_CSS_SELECTOR_MATCH_EQUAL: /* = */
805
+ if (trg->length == src->length) {
806
+ if (ins) {
807
+ return lexbor_str_data_ncasecmp(trg->data, src->data,
808
+ src->length);
809
+ }
810
+
811
+ return lexbor_str_data_ncmp(trg->data, src->data,
812
+ src->length);
813
+ }
814
+
815
+ return false;
816
+
817
+ case LXB_CSS_SELECTOR_MATCH_INCLUDE: /* ~= */
818
+ return lxb_selectors_match_class(trg, src, ins);
819
+
820
+ case LXB_CSS_SELECTOR_MATCH_DASH: /* |= */
821
+ if (trg->length == src->length) {
822
+ if (ins) {
823
+ return lexbor_str_data_ncasecmp(trg->data, src->data,
824
+ src->length);
825
+ }
826
+
827
+ return lexbor_str_data_ncmp(trg->data, src->data,
828
+ src->length);
829
+ }
830
+
831
+ if (trg->length > src->length) {
832
+ if (ins) {
833
+ res = lexbor_str_data_ncasecmp(trg->data,
834
+ src->data, src->length);
835
+ }
836
+ else {
837
+ res = lexbor_str_data_ncmp(trg->data,
838
+ src->data, src->length);
839
+ }
840
+
841
+ if (res && trg->data[src->length] == '-') {
842
+ return true;
843
+ }
844
+ }
845
+
846
+ return false;
847
+
848
+ case LXB_CSS_SELECTOR_MATCH_PREFIX: /* ^= */
849
+ if (src->length != 0 && trg->length >= src->length) {
850
+ if (ins) {
851
+ return lexbor_str_data_ncasecmp(trg->data, src->data,
852
+ src->length);
853
+ }
854
+
855
+ return lexbor_str_data_ncmp(trg->data, src->data,
856
+ src->length);
857
+ }
858
+
859
+ return false;
860
+
861
+ case LXB_CSS_SELECTOR_MATCH_SUFFIX: /* $= */
862
+ if (src->length != 0 && trg->length >= src->length) {
863
+ size_t dif = trg->length - src->length;
864
+
865
+ if (ins) {
866
+ return lexbor_str_data_ncasecmp(trg->data + dif,
867
+ src->data, src->length);
868
+ }
869
+
870
+ return lexbor_str_data_ncmp(trg->data + dif, src->data,
871
+ src->length);
872
+ }
873
+
874
+ return false;
875
+
876
+ case LXB_CSS_SELECTOR_MATCH_SUBSTRING: /* *= */
877
+ if (src->length == 0) {
878
+ return false;
879
+ }
880
+
881
+ if (ins) {
882
+ return lexbor_str_data_ncasecmp_contain(trg->data, trg->length,
883
+ src->data, src->length);
884
+ }
885
+
886
+ return lexbor_str_data_ncmp_contain(trg->data, trg->length,
887
+ src->data, src->length);
888
+
889
+ default:
890
+ return false;
891
+ }
892
+
893
+ case LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS:
894
+ return lxb_selectors_pseudo_class(selector, node);
895
+
896
+ case LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION:
897
+ return lxb_selectors_pseudo_class_function(selectors, selector,
898
+ node, entry);
899
+
900
+ case LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT:
901
+ return lxb_selectors_pseudo_element(selectors, selector, node);
902
+
903
+ case LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT_FUNCTION:
904
+ return lxb_selectors_pseudo_element_function(selectors, selector, node);
905
+
906
+ default:
907
+ break;
908
+ }
909
+
910
+ return false;
911
+ }
912
+
913
+ static bool
914
+ lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src,
915
+ bool quirks)
916
+ {
917
+ lxb_char_t chr;
918
+
919
+ if (target->length < src->length) {
920
+ return false;
921
+ }
922
+
923
+ bool is_it = false;
924
+
925
+ const lxb_char_t *data = target->data;
926
+ const lxb_char_t *pos = data;
927
+ const lxb_char_t *end = data + target->length;
928
+
929
+ for (; data < end; data++) {
930
+ chr = *data;
931
+
932
+ if (lexbor_utils_whitespace(chr, ==, ||)) {
933
+
934
+ if ((data - pos) == src->length) {
935
+ if (quirks) {
936
+ is_it = lexbor_str_data_ncasecmp(pos, src->data, src->length);
937
+ }
938
+ else {
939
+ is_it = lexbor_str_data_ncmp(pos, src->data, src->length);
940
+ }
941
+
942
+ if (is_it) {
943
+ return true;
944
+ }
945
+ }
946
+
947
+ if ((size_t) (end - data) < src->length) {
948
+ return false;
949
+ }
950
+
951
+ pos = data + 1;
952
+ }
953
+ }
954
+
955
+ if ((end - pos) == src->length && src->length != 0) {
956
+ if (quirks) {
957
+ is_it = lexbor_str_data_ncasecmp(pos, src->data, src->length);
958
+ }
959
+ else {
960
+ is_it = lexbor_str_data_ncmp(pos, src->data, src->length);
961
+ }
962
+ }
963
+
964
+ return is_it;
965
+ }
966
+
967
+ static bool
968
+ lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node)
969
+ {
970
+ lexbor_str_t *str;
971
+ lxb_dom_attr_t *attr;
972
+ lxb_dom_node_t *root;
973
+ lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo;
974
+
975
+ static const lxb_char_t checkbox[] = "checkbox";
976
+ static const size_t checkbox_length = sizeof(checkbox) / sizeof(lxb_char_t) - 1;
977
+
978
+ static const lxb_char_t radio[] = "radio";
979
+ static const size_t radio_length = sizeof(radio) / sizeof(lxb_char_t) - 1;
980
+
981
+ switch (pseudo->type) {
982
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ACTIVE:
983
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
984
+ LXB_DOM_ATTR_ACTIVE);
985
+ return attr != NULL;
986
+
987
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ANY_LINK:
988
+ if(node->local_name == LXB_TAG_A ||
989
+ node->local_name == LXB_TAG_AREA ||
990
+ node->local_name == LXB_TAG_MAP)
991
+ {
992
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
993
+ LXB_DOM_ATTR_HREF);
994
+ return attr != NULL;
995
+ }
996
+
997
+ return false;
998
+
999
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_BLANK:
1000
+ return lxb_dom_node_is_empty(node);
1001
+
1002
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_CHECKED:
1003
+ if (node->local_name == LXB_TAG_INPUT) {
1004
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1005
+ LXB_DOM_ATTR_TYPE);
1006
+ if (attr == NULL) {
1007
+ return false;
1008
+ }
1009
+
1010
+ if (attr->value == NULL) {
1011
+ return false;
1012
+ }
1013
+
1014
+ str = attr->value;
1015
+
1016
+ if(str->length == 8) {
1017
+ if (lexbor_str_data_ncasecmp(checkbox, str->data, checkbox_length)) {
1018
+ goto check;
1019
+ }
1020
+ }
1021
+ else if(str->length == 5) {
1022
+ if (lexbor_str_data_ncasecmp(radio, str->data, radio_length)) {
1023
+ goto check;
1024
+ }
1025
+ }
1026
+ }
1027
+ else if(node->local_name == LXB_TAG_OPTION) {
1028
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1029
+ LXB_DOM_ATTR_SELECTED);
1030
+ if (attr != NULL) {
1031
+ return true;
1032
+ }
1033
+ }
1034
+ else if(node->local_name >= LXB_TAG__LAST_ENTRY) {
1035
+ goto check;
1036
+ }
1037
+
1038
+ return false;
1039
+
1040
+ check:
1041
+
1042
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1043
+ LXB_DOM_ATTR_CHECKED);
1044
+ if (attr != NULL) {
1045
+ return true;
1046
+ }
1047
+
1048
+ return false;
1049
+
1050
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_CURRENT:
1051
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_DEFAULT:
1052
+ return false;
1053
+
1054
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_DISABLED:
1055
+ return lxb_selectors_pseudo_class_disabled(node);
1056
+
1057
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_EMPTY:
1058
+ root = node;
1059
+ node = node->first_child;
1060
+
1061
+ while (node != NULL) {
1062
+ if (node->local_name != LXB_TAG__EM_COMMENT) {
1063
+ return false;
1064
+ }
1065
+
1066
+ if (node->first_child != NULL) {
1067
+ node = node->first_child;
1068
+ }
1069
+ else {
1070
+ while (node != root && node->next == NULL) {
1071
+ node = node->parent;
1072
+ }
1073
+
1074
+ if (node == root) {
1075
+ break;
1076
+ }
1077
+
1078
+ node = node->next;
1079
+ }
1080
+ }
1081
+
1082
+ return true;
1083
+
1084
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ENABLED:
1085
+ return !lxb_selectors_pseudo_class_disabled(node);
1086
+
1087
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FIRST_CHILD:
1088
+ return lxb_selectors_pseudo_class_first_child(node);
1089
+
1090
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FIRST_OF_TYPE:
1091
+ return lxb_selectors_pseudo_class_first_of_type(node);
1092
+
1093
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FOCUS:
1094
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1095
+ LXB_DOM_ATTR_FOCUS);
1096
+ return attr != NULL;
1097
+
1098
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FOCUS_VISIBLE:
1099
+ break;
1100
+
1101
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FOCUS_WITHIN:
1102
+ break;
1103
+
1104
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FULLSCREEN:
1105
+ break;
1106
+
1107
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUTURE:
1108
+ break;
1109
+
1110
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_HOVER:
1111
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1112
+ LXB_DOM_ATTR_HOVER);
1113
+ return attr != NULL;
1114
+
1115
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_IN_RANGE:
1116
+ break;
1117
+
1118
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_INDETERMINATE:
1119
+ break;
1120
+
1121
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_INVALID:
1122
+ break;
1123
+
1124
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_LAST_CHILD:
1125
+ return lxb_selectors_pseudo_class_last_child(node);
1126
+
1127
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_LAST_OF_TYPE:
1128
+ return lxb_selectors_pseudo_class_last_of_type(node);
1129
+
1130
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_LINK:
1131
+ if (node->local_name == LXB_TAG_A
1132
+ || node->local_name == LXB_TAG_AREA
1133
+ || node->local_name == LXB_TAG_LINK)
1134
+ {
1135
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1136
+ LXB_DOM_ATTR_HREF);
1137
+ return attr != NULL;
1138
+ }
1139
+
1140
+ return false;
1141
+
1142
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_LOCAL_LINK:
1143
+ break;
1144
+
1145
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ONLY_CHILD:
1146
+ return lxb_selectors_pseudo_class_first_child(node)
1147
+ && lxb_selectors_pseudo_class_last_child(node);
1148
+
1149
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ONLY_OF_TYPE:
1150
+ return lxb_selectors_pseudo_class_first_of_type(node)
1151
+ && lxb_selectors_pseudo_class_last_of_type(node);
1152
+
1153
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_OPTIONAL:
1154
+ if (node->local_name == LXB_TAG_INPUT
1155
+ || node->local_name == LXB_TAG_SELECT
1156
+ || node->local_name == LXB_TAG_TEXTAREA)
1157
+ {
1158
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1159
+ LXB_DOM_ATTR_REQUIRED);
1160
+ return attr == NULL;
1161
+ }
1162
+
1163
+ return false;
1164
+
1165
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_OUT_OF_RANGE:
1166
+ break;
1167
+
1168
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_PAST:
1169
+ break;
1170
+
1171
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_PLACEHOLDER_SHOWN:
1172
+ if (node->local_name == LXB_TAG_INPUT
1173
+ || node->local_name == LXB_TAG_TEXTAREA)
1174
+ {
1175
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1176
+ LXB_DOM_ATTR_PLACEHOLDER);
1177
+ return attr != NULL;
1178
+ }
1179
+
1180
+ return false;
1181
+
1182
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_READ_ONLY:
1183
+ return !lxb_selectors_pseudo_class_read_write(node);
1184
+
1185
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_READ_WRITE:
1186
+ return lxb_selectors_pseudo_class_read_write(node);
1187
+
1188
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_REQUIRED:
1189
+ if (node->local_name == LXB_TAG_INPUT
1190
+ || node->local_name == LXB_TAG_SELECT
1191
+ || node->local_name == LXB_TAG_TEXTAREA)
1192
+ {
1193
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1194
+ LXB_DOM_ATTR_REQUIRED);
1195
+ return attr != NULL;
1196
+ }
1197
+
1198
+ return false;
1199
+
1200
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_ROOT:
1201
+ return lxb_dom_document_root(node->owner_document) == node;
1202
+
1203
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_SCOPE:
1204
+ break;
1205
+
1206
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_TARGET:
1207
+ break;
1208
+
1209
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_TARGET_WITHIN:
1210
+ break;
1211
+
1212
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_USER_INVALID:
1213
+ break;
1214
+
1215
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_VALID:
1216
+ break;
1217
+
1218
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_VISITED:
1219
+ break;
1220
+
1221
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_WARNING:
1222
+ break;
1223
+ }
1224
+
1225
+ return false;
1226
+ }
1227
+
1228
+ static bool
1229
+ lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors,
1230
+ lxb_css_selector_t *selector,
1231
+ lxb_dom_node_t *node,
1232
+ lxb_selectors_entry_t *entry)
1233
+ {
1234
+ size_t index;
1235
+ bool found = false;
1236
+ lxb_dom_node_t *base;
1237
+ lxb_css_selector_anb_of_t *anb;
1238
+ lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo;
1239
+
1240
+ switch (pseudo->type) {
1241
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_CURRENT:
1242
+ entry->child = lxb_selectors_next(selectors, node, entry->child,
1243
+ pseudo->data,
1244
+ lxb_selectors_first_match, &found);
1245
+ if (entry->child == NULL) {
1246
+ return false;
1247
+ }
1248
+
1249
+ return found;
1250
+
1251
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_DIR:
1252
+ break;
1253
+
1254
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_HAS:
1255
+ entry->child = lxb_selectors_next(selectors, node, entry->child,
1256
+ pseudo->data,
1257
+ lxb_selectors_first_match, &found);
1258
+ if (entry->child == NULL) {
1259
+ return false;
1260
+ }
1261
+
1262
+ return found;
1263
+
1264
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_IS:
1265
+ entry->child = lxb_selectors_next(selectors, node, entry->child,
1266
+ pseudo->data,
1267
+ lxb_selectors_first_match, &found);
1268
+ if (entry->child == NULL) {
1269
+ return false;
1270
+ }
1271
+
1272
+ return found;
1273
+
1274
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_LANG:
1275
+ break;
1276
+
1277
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NOT:
1278
+ entry->child = lxb_selectors_next(selectors, node, entry->child,
1279
+ pseudo->data,
1280
+ lxb_selectors_first_match, &found);
1281
+ if (entry->child == NULL) {
1282
+ return false;
1283
+ }
1284
+
1285
+ return !found;
1286
+
1287
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD:
1288
+ index = 0;
1289
+ found = false;
1290
+ anb = selector->u.pseudo.data;
1291
+
1292
+ if (anb->of != NULL) {
1293
+ while (node != NULL) {
1294
+ if (node->local_name != LXB_TAG__TEXT
1295
+ && node->local_name != LXB_TAG__EM_COMMENT)
1296
+ {
1297
+ entry->child = lxb_selectors_current(selectors, node, entry->child,
1298
+ anb->of, lxb_selectors_first_match,
1299
+ &found);
1300
+ if (entry->child == NULL) {
1301
+ return false;
1302
+ }
1303
+
1304
+ if (found) {
1305
+ index++;
1306
+ }
1307
+
1308
+ found = false;
1309
+ }
1310
+
1311
+ node = node->prev;
1312
+ }
1313
+ }
1314
+ else {
1315
+ while (node != NULL) {
1316
+ if (node->local_name != LXB_TAG__TEXT
1317
+ && node->local_name != LXB_TAG__EM_COMMENT)
1318
+ {
1319
+ index++;
1320
+ }
1321
+
1322
+ node = node->prev;
1323
+ }
1324
+ }
1325
+
1326
+ return lxb_selectors_anb_calc(anb, index);
1327
+
1328
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_COL:
1329
+ break;
1330
+
1331
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD:
1332
+ index = 0;
1333
+ found = false;
1334
+ anb = selector->u.pseudo.data;
1335
+
1336
+ if (anb->of != NULL) {
1337
+ while (node != NULL) {
1338
+ if (node->local_name != LXB_TAG__TEXT
1339
+ && node->local_name != LXB_TAG__EM_COMMENT)
1340
+ {
1341
+ entry->child = lxb_selectors_current(selectors, node, entry->child,
1342
+ anb->of, lxb_selectors_first_match,
1343
+ &found);
1344
+ if (entry->child == NULL) {
1345
+ return false;
1346
+ }
1347
+
1348
+ if (found) {
1349
+ index++;
1350
+ }
1351
+
1352
+ found = false;
1353
+ }
1354
+
1355
+ node = node->next;
1356
+ }
1357
+ }
1358
+ else {
1359
+ while (node != NULL) {
1360
+ if (node->local_name != LXB_TAG__TEXT
1361
+ && node->local_name != LXB_TAG__EM_COMMENT)
1362
+ {
1363
+ index++;
1364
+ }
1365
+
1366
+ node = node->next;
1367
+ }
1368
+ }
1369
+
1370
+ return lxb_selectors_anb_calc(anb, index);
1371
+
1372
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_COL:
1373
+ break;
1374
+
1375
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE:
1376
+ index = 0;
1377
+ found = false;
1378
+ anb = selector->u.pseudo.data;
1379
+ base = node;
1380
+
1381
+ while (node != NULL) {
1382
+ if(node->local_name == base->local_name
1383
+ && node->ns == base->ns)
1384
+ {
1385
+ index++;
1386
+ }
1387
+
1388
+ node = node->next;
1389
+ }
1390
+
1391
+ return lxb_selectors_anb_calc(anb, index);
1392
+
1393
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE:
1394
+ index = 0;
1395
+ found = false;
1396
+ anb = selector->u.pseudo.data;
1397
+ base = node;
1398
+
1399
+ while (node != NULL) {
1400
+ if(node->local_name == base->local_name
1401
+ && node->ns == base->ns)
1402
+ {
1403
+ index++;
1404
+ }
1405
+
1406
+ node = node->prev;
1407
+ }
1408
+
1409
+ return lxb_selectors_anb_calc(anb, index);
1410
+
1411
+ case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_WHERE:
1412
+ entry->child = lxb_selectors_next(selectors, node, entry->child,
1413
+ pseudo->data,
1414
+ lxb_selectors_first_match, &found);
1415
+ if (entry->child == NULL) {
1416
+ return false;
1417
+ }
1418
+
1419
+ return found;
1420
+ }
1421
+
1422
+ return false;
1423
+ }
1424
+
1425
+ static bool
1426
+ lxb_selectors_pseudo_element(lxb_selectors_t *selectors,
1427
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
1428
+ {
1429
+ lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo;
1430
+
1431
+ switch (pseudo->type) {
1432
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_AFTER:
1433
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_BACKDROP:
1434
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_BEFORE:
1435
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_FIRST_LETTER:
1436
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_FIRST_LINE:
1437
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_GRAMMAR_ERROR:
1438
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_INACTIVE_SELECTION:
1439
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_MARKER:
1440
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_PLACEHOLDER:
1441
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_SELECTION:
1442
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_SPELLING_ERROR:
1443
+ case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_TARGET_TEXT:
1444
+ break;
1445
+ }
1446
+
1447
+ return false;
1448
+ }
1449
+
1450
+ static bool
1451
+ lxb_selectors_pseudo_element_function(lxb_selectors_t *selectors,
1452
+ lxb_css_selector_t *selector, lxb_dom_node_t *node)
1453
+ {
1454
+ return false;
1455
+ }
1456
+
1457
+ static bool
1458
+ lxb_selectors_pseudo_class_disabled(lxb_dom_node_t *node)
1459
+ {
1460
+ lxb_dom_attr_t *attr;
1461
+ uintptr_t tag_id = node->local_name;
1462
+
1463
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1464
+ LXB_DOM_ATTR_DISABLED);
1465
+ if (attr == NULL) {
1466
+ return false;
1467
+ }
1468
+
1469
+ if (tag_id == LXB_TAG_BUTTON || tag_id == LXB_TAG_INPUT ||
1470
+ tag_id == LXB_TAG_SELECT || tag_id == LXB_TAG_TEXTAREA ||
1471
+ tag_id >= LXB_TAG__LAST_ENTRY)
1472
+ {
1473
+ return true;
1474
+ }
1475
+
1476
+ node = node->parent;
1477
+
1478
+ while (node != NULL) {
1479
+ if (node->local_name == LXB_TAG_FIELDSET
1480
+ && node->first_child->local_name != LXB_TAG_LEGEND)
1481
+ {
1482
+ return true;
1483
+ }
1484
+
1485
+ node = node->parent;
1486
+ }
1487
+
1488
+ return false;
1489
+ }
1490
+
1491
+ static bool
1492
+ lxb_selectors_pseudo_class_first_child(lxb_dom_node_t *node)
1493
+ {
1494
+ node = node->prev;
1495
+
1496
+ while (node != NULL) {
1497
+ if (node->local_name != LXB_TAG__TEXT
1498
+ && node->local_name != LXB_TAG__EM_COMMENT)
1499
+ {
1500
+ return false;
1501
+ }
1502
+
1503
+ node = node->prev;
1504
+ }
1505
+
1506
+ return true;
1507
+ }
1508
+
1509
+ static bool
1510
+ lxb_selectors_pseudo_class_first_of_type(lxb_dom_node_t *node)
1511
+ {
1512
+ lxb_dom_node_t *root = node;
1513
+ node = node->prev;
1514
+
1515
+ while (node) {
1516
+ if (node->local_name == root->local_name
1517
+ && node->ns == root->ns)
1518
+ {
1519
+ return false;
1520
+ }
1521
+
1522
+ node = node->prev;
1523
+ }
1524
+
1525
+ return true;
1526
+ }
1527
+
1528
+ static bool
1529
+ lxb_selectors_pseudo_class_last_child(lxb_dom_node_t *node)
1530
+ {
1531
+ node = node->next;
1532
+
1533
+ while (node != NULL) {
1534
+ if (node->local_name != LXB_TAG__TEXT
1535
+ && node->local_name != LXB_TAG__EM_COMMENT)
1536
+ {
1537
+ return false;
1538
+ }
1539
+
1540
+ node = node->next;
1541
+ }
1542
+
1543
+ return true;
1544
+ }
1545
+
1546
+ static bool
1547
+ lxb_selectors_pseudo_class_last_of_type(lxb_dom_node_t *node)
1548
+ {
1549
+ lxb_dom_node_t *root = node;
1550
+ node = node->next;
1551
+
1552
+ while (node) {
1553
+ if (node->local_name == root->local_name
1554
+ && node->ns == root->ns)
1555
+ {
1556
+ return false;
1557
+ }
1558
+
1559
+ node = node->next;
1560
+ }
1561
+
1562
+ return true;
1563
+ }
1564
+
1565
+ static bool
1566
+ lxb_selectors_pseudo_class_read_write(lxb_dom_node_t *node)
1567
+ {
1568
+ lxb_dom_attr_t *attr;
1569
+
1570
+ if (node->local_name == LXB_TAG_INPUT
1571
+ || node->local_name == LXB_TAG_TEXTAREA)
1572
+ {
1573
+ attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node),
1574
+ LXB_DOM_ATTR_READONLY);
1575
+ if (attr != NULL) {
1576
+ return false;
1577
+ }
1578
+
1579
+ return !lxb_selectors_pseudo_class_disabled(node);
1580
+ }
1581
+
1582
+ return false;
1583
+ }
1584
+
1585
+ static lxb_status_t
1586
+ lxb_selectors_first_match(lxb_dom_node_t *node,
1587
+ lxb_css_selector_specificity_t *spec, void *ctx)
1588
+ {
1589
+ *((bool *) ctx) = true;
1590
+ return LXB_STATUS_STOP;
1591
+ }