るりまサーチ

最速Rubyリファレンスマニュアル検索!
143件ヒット [1-100件を表示] (0.079秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:p[x] > クエリ:force_encoding[x]

別のキーワード

  1. csv force_quotes?
  2. string force_encoding
  3. _builtin force_encoding
  4. options force_update
  5. lazy force

クラス

キーワード

検索結果

<< 1 2 > >>

String#force_encoding(encoding) -> self (18145.0)

文字列の持つエンコーディング情報を指定された encoding に変えます。

...ray#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_e...

Encoding::Converter#insert_output(string) -> nil (6138.0)

変換器内のバッファに文字列を挿入します。 バッファに保持された文字列は、次の変換時の変換結果と一緒に返されます。

...されるべきです。

@param string 挿入する文字列

//emlist[][ruby]{
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
src = "HIRAGANA LETTER A is \u{3042}."
dst = ""
p
ec.primitive_convert(src, dst) #=> :undefined_conversion
p
uts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER...
...t_output("<err>")
p
ec.primitive_convert(src, dst) #=> :finished
p
uts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is <err>.", ""]

ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
src = "\u{306F 3041 3068 2661 3002}" # U+2661 is not representable in iso-2022-jp
dst = ""
p
ec.primit...
...ndefined_conversion
p
uts "[#{dst.dump}, #{src.dump}]" #=> ["\e$B$O$!$H".force_encoding("ISO-2022-JP"), "\xE3\ x80\x82"]
ec.insert_output "?" # state change required to output "?".
p
ec.primitive_convert(src, dst) #=> :finished
p
uts "[#{dst.dump}, #{src.dump}]" #=> ["\e$B$O$...

Encoding#replicate(name) -> Encoding (6120.0)

レシーバのエンコーディングを複製(replicate)します。 複製されたエンコーディングは元のエンコーディングと同じバイト構造を持たなければなりません。 name という名前のエンコーディングが既に存在する場合は ArgumentError を発生します。

...レシーバのエンコーディングを複製(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?...

Encoding.compatible?(obj1, obj2) -> Encoding | nil (6120.0)

2つのオブジェクトのエンコーディングに関する互換性をチェックします。 互換性がある場合はそのエンコーディングを、 ない場合は nil を返します。

...ェクトを返します。

//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
//}

引数が文字列でない場合でも、両...
...ことができます。
//emlist[例][ruby]{
Encoding.compatible?(Encoding::UTF_8, Encoding::CP932)
# => nil
Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII)
# => #<Encoding:UTF-8>
//}
@param obj1 チェック対象のオブジェクト
@param obj2 チェック対象のオブジェクト...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer) -> Symbol (6114.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...Encoding::Converter#primitive_convert が唯一の方法になります。

@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytes...
...容量
@param options 変換の詳細を指定する定数やハッシュ
@return 変換結果を表す Symbol

options には以下が指定できます。

: hash form
:partial_input => true # source buffer may be part of larger source
:after_output => true # stop conversi...
...put before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT

戻り値は以下のうちのどれかです。

* :invalid_byte_sequence
* :incomplete_input
* :undefined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_emp...

絞り込み条件を変える

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset) -> Symbol (6114.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...Encoding::Converter#primitive_convert が唯一の方法になります。

@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytes...
...容量
@param options 変換の詳細を指定する定数やハッシュ
@return 変換結果を表す Symbol

options には以下が指定できます。

: hash form
:partial_input => true # source buffer may be part of larger source
:after_output => true # stop conversi...
...put before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT

戻り値は以下のうちのどれかです。

* :invalid_byte_sequence
* :incomplete_input
* :undefined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_emp...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset, destination_bytesize) -> Symbol (6114.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...Encoding::Converter#primitive_convert が唯一の方法になります。

@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytes...
...容量
@param options 変換の詳細を指定する定数やハッシュ
@return 変換結果を表す Symbol

options には以下が指定できます。

: hash form
:partial_input => true # source buffer may be part of larger source
:after_output => true # stop conversi...
...put before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT

戻り値は以下のうちのどれかです。

* :invalid_byte_sequence
* :incomplete_input
* :undefined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_emp...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset, destination_bytesize, options) -> Symbol (6114.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...Encoding::Converter#primitive_convert が唯一の方法になります。

@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytes...
...容量
@param options 変換の詳細を指定する定数やハッシュ
@return 変換結果を表す Symbol

options には以下が指定できます。

: hash form
:partial_input => true # source buffer may be part of larger source
:after_output => true # stop conversi...
...put before input
: integer form
Encoding::Converter::PARTIAL_INPUT
Encoding::Converter::AFTER_OUTPUT

戻り値は以下のうちのどれかです。

* :invalid_byte_sequence
* :incomplete_input
* :undefined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_emp...

Regexp#fixed_encoding? -> bool (3038.0)

正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。

...# => #<Encoding:US-ASCII>
r =~ "\u{6666} a" # => 2
r =~ "\xa1\xa2 a".force_encoding("euc-jp") # => 2
r =~ "abc".force_encoding("euc-jp") # => 0

r = /a/u
r.fixed_encoding? # => true
r.encoding...
...u{6666} a" # => 2
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # => 0

r = /\u{6666}/
r.fixed_encoding?...
...# => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 0
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # => nil
//}...

String (116.0)

文字列のクラスです。 ヌル文字を含む任意のバイト列を扱うことができます。 文字列の長さにはメモリ容量以外の制限はありません。

...字列のすべての文字を破壊的に大文字へ変更する
String#upcase! メソッドの使用例を以下に示します。

//emlist[例:String#upcase!][ruby]{
a = "string"
b = a
a.upcase!
p
a # => "STRING"
p
b # => "STRING"
//}

この例では、a に対してメソッドを呼ん...
...upcase! メソッドでそのオブジェクト自体が変更されたからです。

upcase! の非破壊版である String#upcase を使った例を以下に示します。
こちらでは a の変更が b に波及しません。

//emlist[例:String#upcase][ruby]{
a = "string"
b = a
a = a.upc...
...ase
p
a # => "STRING"
p
b # => "string"
//}

一般には、破壊的「ではない」メソッドを
中心に使っていくほうがバグが出にくくなります。

String クラスのメソッドには破壊的なメソッドも非破壊的なメソッドもあります。
破壊的な...

絞り込み条件を変える

<< 1 2 > >>