Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (29 sloc) 1.17 KB
---
unicode: "To make your script cope with different character sets, you can set the $KCODE global (or specify the -K option to the interpreter):\r\n\
\r\n\
$KCODE='UTF8'\r\n\
\r\n\
Was originally introduced to signal the Ruby interpreter to go into a certain encoding mode. It's currently (mis)used by several libraries to set the global encoding of text (ie. jcode and activesupport)\r\n\
\r\n\
Values supported in Ruby1.8 appear to be:\r\n\
EUC ('-e', 'e')\r\n\
SJIS ('-s', 's')\r\n\
UTF8 ('-u', 'u')\r\n\
NONE ('-n', 'n')\r\n\
\r\n\
When manipulating strings, include the 'jcode' library:\r\n\
\r\n\
require 'jcode'\r\n\
\r\n\
This will extend the string class to behave in a multi-byte fashion when appropriate, as well as introducing:\r\n\
\r\n\
\"fish\".mbchar? # Returns the index of the first multibyte character in the string, or nil\r\n\
\"cat\".jlength # The length, in characters rather than bytes, of the string\r\n\
\r\n\
You can get even more Unicode support by using ActiveSupport.\r\n\
\r\n\
require 'rubygems' rescue LoadError\r\n\
require 'active_support'\r\n\
\r\n\
$KCODE='UTF8'\r\n\
\"Caf\xC3\xA9\".chars.upcase"