Module: MappedCommon

Included in:
MappedFile, MappedStream
Defined in:
lib/cless/data.rb

Overview

Including class must respond to #each_line

Instance Method Summary collapse

Instance Method Details

#count_lines_upto(stop_off) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cless/data.rb', line 25

def count_lines_upto(stop_off)
  cur = 0
  nb = 0
  while cur <= stop_off do
    cur = @ptr.index("\n", cur)
    if cur
      cur += 1
      nb += 1
    else
      break
    end
  end
  nb
end

#parse_header(allowed = []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cless/data.rb', line 6

def parse_header(allowed = [])
  a = []
  i = 0
  each_line do |l|
    break unless l =~ %r{^\s*#(.*)$}
    i += 1
    s = $1
    case s
    when /^\s*cless:(.*)$/
      s = $1.strip
      a += s.split_with_quotes
    when /^\s*(\w+):(.*)$/
      k, v = $1.strip, $2.strip
      a << "--#{k}" << v if allowed.include?(k)
    end
  end
  return i, a
end