Class: Iconv

Class | Iconv
In: | lib/gettext/iconv.rb
Parent: | Object

Pseudo Iconv class

Provides Iconv.iconv which uses Ruby/GLib(1) functions. This library also required from ‘gettext’. If you require ‘gettext/iconv’, Iconv.iconv try to call Ruby/GLib function when it doesn‘t find original Iconv class(iconv.so).

(1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project. You can get binaries for Win32(One-Click Ruby Installer). <URL: ruby-gnome2.sourceforge.jp/>

### Methods

conv conv iconv

### Classes and Modules

Module Iconv::Failure
Class Iconv::IllegalSequence
Class Iconv::InvalidCharacter
Class Iconv::InvalidEncoding

### Public Class methods

conv(to, from, str)

[Source]

        # File lib/gettext/iconv.rb, line 37
    37:       def self.conv(to, from, str)
    38:         raise InvalidCharacter, "the 3rd argument is nil" unless str
    39:         begin
    40:           str = java.lang.String.new(str.unpack("C*").to_java(:byte), from)
    41:           str.getBytes(to).to_ary.pack("C*")
    42:         rescue java.io.UnsupportedEncodingException
    43:           raise InvalidEncoding
    44:         end
    45:       end

conv(to, from, str)

This is a function equivalent of Iconv.iconv.

- to: encoding name for destination
- from: encoding name for source
- str: strings to be converted
- Returns: Returns an Array of converted strings.

[Source]

        # File lib/gettext/iconv.rb, line 65
    65:           def self.conv(to, from, str)
    66:             begin
    67:               GLib.convert(str, to, from)
    68:             rescue GLib::ConvertError => e
    69:               case e.code
    70:               when GLib::ConvertError::NO_CONVERSION
    71:                 raise InvalidEncoding.new(str)
    72:               when GLib::ConvertError::ILLEGAL_SEQUENCE
    73:                 raise IllegalSequence.new(str)
    74:               else
    75:                 raise InvalidCharacter.new(str)
    76:               end
    77:             end
    78:           end

iconv(to, from, str)

[Source]

        # File lib/gettext/iconv.rb, line 95
    95:     def self.iconv(to, from, str)
    96:       conv(to, from, str).split(//)
    97:     end

[Validate]