Help getting around iconv on a PC

Discussion in 'Ruby' started by Anders, Dec 1, 2005.

  1. Anders

    Anders Guest

    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
     
    Anders, Dec 1, 2005
    #1
    1. Advertising

  2. Anders

    Dave Burt Guest

    Anders wrote:
    > ... 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)
    > ...


    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
     
    Dave Burt, Dec 1, 2005
    #2
    1. Advertising

  3. Hi Anders, I haven't used iconv on windows with Ruby, but I found this
    googling...

    http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/58df01a5bd0=
    ab5b8/330841516d29bc54?lnk=3Dst&q=3Druby+iconv+windows+install&rnum=3D6&hl=
    =3Den#330841516d29bc54

    On 12/1/05, Anders <> wrote:
    > 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 t=

    ime.
    > class Iconv
    > def self.fix_malformed_characters(str)
    > iconv =3D Iconv.new("UTF-8", "UTF-8")
    > out =3D ""
    > begin
    > out << iconv.iconv(str)
    > rescue Iconv::IllegalSequence =3D> e
    > out << e.success
    > ch, str =3D 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=3D"utf-8"\?>/i, 'encodi=

    ng=3D"UTF-8"?>')
    > end
    >
    > def parse(xml_source)
    > xml_source =3D fix_encoding(xml_source)
    > xml_source =3D Iconv.fix_malformed_characters(xml=

    _source)
    > XmlSimple.xml_in(xml_source,
    > { 'ForceArray' =3D> false, 'KeepRoot' =3D=
    > true }
    > )
    > end
    > end
    >
    > end
    >
    >
    >
     
    Dan Smorey Jr., Dec 1, 2005
    #3
  4. Thanks, Dave! That did the trick.

    Anders
     
    Anders Schneiderman, Dec 1, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piet
    Replies:
    0
    Views:
    558
  2. Network/Software Buyer
    Replies:
    0
    Views:
    424
    Network/Software Buyer
    May 23, 2010
  3. Tim Ferrell

    Iconv.iconv and Windows XP

    Tim Ferrell, Oct 2, 2005, in forum: Ruby
    Replies:
    4
    Views:
    436
    nobuyoshi nakada
    Oct 4, 2005
  4. Mister Yu
    Replies:
    2
    Views:
    174
    Mister Yu
    Sep 30, 2007
  5. Krzysztof Cierpisz

    iconv "\n" (Iconv::InvalidCharacter)

    Krzysztof Cierpisz, Sep 8, 2009, in forum: Ruby
    Replies:
    0
    Views:
    190
    Krzysztof Cierpisz
    Sep 8, 2009
Loading...

Share This Page