leptris 1.1.2-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +8 -0
  4. data/CHANGELOG.md +619 -0
  5. data/CLAUDE.md +104 -0
  6. data/LICENSE.md +33 -0
  7. data/README.adoc +405 -0
  8. data/Rakefile +98 -0
  9. data/TODO.impl/01-architecture.md +217 -0
  10. data/TODO.impl/02-ffi-declarations.md +236 -0
  11. data/TODO.impl/03-document-node-element-nodeset.md +382 -0
  12. data/TODO.impl/04-sax-parser.md +203 -0
  13. data/TODO.impl/05-serialize-c14n-memory-specs-css.md +276 -0
  14. data/benchmark/README.md +168 -0
  15. data/benchmark/leptris_vs_nokogiri.rb +105 -0
  16. data/docs/ARCHITECTURE.adoc +559 -0
  17. data/docs/BUILD.md +395 -0
  18. data/docs/ERROR_MESSAGES.md +458 -0
  19. data/docs/FFI_ARCHITECTURE.md +439 -0
  20. data/docs/FUTURE_VISION.md +303 -0
  21. data/docs/GITHUB_ACTIONS.md +293 -0
  22. data/docs/OPTIMIZATIONS_IMPLEMENTED.adoc +459 -0
  23. data/docs/PERFORMANCE.adoc +668 -0
  24. data/docs/PERFORMANCE.md +448 -0
  25. data/docs/RELEASE_NOTES_v1.0.0.md +515 -0
  26. data/docs/XPATH_SPEC_COMPLIANCE.md +298 -0
  27. data/docs/completion/leptris.bash +86 -0
  28. data/docs/completion/leptris.zsh +74 -0
  29. data/docs/man/leptris-format.1 +227 -0
  30. data/docs/man/leptris-parse.1 +178 -0
  31. data/docs/man/leptris-xpath.1 +312 -0
  32. data/docs/man/leptris.1 +160 -0
  33. data/docs/v0.9.0_PERFORMANCE_IMPROVEMENTS.md +217 -0
  34. data/docs/v0.9.0_RELEASE_SUMMARY.md +281 -0
  35. data/docs/v1.0.0_CONTINUATION_PLAN.md +172 -0
  36. data/docs/v1.0.0_CONTINUATION_PROMPT.md +382 -0
  37. data/docs/v1.0.0_SESSION_6_CONTINUATION.md +434 -0
  38. data/docs/v1.0.0_SESSION_6_PROMPT.md +231 -0
  39. data/docs/v1.0.0_STATUS_TRACKER.md +224 -0
  40. data/docs/v1.1.0_CONTINUATION_PLAN.md +299 -0
  41. data/docs/v1.1.0_FINAL_CONTINUATION_PLAN.md +201 -0
  42. data/docs/v1.1.0_SESSION_3_PROMPT.md +223 -0
  43. data/docs/v1.1.0_STATUS_TRACKER.md +355 -0
  44. data/docs/xml-performance.adoc +115 -0
  45. data/docs/xpath-performance.adoc +379 -0
  46. data/leptris.gemspec +42 -0
  47. data/lib/leptris/version.rb +5 -0
  48. data/lib/leptris/xml/attr.rb +41 -0
  49. data/lib/leptris/xml/c_string_array.rb +37 -0
  50. data/lib/leptris/xml/cdata.rb +15 -0
  51. data/lib/leptris/xml/comment.rb +15 -0
  52. data/lib/leptris/xml/css_to_xpath.rb +177 -0
  53. data/lib/leptris/xml/doc_type.rb +54 -0
  54. data/lib/leptris/xml/document.rb +212 -0
  55. data/lib/leptris/xml/document_fragment.rb +42 -0
  56. data/lib/leptris/xml/element.rb +259 -0
  57. data/lib/leptris/xml/ffi.rb +475 -0
  58. data/lib/leptris/xml/namespace.rb +43 -0
  59. data/lib/leptris/xml/node.rb +211 -0
  60. data/lib/leptris/xml/node_set.rb +150 -0
  61. data/lib/leptris/xml/parse_options.rb +29 -0
  62. data/lib/leptris/xml/processing_instruction.rb +24 -0
  63. data/lib/leptris/xml/sax/document.rb +45 -0
  64. data/lib/leptris/xml/sax/parser.rb +136 -0
  65. data/lib/leptris/xml/sax.rb +12 -0
  66. data/lib/leptris/xml/searchable.rb +92 -0
  67. data/lib/leptris/xml/serialization.rb +41 -0
  68. data/lib/leptris/xml/text.rb +15 -0
  69. data/lib/leptris/xml.rb +40 -0
  70. data/lib/leptris.rb +7 -0
  71. data/lib/libleptris.so +0 -0
  72. metadata +162 -0
@@ -0,0 +1,475 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+
5
+ module Leptris
6
+ module XML
7
+ module FFI
8
+ extend ::FFI::Library
9
+
10
+ ffi_lib [
11
+ ENV["LEPTRIS_LIB_PATH"],
12
+ File.expand_path("../../libleptris.dylib", __dir__),
13
+ File.expand_path("../../libleptris.so", __dir__),
14
+ File.expand_path("../../libleptris.dll", __dir__),
15
+ "/usr/local/lib/libleptris.dylib",
16
+ "/usr/local/lib/libleptris.so",
17
+ "leptris",
18
+ ].compact
19
+
20
+ typedef :pointer, :leptris_document
21
+ typedef :pointer, :leptris_element
22
+ typedef :pointer, :leptris_node_ref
23
+ typedef :pointer, :leptris_attribute
24
+ typedef :pointer, :leptris_doctype
25
+ typedef :pointer, :leptris_xpath_result
26
+ typedef :pointer, :leptris_xpath_var_set
27
+ typedef :pointer, :leptris_sax_parser
28
+ typedef :int, :leptris_status
29
+
30
+ class SAXHandler < ::FFI::Struct
31
+ layout \
32
+ :start_document, :pointer,
33
+ :end_document, :pointer,
34
+ :start_element, :pointer,
35
+ :end_element, :pointer,
36
+ :characters, :pointer,
37
+ :comment, :pointer,
38
+ :cdata, :pointer,
39
+ :processing_instruction, :pointer,
40
+ :start_prefix_mapping, :pointer,
41
+ :end_prefix_mapping, :pointer,
42
+ :error, :pointer
43
+ end
44
+
45
+ class SerializeOptions < ::FFI::Struct
46
+ layout \
47
+ :indent, :int,
48
+ :xml_declaration, :int,
49
+ :encoding, :pointer
50
+ end
51
+
52
+ attach_function :leptris_version, [], :string
53
+ attach_function :leptris_version_components, [:pointer, :pointer, :pointer], :void
54
+
55
+ attach_function :leptris_parse_string,
56
+ [:string, :size_t, :pointer], :leptris_document
57
+ attach_function :leptris_parse_string_flags,
58
+ [:string, :size_t, :uint, :pointer], :leptris_document
59
+ attach_function :leptris_parse_string_inplace,
60
+ [:pointer, :size_t, :pointer], :leptris_document
61
+ attach_function :leptris_parse_string_with_encoding,
62
+ [:string, :size_t, :pointer], :leptris_document
63
+ attach_function :leptris_parse_file,
64
+ [:string, :pointer], :leptris_document
65
+ attach_function :leptris_load_file,
66
+ [:string, :pointer], :pointer
67
+ attach_function :leptris_document_free,
68
+ [:leptris_document], :void
69
+ attach_function :leptris_document_root,
70
+ [:leptris_document], :leptris_element
71
+ attach_function :leptris_document_encoding,
72
+ [:leptris_document], :string
73
+ attach_function :leptris_document_finalize_strings,
74
+ [:leptris_document], :int
75
+ attach_function :leptris_document_adopt_child,
76
+ [:leptris_document, :leptris_document], :void
77
+ attach_function :leptris_document_set_strict,
78
+ [:leptris_document, :int], :leptris_status
79
+ attach_function :leptris_document_get_strict,
80
+ [:leptris_document], :int
81
+ attach_function :leptris_document_freeze,
82
+ [:leptris_document], :leptris_status
83
+ attach_function :leptris_document_is_frozen,
84
+ [:leptris_document], :int
85
+ attach_function :leptris_set_strict_mode, [:int], :void
86
+ attach_function :leptris_get_strict_mode, [], :int
87
+ attach_function :leptris_set_max_depth, [:int], :void
88
+ attach_function :leptris_get_max_depth, [], :int
89
+ attach_function :leptris_xinclude_process,
90
+ [:leptris_document, :string], :leptris_status
91
+ attach_function :leptris_xinclude_is_include_element,
92
+ [:leptris_element], :int
93
+ attach_function :leptris_xinclude_is_fallback_element,
94
+ [:leptris_element], :int
95
+ attach_function :leptris_xinclude_get_href, [:leptris_element], :string
96
+ attach_function :leptris_xinclude_get_parse, [:leptris_element], :string
97
+ attach_function :leptris_xinclude_get_xpointer, [:leptris_element], :string
98
+ attach_function :leptris_xinclude_get_encoding, [:leptris_element], :string
99
+
100
+ attach_function :leptris_node_get_type,
101
+ [:leptris_node_ref], :int
102
+ attach_function :leptris_node_first_child,
103
+ [:leptris_node_ref], :leptris_node_ref
104
+ attach_function :leptris_node_last_child,
105
+ [:leptris_node_ref], :leptris_node_ref
106
+ attach_function :leptris_node_next_sibling,
107
+ [:leptris_node_ref], :leptris_node_ref
108
+ attach_function :leptris_node_previous_sibling,
109
+ [:leptris_node_ref], :leptris_node_ref
110
+ attach_function :leptris_node_child_count,
111
+ [:leptris_node_ref], :size_t
112
+ attach_function :leptris_node_as_element,
113
+ [:leptris_node_ref], :leptris_element
114
+ attach_function :leptris_element_as_node,
115
+ [:leptris_element], :leptris_node_ref
116
+ attach_function :leptris_node_get_binding_wrapper,
117
+ [:leptris_node_ref], :pointer
118
+ attach_function :leptris_node_set_binding_wrapper,
119
+ [:leptris_node_ref, :pointer], :void
120
+ attach_function :leptris_node_parent,
121
+ [:leptris_node_ref], :leptris_element
122
+ attach_function :leptris_node_unlink,
123
+ [:leptris_node_ref], :leptris_status
124
+ attach_function :leptris_node_line,
125
+ [:leptris_node_ref], :int
126
+ attach_function :leptris_node_compare,
127
+ [:leptris_node_ref, :leptris_node_ref], :int
128
+ attach_function :leptris_node_traverse,
129
+ [:leptris_node_ref, :int, :pointer, :pointer], :int
130
+
131
+ attach_function :leptris_text_node_get_content,
132
+ [:leptris_node_ref], :string
133
+ attach_function :leptris_comment_node_get_content,
134
+ [:leptris_node_ref], :string
135
+ attach_function :leptris_cdata_node_get_content,
136
+ [:leptris_node_ref], :string
137
+ attach_function :leptris_pi_node_get_target,
138
+ [:leptris_node_ref], :string
139
+ attach_function :leptris_pi_node_get_data,
140
+ [:leptris_node_ref], :string
141
+ attach_function :leptris_text_node_create,
142
+ [:leptris_document, :string], :leptris_node_ref
143
+ attach_function :leptris_comment_node_create,
144
+ [:leptris_document, :string], :leptris_node_ref
145
+ attach_function :leptris_cdata_node_create,
146
+ [:leptris_document, :string], :leptris_node_ref
147
+ attach_function :leptris_pi_node_create,
148
+ [:leptris_document, :string, :string], :leptris_node_ref
149
+ attach_function :leptris_text_node_set_content,
150
+ [:leptris_node_ref, :string], :leptris_status
151
+ attach_function :leptris_comment_node_set_content,
152
+ [:leptris_node_ref, :string], :leptris_status
153
+ attach_function :leptris_cdata_node_set_content,
154
+ [:leptris_node_ref, :string], :leptris_status
155
+ attach_function :leptris_pi_node_set_target,
156
+ [:leptris_node_ref, :string], :leptris_status
157
+ attach_function :leptris_pi_node_set_data,
158
+ [:leptris_node_ref, :string], :leptris_status
159
+
160
+ attach_function :leptris_element_name,
161
+ [:leptris_element], :string
162
+ attach_function :leptris_element_text,
163
+ [:leptris_element], :string
164
+ attach_function :leptris_element_text_int,
165
+ [:leptris_element, :int], :int
166
+ attach_function :leptris_element_text_uint,
167
+ [:leptris_element, :uint], :uint
168
+ attach_function :leptris_element_text_double,
169
+ [:leptris_element, :double], :double
170
+ attach_function :leptris_element_text_float,
171
+ [:leptris_element, :float], :float
172
+ attach_function :leptris_element_text_bool,
173
+ [:leptris_element, :int], :int
174
+ attach_function :leptris_element_attribute,
175
+ [:leptris_element, :string], :string
176
+ attach_function :leptris_element_attribute_string,
177
+ [:leptris_element, :string, :string], :string
178
+ attach_function :leptris_element_attribute_int,
179
+ [:leptris_element, :string, :int], :int
180
+ attach_function :leptris_element_attribute_uint,
181
+ [:leptris_element, :string, :uint], :uint
182
+ attach_function :leptris_element_attribute_double,
183
+ [:leptris_element, :string, :double], :double
184
+ attach_function :leptris_element_attribute_float,
185
+ [:leptris_element, :string, :float], :float
186
+ attach_function :leptris_element_attribute_bool,
187
+ [:leptris_element, :string, :int], :int
188
+ attach_function :leptris_element_has_attribute,
189
+ [:leptris_element, :string], :int
190
+ attach_function :leptris_element_first_attribute,
191
+ [:leptris_element], :leptris_attribute
192
+ attach_function :leptris_attribute_next,
193
+ [:leptris_attribute], :leptris_attribute
194
+ attach_function :leptris_attribute_get_name,
195
+ [:leptris_attribute], :string
196
+ attach_function :leptris_attribute_get_value,
197
+ [:leptris_element, :leptris_attribute], :string
198
+ attach_function :leptris_element_prefix,
199
+ [:leptris_element], :string
200
+ attach_function :leptris_element_attribute_count,
201
+ [:leptris_element], :size_t
202
+ attach_function :leptris_element_attribute_name_at,
203
+ [:leptris_element, :size_t], :string
204
+ attach_function :leptris_element_attribute_value_at,
205
+ [:leptris_element, :size_t], :string
206
+ attach_function :leptris_element_remove_all_attributes,
207
+ [:leptris_element], :leptris_status
208
+
209
+ attach_function :leptris_element_child_count,
210
+ [:leptris_element], :size_t
211
+ attach_function :leptris_element_child,
212
+ [:leptris_element, :size_t], :leptris_element
213
+ attach_function :leptris_element_parent,
214
+ [:leptris_element], :leptris_element
215
+ attach_function :leptris_element_root,
216
+ [:leptris_element], :leptris_element
217
+ attach_function :leptris_element_child_value,
218
+ [:leptris_element], :string
219
+ attach_function :leptris_element_hash_value,
220
+ [:leptris_element], :size_t
221
+ attach_function :leptris_element_find_child,
222
+ [:leptris_element, :string], :leptris_element
223
+ attach_function :leptris_element_find_child_by_attr,
224
+ [:leptris_element, :string, :string, :string], :leptris_element
225
+ attach_function :leptris_element_next_sibling,
226
+ [:leptris_element, :string], :leptris_element
227
+ attach_function :leptris_element_previous_sibling,
228
+ [:leptris_element, :string], :leptris_element
229
+ attach_function :leptris_element_first_child,
230
+ [:leptris_element, :string], :leptris_element
231
+ attach_function :leptris_element_last_child,
232
+ [:leptris_element, :string], :leptris_element
233
+ attach_function :leptris_element_first_child_any,
234
+ [:leptris_element], :leptris_element
235
+ attach_function :leptris_element_last_child_any,
236
+ [:leptris_element], :leptris_element
237
+ attach_function :leptris_element_next_sibling_any,
238
+ [:leptris_element], :leptris_element
239
+ attach_function :leptris_element_previous_sibling_any,
240
+ [:leptris_element], :leptris_element
241
+
242
+ attach_function :leptris_element_create,
243
+ [:leptris_document, :string], :leptris_element
244
+ attach_function :leptris_element_set_name,
245
+ [:leptris_element, :string], :leptris_status
246
+ attach_function :leptris_element_set_text,
247
+ [:leptris_element, :string], :leptris_status
248
+ attach_function :leptris_element_set_attribute,
249
+ [:leptris_element, :string, :string], :leptris_status
250
+ attach_function :leptris_element_set_attribute_bool,
251
+ [:leptris_element, :string, :int], :leptris_status
252
+ attach_function :leptris_element_set_attribute_double,
253
+ [:leptris_element, :string, :double], :leptris_status
254
+ attach_function :leptris_element_set_attribute_float,
255
+ [:leptris_element, :string, :float], :leptris_status
256
+ attach_function :leptris_element_set_attribute_int,
257
+ [:leptris_element, :string, :int], :leptris_status
258
+ attach_function :leptris_element_set_attribute_uint,
259
+ [:leptris_element, :string, :uint], :leptris_status
260
+ attach_function :leptris_element_remove_attribute,
261
+ [:leptris_element, :string], :leptris_status
262
+ attach_function :leptris_element_append_child,
263
+ [:leptris_element, :leptris_element], :leptris_status
264
+ attach_function :leptris_element_prepend_child,
265
+ [:leptris_element, :leptris_element], :leptris_status
266
+ attach_function :leptris_element_insert_before,
267
+ [:leptris_element, :leptris_element], :leptris_status
268
+ attach_function :leptris_element_insert_after,
269
+ [:leptris_element, :leptris_element], :leptris_status
270
+ attach_function :leptris_element_remove_child,
271
+ [:leptris_element, :leptris_element], :leptris_status
272
+ attach_function :leptris_element_remove_children,
273
+ [:leptris_element], :leptris_status
274
+ attach_function :leptris_element_append_copy,
275
+ [:leptris_element, :leptris_element], :leptris_element
276
+ attach_function :leptris_element_prepend_copy,
277
+ [:leptris_element, :leptris_element], :leptris_element
278
+ attach_function :leptris_element_insert_copy_before,
279
+ [:leptris_element, :leptris_element], :leptris_element
280
+ attach_function :leptris_element_insert_copy_after,
281
+ [:leptris_element, :leptris_element], :leptris_element
282
+
283
+ attach_function :leptris_element_copy,
284
+ [:leptris_element, :leptris_document], :leptris_element
285
+ attach_function :leptris_document_copy,
286
+ [:leptris_document], :leptris_document
287
+ attach_function :leptris_node_get_xpath,
288
+ [:leptris_node_ref], :pointer
289
+ attach_function :leptris_parse_fragment,
290
+ [:string, :size_t, :leptris_document, :pointer], :leptris_element
291
+
292
+ attach_function :leptris_element_namespace,
293
+ [:leptris_element], :string
294
+ attach_function :leptris_element_namespace_for_prefix,
295
+ [:leptris_element, :string], :string
296
+ attach_function :leptris_element_namespace_count,
297
+ [:leptris_element], :size_t
298
+ attach_function :leptris_element_namespace_decl_prefix,
299
+ [:leptris_element, :size_t], :string
300
+ attach_function :leptris_element_namespace_decl_uri,
301
+ [:leptris_element, :size_t], :string
302
+ attach_function :leptris_element_add_namespace_definition,
303
+ [:leptris_element, :string, :string], :leptris_status
304
+ attach_function :leptris_element_set_default_namespace,
305
+ [:leptris_element, :string], :leptris_status
306
+ attach_function :leptris_element_remove_namespace_definition,
307
+ [:leptris_element, :string], :leptris_status
308
+ attach_function :leptris_namespace_uri, [:string], :string
309
+ attach_function :leptris_namespace_prefix, [:string], :string
310
+
311
+ attach_function :leptris_xpath_eval,
312
+ [:leptris_document, :leptris_element, :string], :leptris_xpath_result
313
+ attach_function :leptris_xpath_eval_with_vars,
314
+ [:leptris_document, :string, :leptris_xpath_var_set], :leptris_xpath_result
315
+ attach_function :leptris_xpath_eval_with_vars_context,
316
+ [:leptris_document, :leptris_element, :string, :leptris_xpath_var_set],
317
+ :leptris_xpath_result
318
+ attach_function :leptris_xpath_result_type,
319
+ [:leptris_xpath_result], :int
320
+ attach_function :leptris_xpath_result_count,
321
+ [:leptris_xpath_result], :size_t
322
+ attach_function :leptris_xpath_result_get,
323
+ [:leptris_xpath_result, :size_t], :leptris_element
324
+ # Mixed nodesets (v1.1.0): unlike result_get (elements only),
325
+ # get_node returns the node whatever its kind; node_kind reports
326
+ # which (element / synthetic attribute / text / other).
327
+ attach_function :leptris_xpath_result_node_kind,
328
+ [:leptris_xpath_result, :size_t], :int
329
+ attach_function :leptris_xpath_result_get_node,
330
+ [:leptris_xpath_result, :size_t], :leptris_node_ref
331
+ attach_function :leptris_xpath_result_node_name,
332
+ [:leptris_xpath_result, :size_t], :string
333
+ attach_function :leptris_xpath_result_node_value,
334
+ [:leptris_xpath_result, :size_t], :string
335
+ # Document-scoped custom XPath functions. The callback receives
336
+ # (const char* const* args, int argc, void* user_data) and returns
337
+ # a heap string the library frees.
338
+ attach_function :leptris_xpath_register_function,
339
+ [:leptris_document, :string, :pointer, :pointer], :leptris_status
340
+ attach_function :leptris_xpath_result_get_nodes,
341
+ [:leptris_xpath_result, :pointer, :size_t], :size_t
342
+ attach_function :leptris_xpath_result_boolean,
343
+ [:leptris_xpath_result], :int
344
+ attach_function :leptris_xpath_result_number,
345
+ [:leptris_xpath_result], :double
346
+ attach_function :leptris_xpath_result_string,
347
+ [:leptris_xpath_result], :pointer
348
+ attach_function :leptris_xpath_result_free,
349
+ [:leptris_xpath_result], :void
350
+ attach_function :leptris_xpath_function_supported, [:string], :int
351
+ attach_function :leptris_xpath_supported_functions, [], :pointer
352
+
353
+ attach_function :leptris_xpath_variable_set_new,
354
+ [], :leptris_xpath_var_set
355
+ attach_function :leptris_xpath_variable_set_free,
356
+ [:leptris_xpath_var_set], :void
357
+ attach_function :leptris_xpath_variable_set_boolean,
358
+ [:leptris_xpath_var_set, :string, :int], :leptris_status
359
+ attach_function :leptris_xpath_variable_set_number,
360
+ [:leptris_xpath_var_set, :string, :double], :leptris_status
361
+ attach_function :leptris_xpath_variable_set_string,
362
+ [:leptris_xpath_var_set, :string, :string], :leptris_status
363
+
364
+ attach_function :leptris_sax_parse,
365
+ [:string, :size_t, :pointer, :pointer], :int
366
+ attach_function :leptris_sax_parser_create,
367
+ [:pointer, :pointer], :leptris_sax_parser
368
+ attach_function :leptris_sax_parser_feed,
369
+ [:leptris_sax_parser, :string, :size_t, :int], :int
370
+ attach_function :leptris_sax_parser_free,
371
+ [:leptris_sax_parser], :void
372
+ attach_function :leptris_sax_parser_set_streaming,
373
+ [:leptris_sax_parser, :int], :int
374
+
375
+ attach_function :leptris_document_serialize,
376
+ [:leptris_document, :pointer], :pointer
377
+ # Legacy simple serializer, declared retroactively in v1.1.0.
378
+ # Prefer leptris_document_serialize; bound for API completeness.
379
+ attach_function :leptris_serialize_document,
380
+ [:leptris_document], :pointer
381
+ attach_function :leptris_document_get_dtd,
382
+ [:leptris_document], :pointer
383
+ attach_function :leptris_element_serialize,
384
+ [:leptris_element, :pointer], :pointer
385
+ attach_function :leptris_document_save_file,
386
+ [:leptris_document, :string, :pointer], :leptris_status
387
+ attach_function :leptris_c14n_canonicalize,
388
+ [:leptris_document, :int, :int], :pointer
389
+ attach_function :leptris_c14n_canonicalize_subtree,
390
+ [:leptris_element, :int, :int], :pointer
391
+ attach_function :leptris_c14n_canonicalize_ex,
392
+ [:leptris_document, :int, :int, :pointer, :int], :pointer
393
+ attach_function :leptris_c14n_canonicalize_subtree_ex,
394
+ [:leptris_element, :int, :int, :pointer, :int], :pointer
395
+
396
+ attach_function :leptris_document_internal_subset,
397
+ [:leptris_document], :leptris_doctype
398
+ attach_function :leptris_doctype_get_name,
399
+ [:leptris_doctype], :string
400
+ attach_function :leptris_doctype_get_root_name,
401
+ [:leptris_doctype], :string
402
+ attach_function :leptris_doctype_get_public_id,
403
+ [:leptris_doctype], :string
404
+ attach_function :leptris_doctype_get_system_id,
405
+ [:leptris_doctype], :string
406
+ attach_function :leptris_doctype_get_internal_subset,
407
+ [:leptris_doctype], :string
408
+
409
+ attach_function :leptris_free_string, [:pointer], :void
410
+ attach_function :leptris_explicit_cleanup, [], :void
411
+ attach_function :leptris_set_memory_management_functions,
412
+ [:pointer, :pointer], :void
413
+ attach_function :leptris_get_memory_allocation_function, [], :pointer
414
+ attach_function :leptris_get_memory_deallocation_function, [], :pointer
415
+ attach_function :leptris_document_set_allocators,
416
+ [:leptris_document, :pointer, :pointer], :leptris_status
417
+ attach_function :leptris_status_string, [:leptris_status], :string
418
+
419
+ LEPTRIS_OK = 0
420
+ LEPTRIS_ERROR_MEMORY = -1
421
+ LEPTRIS_ERROR_PARSE = -2
422
+ LEPTRIS_ERROR_XPATH = -3
423
+ LEPTRIS_ERROR_NULL_ARG = -4
424
+ LEPTRIS_ERROR_INVALID_ARG = -5
425
+ LEPTRIS_ERROR_NOT_FOUND = -6
426
+ LEPTRIS_ERROR_IO = -7
427
+ LEPTRIS_ERROR_NOT_IMPLEMENTED = -8
428
+
429
+ XPATH_NODESET = 0
430
+ XPATH_BOOLEAN = 1
431
+ XPATH_NUMBER = 2
432
+ XPATH_STRING = 3
433
+
434
+ XPATH_NODE_ELEMENT = 0
435
+ XPATH_NODE_ATTRIBUTE = 1
436
+ XPATH_NODE_TEXT = 2
437
+ XPATH_NODE_OTHER = 3
438
+
439
+ NODE_ELEMENT = 0
440
+ NODE_TEXT = 1
441
+ NODE_COMMENT = 2
442
+ NODE_CDATA = 3
443
+ NODE_PI = 4
444
+ NODE_DOCTYPE = 5
445
+ NODE_ATTRIBUTE = 6
446
+
447
+ C14N_1_0 = 0
448
+ C14N_1_1 = 1
449
+
450
+ C14N_MODE_CANONICAL = 0
451
+ C14N_MODE_EXCLUSIVE = 1
452
+
453
+ TRAVERSE_PRE_ORDER = 0
454
+ TRAVERSE_POST_ORDER = 1
455
+
456
+ LEPTRIS_PARSE_DEFAULT = 0
457
+ LEPTRIS_PARSE_DROP_WS_TEXT = 1
458
+
459
+ # Reads an libleptris-owned char* result and frees it as one unit,
460
+ # so a call site can neither leak nor double-free.
461
+ def self.read_owned_string(ptr)
462
+ return "" if ptr.nil? || ptr.null?
463
+ ptr.read_string.tap { leptris_free_string(ptr) }
464
+ end
465
+
466
+ # Single status seam: turns a C status code into a Ruby error.
467
+ def self.check_status(status)
468
+ unless status == LEPTRIS_OK
469
+ raise Leptris::XML::Error, leptris_status_string(status)
470
+ end
471
+ status
472
+ end
473
+ end
474
+ end
475
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # libleptris's LeptrisNamespace is `const char*` (the URI directly). The Ruby
4
+ # Namespace wrapper holds (element, uri, optional prefix). When the prefix
5
+ # isn't supplied (e.g. via Element#namespace), it can be derived by walking
6
+ # the element's namespace declarations via leptris_element_namespace_decl_*.
7
+
8
+ class Leptris::XML::Namespace
9
+ attr_reader :element, :href, :prefix
10
+
11
+ def initialize(element, href, prefix: :derive)
12
+ @element = element
13
+ @href = href
14
+ @prefix = prefix == :derive ? derive_prefix : prefix
15
+ end
16
+
17
+ def document
18
+ @element&.document
19
+ end
20
+
21
+ def ==(other)
22
+ other.is_a?(Leptris::XML::Namespace) &&
23
+ @href == other.href && @prefix == other.prefix
24
+ end
25
+
26
+ def inspect
27
+ "#<#{self.class.name} prefix=#{@prefix.inspect} href=#{@href.inspect}>"
28
+ end
29
+
30
+ private
31
+
32
+ def derive_prefix
33
+ return nil if @element.nil?
34
+ count = Leptris::XML::FFI.leptris_element_namespace_count(@element.c_ptr)
35
+ count.times do |i|
36
+ uri = Leptris::XML::FFI.leptris_element_namespace_decl_uri(@element.c_ptr, i)
37
+ next unless uri == @href
38
+ prefix = Leptris::XML::FFI.leptris_element_namespace_decl_prefix(@element.c_ptr, i)
39
+ return prefix.nil? || prefix.empty? ? nil : prefix
40
+ end
41
+ nil
42
+ end
43
+ end