Ruby extension for codeset conversion.
Iconv is a wrapper class for UNIX 95 iconv() function family, which
translates string between various coding systems.
See Open Group[外部]'s on-line documents for more details.
Which coding systems are available, it depends on the platform.
Iconv.new(to, from) {|cd| ...}Creates new code converter from a coding-system designated with from to another one designated with to.
coding-system name for destination.
coding-system name for source.
TypeErrorif to or from aren't String
ArgumentErrorif designated converter couldn't find out.
SystemCallErrorwhen iconv_open(3) failed.
Iconv.open(to, from)Equivalents to Iconv.new except with in the case of called with a block, yields with the new instance and closes it, and returns the result which returned from the block.
Iconv.iconv(to, from, *strs)Shorthand for
Iconv.open(to, from) {|cd| (strs + [nil]).collect {|s| cd.iconv(s)}}
see Iconv.new.
strings to be converted.
exceptions thrown by Iconv.new, Iconv.open and Iconv#iconv.
Iconv.conv(to, from, str)Shorthand for
Iconv.iconv(to, from, str).join
see Iconv.iconv
Iconv.list {|*aliases| ... }Iterates each alias sets.
Iconv#closeFinishes conversion.
close are guaranteed to
end successfully.Iconv#iconv(str, [ start = 0, [ length = -1 ] ])Converts string and returns converted one.
String, converts str[start, length].
Returns converted string.nil, places converter
itself into initial shift state and just returns a string contains
the byte sequence to change the output buffer to its initial shift
state.string to be converted or nil.
starting offset.
conversion length,
nil or -1 means whole string from start.
Base exceptional attributes from Iconv.
Iconv::Failure#successReturns string(s) translated successfully until the exception occurred.
Iconv::Failure#failedReturns substring of the original string passed to Iconv that starts at the character caused the exception.
Iconv::Failure#inspectReturns inspected string like as: #<type: "success", "failed">
Input conversion stopped due to an input byte that does not belong to the input codeset, or the output codeset does not contain the character.
ArgumentError
Iconv::Failure
Input conversion stopped due to an incomplete character or shift sequence at the end of the input buffer.
ArgumentError
Iconv::Failure
Iconv library internal error. Must not occur.
RuntimeError
Iconv::Failure
Instantiate a new Iconv, use method Iconv#iconv.
cd = Iconv.new(to, from)
begin
input.each {|s| output << cd.iconv(s)}
output << cd.iconv(nil) # don't forget this
ensure
cd.close
endInvoke Iconv.open with a block.
Iconv.open(to, from) do |cd|
input.each {|s| output << cd.iconv(s)}
output << cd.iconv(nil)
endShorthand for (2).
Iconv.iconv(to, from, *input.to_a)