Sha256: ef683a353fe7df85f1ee5698d1c6a34fec73a886e27fefcca7c654e54bd1ff2b

Contents?: true

Size: 716 Bytes

Versions: 2

Compression:

Stored size: 716 Bytes

Contents

# Buffer structure.
#
class Tidybuf

  extend DL::Importable
  
  # Access TidyBuffer instance.
  #
  attr_reader(:struct)

  def initialize
    @struct = self.class.struct(construct_tidy_buffer).malloc
  end
    
  # Free current contents and zero out.
  #
  def free
    Tidylib.buf_free(@struct)
  end

  # Convert to array.
  #
  def to_a
    to_s.split($/)
  end

  # Convert to string.
  #
  def to_s
    @struct.bp ? @struct.bp.to_s(@struct.size) : ''
  end

protected

  def construct_tidy_buffer
    struct_rows = [ "byte* bp",
      "uint size",
      "uint allocated",
      "uint next" 
    ]
    if Tidy.fresh_tidy_version
      struct_rows.unshift "int* allocator"
    end
    struct_rows
  end
  
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
adamcooper-tidy-1.2.0 lib/tidy/tidybuf.rb
pelle-tidy-1.1.4 lib/tidy/tidybuf.rb