Forum: Ruby Help getting around iconv on a PC

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
64ac86301d8115d9812a1cd92abebfc3?d=identicon&s=25 schneida (Guest)
on 2005-12-01 22:35
(Received via mailing list)
I've just started using Ruby again, and maybe it's because it's been
awhile since I've used it, but I've gotten stuck.  I want to use the
bloglines Webservice API.  So, I downloaded and installed it as well as
simple-xml, which it uses.  I run a simple test:

require 'webservice/bloglines'
print "done!\n"

Ruby chokes, saying:

:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require__': No such file to load -- iconv (LoadError)
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require'
	from c:/ruby/lib/ruby/site_ruby/1.8/webservice/parser.rb:4
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require__'
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require'
	from c:/ruby/lib/ruby/site_ruby/1.8/webservice/restapi.rb:7
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require__'
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require'
	from c:/ruby/lib/ruby/site_ruby/1.8/webservice/bloglines.rb:3
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require__'
	from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in
`require'
	from test.rbw:1

As far as I can tell from looking around the web, iconv is a Unix
library, and I'm on a PC running WinXP.  How do I work around this?  To
figure out what the parser is using iconv for, I've included the code
below.  Any help would be greatly appreciated.

Thanks,
Anders Schneiderman
SEIU International
-------------------------------------------------------------------------------------

# $Id: parser.rb,v 1.2 2004/09/29 04:19:10 date Exp $

require 'xmlsimple'
require 'iconv'

# handling invalid character
#	 Replace from invalid character to `?'
#	 (instead of numerical character reference).
#	 Because REXML convert numerical character reference at parsing time.
class Iconv
	def self.fix_malformed_characters(str)
		iconv = Iconv.new("UTF-8", "UTF-8")
		out = ""
		begin
			out << iconv.iconv(str)
		rescue Iconv::IllegalSequence => e
			out << e.success
			ch, str = e.failed.split(//n, 2)
			out << if respond_to?(:unknown_unicode_handler)
							 unknown_unicode_handler(ch)
						 else
							 "?"
						 end
			retry
		end
		return out
	end
end

module WebService

	class Parser
		def initialize
		end

		# for REXML
		def fix_encoding(xml_source)
			 xml_source.sub(/encoding="utf-8"\?>/i, 'encoding="UTF-8"?>')
		end

		def parse(xml_source)
			xml_source = fix_encoding(xml_source)
			xml_source = Iconv.fix_malformed_characters(xml_source)
			XmlSimple.xml_in(xml_source,
				{ 'ForceArray' => false, 'KeepRoot' => true }
			)
		end
	end

end
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 dave (Guest)
on 2005-12-01 22:51
(Received via mailing list)
Anders wrote:
> `require__': No such file to load -- iconv (LoadError)
> ...

I've put together a package to install iconv on a One-Click Ruby box
here:
http://dave.burt.id.au/ruby/iconv.zip

Cheers,
Dave
1a5308cf823e320bced9f0cfed49ba33?d=identicon&s=25 dsmorey (Guest)
on 2005-12-01 22:59
(Received via mailing list)
Hi Anders, I haven't used iconv on windows with Ruby, but I found this
googling...

http://groups.google.com/group/comp.lang.ruby/brow...
64ac86301d8115d9812a1cd92abebfc3?d=identicon&s=25 schneida (Guest)
on 2005-12-01 23:32
(Received via mailing list)
Thanks, Dave!  That did the trick.

Anders
This topic is locked and can not be replied to.