/* * call-seq: * Encoding.find(string) -> enc * * Search the encoding with specified <i>name</i>. * <i>name</i> should be a string. * * Encoding.find("US-ASCII") #=> #<Encoding:US-ASCII> * * Names which this method accept are encoding names and aliases * including following special aliases * * "external":: default external encoding * "internal":: default internal encoding * "locale":: locale encoding * "filesystem":: filesystem encoding * * An ArgumentError is raised when no encoding with <i>name</i>. * Only <code>Encoding.find("internal")</code> however returns nil * when no encoding named "internal", in other words, when Ruby has no * default internal encoding. */ static VALUE enc_find(VALUE klass, VALUE enc) { int idx; if (RB_TYPE_P(enc, T_DATA) && is_data_encoding(enc)) return enc; idx = str_to_encindex(enc); if (idx == UNSPECIFIED_ENCODING) return Qnil; return rb_enc_from_encoding_index(idx); }
/* * call-seq: * Encoding.find(string) -> enc * Encoding.find(symbol) -> enc * * Search the encoding with specified <i>name</i>. * <i>name</i> should be a string or symbol. * * Encoding.find("US-ASCII") #=> #<Encoding:US-ASCII> * Encoding.find(:Shift_JIS) #=> #<Encoding:Shift_JIS> * * Names which this method accept are encoding names and aliases * including following special aliases * * "external":: default external encoding * "internal":: default internal encoding * "locale":: locale encoding * "filesystem":: filesystem encoding * * An ArgumentError is raised when no encoding with <i>name</i>. * Only <code>Encoding.find("internal")</code> however returns nil * when no encoding named "internal", in other words, when Ruby has no * default internal encoding. */ static VALUE enc_find(VALUE klass, VALUE enc) { int idx; if (is_obj_encoding(enc)) return enc; idx = str_to_encindex(enc); if (idx == UNSPECIFIED_ENCODING) return Qnil; return rb_enc_from_encoding_index(idx); }
static rb_encoding * str_to_encoding(VALUE enc) { return rb_enc_from_index(str_to_encindex(enc)); }