# kconv.rb - Kanji Converter.
# $Id: kconv.rb 11708 2007-02-12 23:01:19Z shyouhei $
# kconv.rb implements the Kconv class for Kanji Converter. Additionally,
# some methods in String classes are added to allow easy conversion.
# Kanji Converter for Ruby.
REVISION = %q$Revision: 11708 $
# Regexp of Shift_JIS string (private constant)
[\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc]
# Regexp of EUC-JP string (private constant)
\x8f [\xa1-\xfe] [\xa1-\xfe] |
# Regexp of UTF-8 string (private constant)
[\xc2-\xdf] [\x80-\xbf] |
\xe0 [\xa0-\xbf] [\x80-\xbf] |
[\xe1-\xef] [\x80-\xbf] [\x80-\xbf] |
\xf0 [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |
[\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |
\xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf]
# Kconv.kconv(str, out_code, in_code = Kconv::AUTO)
# Convert <code>str</code> to out_code.
# <code>out_code</code> and <code>in_code</code> are given as constants of Kconv.
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want to decode them, use NKF.nkf.
def kconv(str, out_code, in_code = AUTO)
# Kconv.tojis(str) -> string
# Convert <code>str</code> to ISO-2022-JP
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-jxm0', str).
# Kconv.toeuc(str) -> string
# Convert <code>str</code> to EUC-JP
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-exm0', str).
# Kconv.tosjis(str) -> string
# Convert <code>str</code> to Shift_JIS
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-sxm0', str).
# Kconv.toutf8(str) -> string
# Convert <code>str</code> to UTF-8
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-wxm0', str).
# Kconv.toutf16(str) -> string
# Convert <code>str</code> to UTF-16
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-w16xm0', str).
# Kconv.guess(str) -> integer
# Guess input encoding by NKF.guess2
# Kconv.guess_old(str) -> integer
# Guess input encoding by NKF.guess1
module_function :guess_old
# Kconv.iseuc(str) -> obj or nil
# Returns whether input encoding is EUC-JP or not.
# *Note* don't expect this return value is MatchData.
# Kconv.issjis(str) -> obj or nil
# Returns whether input encoding is Shift_JIS or not.
# *Note* don't expect this return value is MatchData.
RegexpShiftjis.match( str )
# Kconv.isutf8(str) -> obj or nil
# Returns whether input encoding is UTF-8 or not.
# *Note* don't expect this return value is MatchData.
# String#kconv(out_code, in_code = Kconv::AUTO)
# Convert <code>self</code> to out_code.
# <code>out_code</code> and <code>in_code</code> are given as constants of Kconv.
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want to decode them, use NKF.nkf.
def kconv(out_code, in_code=Kconv::AUTO)
Kconv::kconv(self, out_code, in_code)
# Convert <code>self</code> to ISO-2022-JP
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-jxm0', str).
def tojis; Kconv.tojis(self) end
# Convert <code>self</code> to EUC-JP
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-exm0', str).
def toeuc; Kconv.toeuc(self) end
# String#tosjis -> string
# Convert <code>self</code> to Shift_JIS
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-sxm0', str).
def tosjis; Kconv.tosjis(self) end
# String#toutf8 -> string
# Convert <code>self</code> to UTF-8
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-wxm0', str).
def toutf8; Kconv.toutf8(self) end
# String#toutf16 -> string
# Convert <code>self</code> to UTF-16
# This method decode MIME encoded string and
# convert halfwidth katakana to fullwidth katakana.
# If you don't want it, use NKF.nkf('-w16xm0', str).
def toutf16; Kconv.toutf16(self) end
# String#iseuc -> obj or nil
# Returns whether <code>self</code>'s encoding is EUC-JP or not.
# *Note* don't expect this return value is MatchData.
def iseuc; Kconv.iseuc(self) end
# String#issjis -> obj or nil
# Returns whether <code>self</code>'s encoding is Shift_JIS or not.
# *Note* don't expect this return value is MatchData.
def issjis; Kconv.issjis(self) end
# String#isutf8 -> obj or nil
# Returns whether <code>self</code>'s encoding is UTF-8 or not.
# *Note* don't expect this return value is MatchData.
def isutf8; Kconv.isutf8(self) end