種類
- インスタンスメソッド (174)
- クラス (22)
- 特異メソッド (11)
- 文書 (11)
- モジュール関数 (11)
クラス
- Encoding (22)
-
Encoding
:: Converter (66) - Regexp (11)
- String (86)
モジュール
- Kconv (11)
キーワード
- InvalidByteSequenceError (11)
- String (11)
- compatible? (11)
- convert (11)
- encode (33)
-
fixed
_ encoding? (11) -
insert
_ output (11) - iseuc (11)
- isjis (11)
-
primitive
_ convert (44) - replicate (11)
-
unicode
_ normalize (10) -
unicode
_ normalized? (10) -
valid
_ encoding? (11) - 多言語化 (11)
検索結果
先頭5件
-
String
# force _ encoding(encoding) -> self (24397.0) -
文字列の持つエンコーディング情報を指定された encoding に変えます。
...情報を指定された encoding に変えます。
このとき実際のエンコーディングは変換されず、検査もされません。
Array#pack などで得られたバイト列のエンコーディングを指定する時に使います。
@param encoding 変更するエンコー......す文字列か Encoding オブジェクトを指定します。
//emlist[例][ruby]{
s = [164, 164, 164, 237, 164, 207].pack("C*")
p s.encoding #=> ASCII-8BIT
p s.force_encoding("EUC-JP") #=> "いろは"
p s.force_encoding(Encoding::EUC_JP)......#=> "いろは"
u = [12411, 12408, 12392].pack("U*")
u.force_encoding("UTF-8") #=> "ほへと"
u.force_encoding(Encoding::UTF_8) #=> "ほへと"
//}... -
Encoding
. compatible?(obj1 , obj2) -> Encoding | nil (21209.0) -
2つのオブジェクトのエンコーディングに関する互換性をチェックします。 互換性がある場合はそのエンコーディングを、 ない場合は nil を返します。
...列が取るであろう Encoding オブジェクトを返します。
//emlist[例][ruby]{
Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
#=> #<Encoding:ISO-8859-1>
Encoding.compatible?(
"\xa1".force_encoding("iso-8859-1"),
"\xa1\xa1".force_encoding("euc-jp"))
#=> nil
//}
引......両方のオブジェクトが encoding を持つ場合には
互換性を判定することができます。
//emlist[例][ruby]{
Encoding.compatible?(Encoding::UTF_8, Encoding::CP932)
# => nil
Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII)
# => #<Encoding:UTF-8>
//}
@param obj1 チェ... -
Encoding
# replicate(name) -> Encoding (21197.0) -
レシーバのエンコーディングを複製(replicate)します。 複製されたエンコーディングは元のエンコーディングと同じバイト構造を持たなければなりません。 name という名前のエンコーディングが既に存在する場合は ArgumentError を発生します。
...]{
encoding = Encoding::UTF_8.replicate("REPLICATED_UTF-8") #=> #<Encoding:REPLICATED_UTF-8>
encoding.name #=> "REPLICATED_UTF-8"
"\u3042".force_encoding(Encoding::UTF_8).valid_encoding? #=> true
"\u3042".force_encoding(encoding).valid_encoding?......#=> true
"\u3042".force_encoding(Encoding::SHIFT_JIS).valid_encoding? #=> false
//}... -
Regexp
# fixed _ encoding? -> bool (6239.0) -
正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
...*-
r = /a/
r.fixed_encoding? # => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u{6666} a" # => 2
r =~ "\xa1\xa2 a".force_encoding("euc-jp") # => 2
r =~ "abc".force_encoding("euc-jp")......_encoding? # => true
r.encoding # => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 2
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding:......=~ "abc".force_encoding("euc-jp") # => 0
r = /\u{6666}/
r.fixed_encoding? # => true
r.encoding # => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 0
begin
r =~ "\xa1\xa2".force_encoding("euc-jp"... -
String
# valid _ encoding? -> bool (6155.0) -
文字列の内容が、現在のエンコーディングに照らしあわせて妥当であれば true を返します。さもなくば false を返します。
...て妥当であれば
true を返します。さもなくば false を返します。
//emlist[例][ruby]{
"\xc2\xa1".force_encoding("UTF-8").valid_encoding? #=> true
"\xc2".force_encoding("UTF-8").valid_encoding? #=> false
"\x80".force_encoding("UTF-8").valid_encoding? #=> false
//}... -
Encoding
:: Converter # convert(source _ string) -> String (3118.0) -
与えられた文字列を変換して、変換できた結果を返します。 引数の末尾の文字がバイト列の途中で終わっている場合、そのバイト列は変換器内に取り置かれます。 変換を終了させるには Encoding::Converter#finish を呼びます。
...で終わっている場合、そのバイト列は変換器内に取り置かれます。
変換を終了させるには Encoding::Converter#finish を呼びます。
Encoding::Converter を用いると、文字列の一部または全部を渡して変換を行うことができます。よって......トを意識せずにストリームから読み出した文字列を変換したいときには Encoding::Converter が適します。
なお、Encoding::Converter#convert では、これらの例外を捕獲しても、例外を起こしたところから変換を再開することはできませ......ec = Encoding::Converter.new("euc-jp", "utf-8")
puts ec.convert("\xA4").dump #=> ""
puts ec.convert("\xA2").dump #=> "\xE3\x81\x82"
puts ec.finish.dump #=> ""
ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
puts ec.convert("\xE3").dump #=> "".force_encoding("IS... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer) -> Symbol (3048.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
...ッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buff......fer may be part of larger source
:after_output => true # stop conversion after output before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT
戻り値は以下のうちのどれかです。
* :invalid_byte_sequence
* :incomplete_input......itive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
when :... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset) -> Symbol (3048.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
...ッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buff......fer may be part of larger source
:after_output => true # stop conversion after output before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT
戻り値は以下のうちのどれかです。
* :invalid_byte_sequence
* :incomplete_input......itive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
when :... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset , destination _ bytesize) -> Symbol (3048.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
...ッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buff......fer may be part of larger source
:after_output => true # stop conversion after output before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT
戻り値は以下のうちのどれかです。
* :invalid_byte_sequence
* :incomplete_input......itive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
when :... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset , destination _ bytesize , options) -> Symbol (3048.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
...ッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buff......fer may be part of larger source
:after_output => true # stop conversion after output before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT
戻り値は以下のうちのどれかです。
* :invalid_byte_sequence
* :incomplete_input......itive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
when :...