Module: Taurus::XML

Defined in:
lib/taurus/xml.rb,
lib/taurus/xml/ffi.rb,
lib/taurus/xml/sax.rb,
lib/taurus/xml/c14n.rb,
lib/taurus/xml/css_to_xpath.rb

Defined Under Namespace

Modules: CssToXPath, FFI, SAX, Searchable Classes: Attr, CDATA, Comment, DocType, Document, DocumentFragment, Element, Error, Namespace, Node, NodeSet, ParseError, ParseOptions, ProcessingInstruction, Text, UseAfterFreeError, XPathError

Class Method Summary collapse

Class Method Details

.c14n_build_ns_pointer(inclusive_namespaces) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds a NULL-terminated const char** from a Ruby array of strings, suitable for passing to taurus_c14n_canonicalize_ex's inclusive_ns_prefixes argument. Returns [pointer, anchor] where anchor is the underlying MemoryPointer that the caller must keep alive (e.g. via local variable) for the duration of the FFI call.



12
13
14
15
16
17
18
19
20
21
# File 'lib/taurus/xml/c14n.rb', line 12

def self.c14n_build_ns_pointer(inclusive_namespaces)
  return [nil, nil] if inclusive_namespaces.nil? || inclusive_namespaces.empty?
  strs = Array(inclusive_namespaces).map(&:to_s)
  ptr_size = ::FFI.type_size(:pointer)
  buffer = ::FFI::MemoryPointer.new(:pointer, strs.size + 1)
  anchors = strs.map { |s| ::FFI::MemoryPointer.from_string(s) }
  anchors.each_with_index { |p, i| buffer.put_pointer(i * ptr_size, p) }
  buffer.put_pointer(strs.size * ptr_size, nil)
  [buffer, anchors]
end