Repost: system encoding?

Hello,

I'm reading data from different encodings (web pages), i first 

thought about converting all to unicode, but it’s not handy right now in
ruby. Then i thought i might as well convert it all to my local encoding
for easy processing in ruby (uppercase, regexps etc) [1]. it’s easy to
hardcode my local encoding in the app, but i’d like to make it generic,
to work at my work (windows, cp1250) and at home (linux, iso8859-2).
Hence the question: how can i get a string of my local encoding, on
linux or windows? or how do i tell iconv “convert to my local encoding”?

thank you,

emmanuel
[1] i thought about it late, because i didn’t think latin2 has so many
chars from latin1 as it does; many times the conversion would be successful.

Emmanuel Touzery wrote:

a string is considered by ruby as encoded as <insert your locale

. If you want to treat strings from other encodings, you can
convert encoding using “iconv” (bundled with ruby 1.8); in your case,
you can use iconv to convert the string to your local encoding
(iso-8859-1) and then capitalize will work fine.

which made me wonder: how do I find out what is the current local
encoding for the computer in a portable (unix/windows) way?

emmanuel

Hi,

···

At Thu, 25 Sep 2003 19:41:57 +0900, Emmanuel Touzery wrote:

I'm reading data from different encodings (web pages), i first 

thought about converting all to unicode, but it’s not handy right now in
ruby. Then i thought i might as well convert it all to my local encoding
for easy processing in ruby (uppercase, regexps etc) [1]. it’s easy to
hardcode my local encoding in the app, but i’d like to make it generic,
to work at my work (windows, cp1250) and at home (linux, iso8859-2).
Hence the question: how can i get a string of my local encoding, on
linux or windows? or how do i tell iconv “convert to my local encoding”?

On many unixes, environment variables LC_CTYPE or LANG would be
used for that purpose. Current linux’s iconv accepts both of
iso8859-2 and cp1250, and I expect libiconv for win32 does too.


Nobu Nakada