lib/lineinput.rb in review-2.0.0.beta1 vs lib/lineinput.rb in review-2.0.0
- old
+ new
@@ -46,10 +46,50 @@
@lineno -= 1
@buf.push line
line
end
+ def peek
+ line = gets()
+ ungets line if line
+ line
+ end
+
+ def next?
+ peek() ? true : false
+ end
+
+ def skip_blank_lines
+ n = 0
+ while line = gets()
+ unless line.strip.empty?
+ ungets line
+ return n
+ end
+ n += 1
+ end
+ n
+ end
+
+ def gets_if(re)
+ line = gets()
+ if not line or not (re =~ line)
+ ungets line
+ return nil
+ end
+ line
+ end
+
+ def gets_unless(re)
+ line = gets()
+ if not line or re =~ line
+ ungets line
+ return nil
+ end
+ line
+ end
+
def each
while line = gets()
yield line
end
end
@@ -100,8 +140,16 @@
while line = gets()
return if re =~ line # discard terminal line
yield line
end
nil
+ end
+
+ def getblock(term_re)
+ buf = []
+ until_terminator(term_re) do |line|
+ buf.push line
+ end
+ buf
end
end