mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Added accessor of original line when parsing.
[Feature #11865][ruby-core:72452][fix GH-1170] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
59faac613f
commit
3b77cb2a64
2 changed files with 21 additions and 1 deletions
|
@ -1656,7 +1656,7 @@ class CSV
|
||||||
# The line number of the last row read from this file. Fields with nested
|
# The line number of the last row read from this file. Fields with nested
|
||||||
# line-end characters will not affect this count.
|
# line-end characters will not affect this count.
|
||||||
#
|
#
|
||||||
attr_reader :lineno
|
attr_reader :lineno, :line
|
||||||
|
|
||||||
### IO and StringIO Delegation ###
|
### IO and StringIO Delegation ###
|
||||||
|
|
||||||
|
@ -1831,6 +1831,12 @@ class CSV
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if in_extended_col
|
||||||
|
@line.concat(parse)
|
||||||
|
else
|
||||||
|
@line = parse.clone
|
||||||
|
end
|
||||||
|
|
||||||
parse.sub!(@parsers[:line_end], "")
|
parse.sub!(@parsers[:line_end], "")
|
||||||
|
|
||||||
if csv.empty?
|
if csv.empty?
|
||||||
|
|
|
@ -104,6 +104,20 @@ class TestCSV::Features < TestCSV
|
||||||
assert_equal($/, CSV.new(STDERR).row_sep)
|
assert_equal($/, CSV.new(STDERR).row_sep)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_line
|
||||||
|
lines = [
|
||||||
|
%Q(abc,def\n),
|
||||||
|
%Q(abc,"d\nef"\n),
|
||||||
|
%Q(abc,"d\r\nef"\n),
|
||||||
|
%Q(abc,"d\ref")
|
||||||
|
]
|
||||||
|
csv = CSV.new(lines.join(''))
|
||||||
|
lines.each do |line|
|
||||||
|
csv.shift
|
||||||
|
assert_equal(line, csv.line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_lineno
|
def test_lineno
|
||||||
assert_equal(5, @sample_data.lines.to_a.size)
|
assert_equal(5, @sample_data.lines.to_a.size)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue