Module: Kconv
| Relationships & Source Files | |
| Defined in: | ext/nkf/lib/kconv.rb | 
Overview
Kanji Converter for Ruby.
Constant Summary
- 
    ASCII =
    # File 'ext/nkf/lib/kconv.rb', line 38
ASCIINKF::ASCII
 - 
    AUTO =
    # File 'ext/nkf/lib/kconv.rb', line 26
Auto-Detect
NKF::AUTO
 - 
    BINARY =
    # File 'ext/nkf/lib/kconv.rb', line 34
BINARYNKF::BINARY
 - 
    EUC =
    # File 'ext/nkf/lib/kconv.rb', line 30
EUC-JP
NKF::EUC
 - 
    JIS =
    # File 'ext/nkf/lib/kconv.rb', line 28
ISO-2022-JP
NKF::JIS
 - 
    NOCONV =
    # File 'ext/nkf/lib/kconv.rb', line 36
NOCONVNKF::NOCONV
 - 
    SJIS =
    # File 'ext/nkf/lib/kconv.rb', line 32
Shift_JIS
NKF::SJIS
 - 
    UNKNOWN =
    # File 'ext/nkf/lib/kconv.rb', line 46
UNKNOWNNKF::UNKNOWN
 - 
    UTF16 =
    # File 'ext/nkf/lib/kconv.rb', line 42
UTF-16
NKF::UTF16
 - 
    UTF32 =
    # File 'ext/nkf/lib/kconv.rb', line 44
UTF-32
NKF::UTF32
 - 
    UTF8 =
    # File 'ext/nkf/lib/kconv.rb', line 40
UTF-8
NKF::UTF8
 
Class Method Summary
- 
    
      .guess(str)  ⇒ Encoding 
    
    mod_func
    
Guess input encoding by NKF.guess
 - 
    
      .iseuc(str)  ⇒ Boolean 
    
    mod_func
    
Returns whether input encoding is EUC-JP or not.
 - 
    
      .isjis(str)  ⇒ Boolean 
    
    mod_func
    
Returns whether input encoding is ISO-2022-JP or not.
 - 
    
      .issjis(str)  ⇒ Boolean 
    
    mod_func
    
Returns whether input encoding is Shift_JIS or not.
 - 
    
      .isutf8(str)  ⇒ Boolean 
    
    mod_func
    
Returns whether input encoding is UTF-8 or not.
 - 
    
      .kconv(str, to_enc, from_enc = nil)  
    
    mod_func
    
Convert
strtoto_enc. - 
    
      .toeuc(str)  ⇒ String 
    
    mod_func
    
Convert
strto EUC-JP. - 
    
      .tojis(str)  ⇒ String 
    
    mod_func
    
Convert
strto ISO-2022-JP. - 
    
      .tolocale  ⇒ String 
    
    mod_func
    
Convert
selfto locale encoding. - 
    
      .tosjis(str)  ⇒ String 
    
    mod_func
    
Convert
strto Shift_JIS. - 
    
      .toutf16(str)  ⇒ String 
    
    mod_func
    
Convert
strto UTF-16. - 
    
      .toutf32(str)  ⇒ String 
    
    mod_func
    
Convert
strto UTF-32. - 
    
      .toutf8(str)  ⇒ String 
    
    mod_func
    
Convert
strto UTF-8. 
Class Method Details
    .guess(str)  ⇒ Encoding  (mod_func)  
Guess input encoding by NKF.guess
    .iseuc(str)  ⇒ Boolean  (mod_func)  
Returns whether input encoding is EUC-JP or not.
Note don’t expect this return value is MatchData.
# File 'ext/nkf/lib/kconv.rb', line 156
def iseuc(str) str.dup.force_encoding(EUC).valid_encoding? end
    .isjis(str)  ⇒ Boolean  (mod_func)  
Returns whether input encoding is ISO-2022-JP or not.
# File 'ext/nkf/lib/kconv.rb', line 174
def isjis(str) /\A [\t\n\r\x20-\x7E]* (?: (?:\x1b \x28 I [\x21-\x7E]* |\x1b \x28 J [\x21-\x7E]* |\x1b \x24 @ (?:[\x21-\x7E]{2})* |\x1b \x24 B (?:[\x21-\x7E]{2})* |\x1b \x24 \x28 D (?:[\x21-\x7E]{2})* )* \x1b \x28 B [\t\n\r\x20-\x7E]* )* \z/nox =~ str.dup.force_encoding('BINARY') ? true : false end
    .issjis(str)  ⇒ Boolean  (mod_func)  
Returns whether input encoding is Shift_JIS or not.
# File 'ext/nkf/lib/kconv.rb', line 165
def issjis(str) str.dup.force_encoding(SJIS).valid_encoding? end
    .isutf8(str)  ⇒ Boolean  (mod_func)  
Returns whether input encoding is UTF-8 or not.
# File 'ext/nkf/lib/kconv.rb', line 193
def isutf8(str) str.dup.force_encoding(UTF8).valid_encoding? end
.kconv(str, to_enc, from_enc = nil) (mod_func)
Convert str to to_enc. to_enc and from_enc are given as constants of Kconv or Encoding objects.
.toeuc(str) ⇒ String (mod_func)
Convert str to EUC-JP
.tojis(str) ⇒ String (mod_func)
Convert str to ISO-2022-JP
.tolocale ⇒ String (mod_func)
Convert self to locale encoding
# File 'ext/nkf/lib/kconv.rb', line 128
def tolocale(str) kconv(str, Encoding.locale_charmap) end
.tosjis(str) ⇒ String (mod_func)
Convert str to Shift_JIS
.toutf16(str) ⇒ String (mod_func)
Convert str to UTF-16
.toutf32(str) ⇒ String (mod_func)
Convert str to UTF-32
.toutf8(str) ⇒ String (mod_func)
Convert str to UTF-8