Class: Tidybuf

Inherits:
Object
  • Object
show all
Extended by:
DL::Importable
Defined in:
lib/tidy/tidybuf.rb

Overview

Buffer structure.

Constant Summary collapse

TidyBuffer =

Mimic TidyBuffer.

struct [
  "TidyAllocator* allocator",
  "byte* bp",
  "uint size",
  "uint allocated",
  "uint next"
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTidybuf

Returns a new instance of Tidybuf.



21
22
23
24
# File 'lib/tidy/tidybuf.rb', line 21

def initialize
  @struct = TidyBuffer.malloc
  Tidylib.buf_init(@struct)
end

Instance Attribute Details

#structObject (readonly)

Access TidyBuffer instance.



9
10
11
# File 'lib/tidy/tidybuf.rb', line 9

def struct
  @struct
end

Instance Method Details

#freeObject

Free current contents and zero out.



28
29
30
# File 'lib/tidy/tidybuf.rb', line 28

def free
  Tidylib.buf_free(@struct)
end

#to_aObject

Convert to array.



34
35
36
# File 'lib/tidy/tidybuf.rb', line 34

def to_a
  to_s.split("\r\n")
end

#to_sObject

Convert to string.



40
41
42
# File 'lib/tidy/tidybuf.rb', line 40

def to_s
  @struct.bp ? @struct.bp.to_s(@struct.size) : ''
end