Beispiel #1
0
  void Encoding::init(STATE) {
    onig_init();  // in regexp.cpp too, but idempotent.

    Class* enc = ontology::new_class_under(state, "EncodingClass", G(rubinius));

    GO(encoding).set(ontology::new_class_under(state, "Encoding", enc));
    G(encoding)->set_object_type(state, EncodingType);

    enc->set_const(state, "EncodingMap", LookupTable::create(state));
    enc->set_const(state, "EncodingList", Array::create(state, 3));

    G(encoding)->set_ivar(state, state->symbol("@default_external"), G(undefined));
    G(encoding)->set_ivar(state, state->symbol("@default_internal"), G(undefined));

    Encoding* ascii = create_bootstrap(state, "US-ASCII", eAscii, ONIG_ENCODING_US_ASCII);
    Encoding* binary = create_bootstrap(state, "ASCII-8BIT", eBinary, ONIG_ENCODING_ASCII);
    Encoding* utf8 = create_bootstrap(state, "UTF-8", eUtf8, ONIG_ENCODING_UTF_8);

    ascii->name(state, String::create(state, "US-ASCII"));
    binary->name(state, String::create(state, "ASCII-8BIT"));
    utf8->name(state, String::create(state, "UTF-8"));

#include "vm/gen/encoding_database.cpp"

    int index = -1;
    char* locale_charmap;

#ifdef HAVE_NL_LANGINFO
    setlocale(LC_CTYPE, "");
    locale_charmap = nl_langinfo(CODESET);
#else
    locale_charmap = "US-ASCII";
#endif

    enc->set_const(state, "LocaleCharmap", String::create(state, locale_charmap));

    index = find_index(state, locale_charmap);
    if(index < 0) index = find_index(state, "US-ASCII");

    create_internal(state, "locale", index);
    create_internal(state, "external", index);
    create_internal(state, "filesystem", index);
    create_internal(state, "internal", -1);

    Transcoding::init(state);
    Converter::init(state);
  }
Beispiel #2
0
  void Encoding::init(STATE) {
    onig_init();  // in regexp.cpp too, but idempotent.

    Class* enc = ontology::new_class_under(state, "Encoding", G(rubinius));
    enc->name(state, state->symbol("Rubinius::Encoding"));

    GO(encoding).set(ontology::new_class_under(state, "Encoding", enc));
    G(encoding)->set_object_type(state, EncodingType);
    G(encoding)->name(state, state->symbol("Encoding"));

    enc->set_const(state, "SymbolMap", LookupTable::create(state));
    enc->set_const(state, "IndexMap", LookupTable::create(state));

    Encoding* ascii = create_bootstrap(state, "US-ASCII", eAscii, ONIG_ENCODING_ASCII);
    Encoding* utf8 = create_bootstrap(state, "UTF-8", eUtf8, ONIG_ENCODING_UTF_8);

    ascii->name(state, String::create(state, "US-ASCII"));
    utf8->name(state, String::create(state, "UTF-8"));

#include "vm/gen/encoding_database.cpp"
  }