diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-05 02:36:11 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-05 02:36:11 +0000 |
commit | 17d0a403c0fd248586f37707c4409d7923d33e6e (patch) | |
tree | 97b3b0e219ab59de0ff41c134b965124697e88db | |
parent | 448459dc8295c9b6b11d2313723420257966ba89 (diff) | |
download | ruby-17d0a403c0fd248586f37707c4409d7923d33e6e.tar.gz ruby-17d0a403c0fd248586f37707c4409d7923d33e6e.tar.xz ruby-17d0a403c0fd248586f37707c4409d7923d33e6e.zip |
merges r25353 and r25362 from trunk into ruby_1_9_1.
--
* lib/csv.rb (CSV#read_to_char): set encoding and verify data
which read from io before encode it to @encoding.
* lib/csv.rb (CSV#raw_encoding): add to get @io's encoding.
* lib/csv.rb (CSV#read_io): add to read string and set @io's
encoding.
--
* lib/csv.rb (CSV#raw_encoding): returns ASCII-8BIT when the io
doesn't have encoding.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@25999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | lib/csv.rb | 32 | ||||
-rw-r--r-- | version.h | 8 |
3 files changed, 41 insertions, 14 deletions
@@ -1,3 +1,18 @@ +Fri Oct 16 12:03:31 2009 NARUSE, Yui <naruse@ruby-lang.org> + + * lib/csv.rb (CSV#raw_encoding): returns ASCII-8BIT when the io + doesn't have encoding. + +Fri Oct 16 03:15:52 2009 NARUSE, Yui <naruse@ruby-lang.org> + + * lib/csv.rb (CSV#read_to_char): set encoding and verify data + which read from io before encode it to @encoding. + + * lib/csv.rb (CSV#raw_encoding): add to get @io's encoding. + + * lib/csv.rb (CSV#read_io): add to read string and set @io's + encoding. + Mon Sep 28 22:33:11 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * dln.c (aix_loaderror): needs format string. diff --git a/lib/csv.rb b/lib/csv.rb index 832ff2f06..71ebee830 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1550,13 +1550,8 @@ class CSV # create the IO object we will read from @io = if data.is_a? String then StringIO.new(data) else data end # honor the IO encoding if we can, otherwise default to ASCII-8BIT - @encoding = if @io.respond_to? :internal_encoding - @io.internal_encoding || @io.external_encoding - elsif @io.is_a? StringIO - @io.string.encoding - end - @encoding ||= Encoding.default_internal || Encoding.default_external - # + @encoding = raw_encoding || Encoding.default_internal || Encoding.default_external + # # prepare for building safe regular expressions in the target encoding, # if we can transcode the needed characters # @@ -1989,7 +1984,6 @@ class CSV sample = read_to_char(1024) sample += read_to_char(1) if sample[-1..-1] == encode_str("\r") and not @io.eof? - # try to find a standard separator if sample =~ encode_re("\r\n?|\n") @row_sep = $& @@ -2272,8 +2266,9 @@ class CSV # def read_to_char(bytes) return "" if @io.eof? - data = @io.read(bytes) + data = read_io(bytes) begin + raise unless data.valid_encoding? encoded = encode_str(data) raise unless encoded.valid_encoding? return encoded @@ -2281,11 +2276,28 @@ class CSV if @io.eof? or data.size >= bytes + 10 return data else - data += @io.read(1) + data += read_io(1) retry end end end + + private + def raw_encoding + if @io.respond_to? :internal_encoding + @io.internal_encoding || @io.external_encoding + elsif @io.is_a? StringIO + @io.string.encoding + elsif @io.respond_to? :encoding + @io.encoding + else + Encoding::ASCII_8BIT + end + end + + def read_io(bytes) + @io.read(bytes).force_encoding(raw_encoding) + end end # Another name for CSV::instance(). @@ -1,13 +1,13 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 355 +#define RUBY_PATCHLEVEL 356 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_YEAR 2009 -#define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 27 -#define RUBY_RELEASE_DATE "2009-11-27" +#define RUBY_RELEASE_MONTH 12 +#define RUBY_RELEASE_DAY 5 +#define RUBY_RELEASE_DATE "2009-12-05" #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; |