Skip to content

Commit

Permalink
parser: simplify :skip_lines implementation
Browse files Browse the repository at this point in the history
We can use #each_line here because :skip_lines is a line based
process.
  • Loading branch information
kou committed Mar 22, 2024
1 parent 86de331 commit c2cc984
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/csv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,18 +901,15 @@ def build_scanner
def skip_needless_lines
return unless @skip_lines

until @scanner.eos?
@scanner.keep_start
line = @scanner.scan_all(@not_line_end) || "".encode(@encoding)
@scanner.keep_start
@scanner.each_line(@row_separator) do |line|
line << @row_separator if parse_row_end
if skip_line?(line)
@lineno += 1
@scanner.keep_drop
else
@scanner.keep_back
return
end
break unless skip_line?(line)
@lineno += 1
@scanner.keep_drop
@scanner.keep_start
end
@scanner.keep_back
end

def skip_line?(line)
Expand Down

0 comments on commit c2cc984

Please sign in to comment.