Encoding* Encoding::from_index(STATE, int index) { if(Encoding* enc = try_as<Encoding>(encoding_list(state)->get(state, index))) { return enc; } else { return nil<Encoding>(); } }
Encoding* Encoding::alias(STATE, const char* name, const char* original) { int index = find_index(state, original); if(index < 0) return nil<Encoding>(); Tuple* ref = encoding_reference(state, index, name); encoding_map(state)->store(state, encoding_symbol(state, name), ref); add_constant(state, name, from_index(state, index)); return as<Encoding>(encoding_list(state)->get(state, index)); }
Encoding* Encoding::create_bootstrap(STATE, const char* name, Index index, OnigEncodingType* enc) { Encoding* e = create(state, enc); Tuple* ref = encoding_reference(state, index); encoding_map(state)->store(state, encoding_symbol(state, name), ref); encoding_list(state)->set(state, index, e); add_constant(state, name, e); return e; }
Encoding* Encoding::define(STATE, const char* name, OnigEncodingType* enc, Object* dummy) { Encoding* e = create(state, enc, dummy); e->name(state, String::create(state, name)); Array* list = encoding_list(state); size_t index = list->size(); Tuple* ref = encoding_reference(state, index); encoding_map(state)->store(state, encoding_symbol(state, name), ref); list->set(state, index, e); add_constant(state, name, e); return e; }
Encoding* Encoding::find(STATE, const char* name) { int index = find_index(state, name); if(index < 0) return nil<Encoding>(); return as<Encoding>(encoding_list(state)->get(state, index)); }
Encoding* Encoding::ascii8bit_encoding(STATE) { return as<Encoding>(encoding_list(state)->get(state, eBinary)); }
Encoding* Encoding::utf8_encoding(STATE) { return as<Encoding>(encoding_list(state)->get(state, eUtf8)); }
Encoding* Encoding::usascii_encoding(STATE) { return as<Encoding>(encoding_list(state)->get(state, eAscii)); }