Ruby 2.4.0 リファレンスマニュアル > ライブラリ一覧 > kconvライブラリ > Kconvモジュール > isjis

module function Kconv.#isjis

isjis(str) -> bool[permalink][rdoc]

文字列 str が ISO-2022-JP なバイト列として正当であるかどうかを判定します。

[PARAM] str:
判定対象の文字列

[SEE_ALSO] String#isjis



require 'kconv'

euc_str = "\
\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\
\xa5\xd7\xa5\xed\xa5\xb0\xa5\xe9\xa5\xdf\xa5\xf3\xa5\xb0\xb8\xc0\xb8\xec\
\x52\x75\x62\x79".force_encoding('EUC-JP')

jis_str = "\
\x1b\x24\x42\x25\x2a\x25\x56\x25\x38\x25\x27\x25\x2f\x25\x48\x3b\x58\x38\x7e\
\x25\x57\x25\x6d\x25\x30\x25\x69\x25\x5f\x25\x73\x25\x30\x38\x40\x38\x6c\x1b\x28\x42\
\x52\x75\x62\x79".force_encoding('ISO-2022-JP')

euc_str.isjis  # => false
jis_str.isjis  # => true