James Gray wrote:
> On Aug 7, 2009, at 8:49 AM, V鱈t Ondruch wrote:
> 
>> Hello
> 
> Hello.
> 
>> C:\enc>echo p 'zufテ、llige_ナセluナ・ouト耕テス'.encoding > encoding.rb
>> according to specified encoding.
> The problem with an idea like this is that before your String is ever
> created the code to create it must be read (correctly) by Ruby's
> parser and formed into a proper String literal.  That would be
> impossible to do if String literals could be in any random Encoding.

Yes, I understand that you have to parse the file. However, if I am 
right, you still have to read the file binary in case you are looking 
for some encoding directive on top of file. So from my point of view, it 
shouldn't be big problem to read until first quotes, suppose the file is 
stored in the encoding designed on top of the file. Then read whatever 
in between quotes as binary and decide later how to interpret that 
binary data, by suggested encoding in second parameter of string 
constructor.

> 
> You have a couple of options though:
> 
> * Just set an Encoding like UTF-8 for the source code, enter
> everything in UTF-8, and transcode it into the needed Encoding.  This
> would make your example something like:
> 
>    # encoding: UTF-8
>    cp852 = "zufテ、llige_ナセluナ・ouト耕テス".encode("CP852")  # literal in
> UTF-8
> 
> * Have one or more data files the program reads needed String objects
> from.  Those files can be in any Encoding you need and you can specify
> it to IO operations, so your String objects are returned with that
> Encoding.

Both your suggestions are valid of course, but I consider them as 
solutions far from ideal. They brings far more complexity than desired.

> 
> I hope that helps.
> 
> James Edward Gray II

Of course my idea could be considered naive and there might be many 
technical issues with parser, etc. which prevents the implementation. 
Nevertheless, it would be nice feature.

Thank you for you suggestion anyway.

Vit
-- 
Posted via http://www.ruby-forum.com/.