[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: ruby 1.9.1: Encoding trouble: broken US-ASCII String

Yukihiro Matsumoto

12/15/2008 4:05:00 PM

Hi,

In message "Re: ruby 1.9.1: Encoding trouble: broken US-ASCII String"
on Tue, 16 Dec 2008 00:47:37 +0900, Ollivier Robert <roberto@REMOVETHIS.eu.org> writes:

|From what I've seen and experimented with 1.9 for a few months, my main gripe
|is that the whole encoding support is overly complex. I know m17n is not
|solved by the magic unicode wand but I'd love to have a more simple way.

The whole picture must be complex, since encoding support itself is
VERY complex indeed. History sucks. But for daily use, just remember
specifying encoding if you are not sure what is the default_encoding,
e.g.

f = open(path, "r:iso-8859-1")

or

f = open(path, "r", encoding: "iso-8859-1")

Simple? If you want to convert your data into Unicode every time you
read, just put -U at your shebang (#!) line, in addition.

matz.

2 Answers

Brian Candler

12/15/2008 4:17:00 PM

0

Yukihiro Matsumoto wrote:
> The whole picture must be complex, since encoding support itself is
> VERY complex indeed. History sucks. But for daily use, just remember
> specifying encoding if you are not sure what is the default_encoding,
> e.g.
>
> f = open(path, "r:iso-8859-1")

It seems to go against DRY to have to write "r:binary" or "rb:binary"
when opening lots of binary files. But if I remember to use
#!/usr/bin/ruby -Knw everywhere that should be OK.

However, I also don't like the unstated assumption that all Strings
contain text.

In RFC2045 (MIME), there is a distinction made between 7bit text, 8bit
text, and binary data.

But if you label a string as "binary", Ruby changes this to
"ASCII-8BIT". I think that is a misrepresentation of that data, if it is
not actually ASCII-based text. I would much rather it made no assertion
about the content than a wrong assertion.
--
Posted via http://www.ruby-....

Dave Thomas

12/15/2008 4:23:00 PM

0


On Dec 15, 2008, at 10:16 AM, Brian Candler wrote:

> It seems to go against DRY to have to write "r:binary" or "rb:binary"
> when opening lots of binary files. But if I remember to use
> #!/usr/bin/ruby -Knw everywhere that should be OK.

You used to have to do that. In recent HEADS, rb sets binary encoding
automatically (unless overridden).


Dave