File: tidybuf.rb

package info (click to toggle)
libtidy-ruby 1.1.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 84 kB
  • ctags: 45
  • sloc: ruby: 233; makefile: 38
file content (42 lines) | stat: -rw-r--r-- 570 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Buffer structure.
#
class Tidybuf

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

  # Mimic TidyBuffer.
  #
  TidyBuffer = struct [
    "byte* bp",
    "uint size",
    "uint allocated",
    "uint next"
  ]

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

  # Convert to array.
  #
  def to_a
    to_s.split("\r\n")
  end

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

end