Project

General

Profile

Actions

Bug #3179

closed

getc with text mode returns ASCII-8BIT

Added by mame (Yusuke Endoh) almost 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2dev (2010-04-20 trunk 27405) [i686-linux]
Backport:
[ruby-dev:41023]

Description

=begin
遠藤です。

以下の動作は意図的でしょうか。

coding: UTF-8

"あいう" というファイルを作る

s = "あいう"
open("foo.txt", "wb") {|f| f.write(s) }

IO#read で一気に読めば期待通り

open("foo.txt", "rt") {|f| p f.read } #=> "あいう"

getc するとバイナリとして読んだ感じになる

open("foo.txt", "rt") do |f|
p f.getc #=> "\xE3"
p f.getc #=> "\x81"
p f.getc #=> "\x82"
end

各 getc で "あ" "い" "う" が帰ってくることを期待しました。
LANG は ja_JP.UTF-8 です。

--
Yusuke Endoh
=end

Actions #1

Updated by naruse (Yui NARUSE) almost 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r27426.
Yusuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions #2

Updated by matz (Yukihiro Matsumoto) almost 14 years ago

=begin
まつもと ゆきひろです

私のところでは"あ" "い" "う"が返りますね。

minirubyはLANGを見ないのでexternal_encodingがASCII-8BITにな
り、"\xE3" "\x81" "\x82" が返りますが、これは明示的にUTF-8を
指定して

open("foo.txt", "rt:UTF-8")

とすると、やはりUTF-8の文字単位で動作します。

In message "Re: [ruby-dev:41023] [Bug #3179] getc with text mode returns ASCII-8BIT"
on Tue, 20 Apr 2010 21:58:03 +0900, Yusuke Endoh writes:

|以下の動作は意図的でしょうか。
|
| # coding: UTF-8
| # "あいう" というファイルを作る
| s = "あいう"
| open("foo.txt", "wb") {|f| f.write(s) }
|
| # IO#read で一気に読めば期待通り
| open("foo.txt", "rt") {|f| p f.read } #=> "あいう"
|
| # getc するとバイナリとして読んだ感じになる
| open("foo.txt", "rt") do |f|
| p f.getc #=> "\xE3"
| p f.getc #=> "\x81"
| p f.getc #=> "\x82"
| end
|
|各 getc で "あ" "い" "う" が帰ってくることを期待しました。
|LANG は ja_JP.UTF-8 です。

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0