class Fuzz::FileObject::LinePointer

Constants

FZZR_DISABLE_RE
FZZR_ENABLE_RE

Attributes

err_lines[R]

Public Class Methods

new(lines, fzzr_id) click to toggle source
# File lib/fuzz/fzzr.rb, line 134
def initialize(lines, fzzr_id)
  @lines = lines
  @fzzr_id = fzzr_id.to_s
  @err_lines = []
  reset
end

Public Instance Methods

bof?() click to toggle source
# File lib/fuzz/fzzr.rb, line 185
def bof?
  @line_nr <= 0
end
eof?() click to toggle source
# File lib/fuzz/fzzr.rb, line 182
def eof?
  @line_nr >= @lines.size
end
fzzr_disabled?() click to toggle source
# File lib/fuzz/fzzr.rb, line 140
def fzzr_disabled?
  @fzzr_disabled
end
line_nr() click to toggle source
# File lib/fuzz/fzzr.rb, line 143
def line_nr
  @line_nr+1
end
mark_error(ln = nil) click to toggle source
# File lib/fuzz/fzzr.rb, line 188
def mark_error(ln = nil)
  @err_lines << (ln || (@line_nr+1))
end
move(offs) click to toggle source
# File lib/fuzz/fzzr.rb, line 166
def move(offs)
  if offs < 0
    _backward(-offs) unless bof?
  else
    _forward(offs) unless eof?
  end
  self.line_nr
end
reset() click to toggle source
# File lib/fuzz/fzzr.rb, line 174
def reset
  @line_nr = 0
  @fzzr_disabled = false
  _check_fzzr_escape
end
set_text_at(offs, txt) click to toggle source
# File lib/fuzz/fzzr.rb, line 153
def set_text_at(offs, txt)
  ln = @line_nr+offs
  if ln>=0 && ln<@lines.size
    return (@lines[ln] = txt)
  end
  nil
end
text() click to toggle source
# File lib/fuzz/fzzr.rb, line 160
def text
  text_at(0)
end
text=(txt) click to toggle source
# File lib/fuzz/fzzr.rb, line 163
def text=(txt)
  set_text_at(0, txt)
end
text_at(offs) click to toggle source
# File lib/fuzz/fzzr.rb, line 146
def text_at(offs)
  ln = @line_nr+offs
  if ln>=0 && ln<@lines.size
    return @lines[ln]
  end
  nil
end
to_eof() click to toggle source
# File lib/fuzz/fzzr.rb, line 179
def to_eof
  _forward(@lines.size - @line_nr)
end

Private Instance Methods

_backward(distance) click to toggle source
# File lib/fuzz/fzzr.rb, line 202
def _backward(distance)
  distance.times do
    break if bof?
    @line_nr -= 1
    _check_fzzr_escape(false)
  end
end
_check_fzzr_escape(forward = true) click to toggle source
# File lib/fuzz/fzzr.rb, line 210
def _check_fzzr_escape(forward = true)
  begin
    if FZZR_ENABLE_RE =~ @lines[@line_nr]
      @fzzr_disabled = !forward if $1 == @fzzr_id
    elsif FZZR_DISABLE_RE =~ @lines[@line_nr]
      @fzzr_disabled = forward if $1 == @fzzr_id
    end
  rescue
    Fuzz.log_error(%Q{ERROR: Exception while checking fzzr escapes in line #{@line_nr+1} - #{$!}\n#{@lines[@line_nr]}})
    raise
  end
end
_forward(distance) click to toggle source
# File lib/fuzz/fzzr.rb, line 194
def _forward(distance)
  distance.times do
    @line_nr += 1
    break if eof?
    _check_fzzr_escape
  end
end