Sha256: c5c577f3221844d01c70c2cf038cbfc6fb26a2613304f187d11c0aeeee80ca9c

Contents?: true

Size: 910 Bytes

Versions: 2

Compression:

Stored size: 910 Bytes

Contents

# XSD4R - Charset handling with iconv.
# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.

# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.

unless ''.respond_to? :encode
  require 'iconv'
end

module XSD


class IconvCharset
  if ''.respond_to? :encode
    def self.safe_iconv(to, from, str)
      str.encode(to, from, :invalid => :replace, :undef => :replace, :replace => '?')
    end
  else
  def self.safe_iconv(to, from, str)
    iconv = Iconv.new(to, from)
    out = ""
    begin
      out << iconv.iconv(str)
    rescue Iconv::IllegalSequence => e
      out << e.success
      ch, str = e.failed.split(//, 2)
      out << '?'
      warn("Failed to convert #{ch}")
      retry
    end
    return out
  end
  end
end


end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
soap2r-1.5.8 lib/xsd/iconvcharset.rb
soap4r-r19-1.5.9 lib/xsd/iconvcharset.rb