Bug #9766 » csv.rb.diff
| lib/csv.rb | ||
|---|---|---|
|
when /\A[^:]+/; Encoding.find($&)
|
||
|
end ) ||
|
||
|
Encoding.default_internal || Encoding.default_external
|
||
|
@force_encoding = !!options.delete(:force_encoding)
|
||
|
#
|
||
|
# prepare for building safe regular expressions in the target encoding,
|
||
|
# if we can transcode the needed characters
|
||
| ... | ... | |
|
attr_reader :encoding
|
||
|
#
|
||
|
# The flag to encode inserted strings forcibly.
|
||
|
#
|
||
|
attr_reader :force_encoding
|
||
|
#
|
||
|
# The line number of the last row read from this file. Fields with nested
|
||
|
# line-end characters will not affect this count.
|
||
|
#
|
||
| ... | ... | |
|
output = row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
|
||
|
if @io.is_a?(StringIO) and
|
||
|
output.encoding != raw_encoding and
|
||
|
(compatible_encoding = Encoding.compatible?(@io.string, output))
|
||
|
@io.set_encoding(compatible_encoding)
|
||
|
@io.seek(0, IO::SEEK_END)
|
||
|
output.encoding != raw_encoding
|
||
|
if force_encoding
|
||
|
output = output.force_encoding(raw_encoding)
|
||
|
elsif compatible_encoding = Encoding.compatible?(@io.string, output)
|
||
|
@io.set_encoding(compatible_encoding)
|
||
|
@io.seek(0, IO::SEEK_END)
|
||
|
end
|
||
|
end
|
||
|
@io << output
|
||