luislavena / exerb-mingw

Exerb support for mingw/rubyinstaller
http://exerb.sourceforge.jp/
7 stars 3 forks source link

failed to load encoding (GB18030); use ASCII-8BIT instead #2

Open sevk opened 7 years ago

sevk commented 7 years ago
#cat a.rb

$ec1 = Encoding::Converter.new("UTF-8","GB18030", :universal_newline => true)
# $ec2 = Encoding::Converter.new("GB18030","UTF-8", :universal_newline => true)

puts $ec1.convert("酒") 
# puts $ec2.convert("酒") 
Z:\>mkexy a.rb && exerb a.rb
酒
酒

Z:\>a.exe
a.rb:3: warning: failed to load encoding (GB18030); use ASCII-8BIT instead
a.rb:6:in `convert': U+9152 from UTF-8 to ASCII-8BIT (Encoding::UndefinedConversionError)
        from a.rb:6:in `<main>'
        from a.rb:1:in `eval'

Z:\>

how to fix this ? thanks

Z-H-Sun commented 10 months ago

Include the following lines at the beginning:

require 'enc/gb18030'
require 'enc/trans/gb18030'

The second line is not necessary in the snippet you provided, but it will be required if you want to convert a string from GB18030 to other encodings.

Ideally, the import of such libraries should be automatic, but this is not yet possible with the current version of Exerb, so you still need to do this manually.