Esempio n. 1
0
  @SuppressWarnings("unchecked")
  @JRubyMethod(name = "aliases", meta = true)
  public static IRubyObject aliases(ThreadContext context, IRubyObject recv) {
    Ruby runtime = context.runtime;
    EncodingService service = runtime.getEncodingService();

    IRubyObject list[] = service.getEncodingList();
    HashEntryIterator i = service.getAliases().entryIterator();
    RubyHash result = RubyHash.newHash(runtime);

    while (i.hasNext()) {
      CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
          ((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>) i.next());
      IRubyObject alias =
          RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context);
      IRubyObject name =
          RubyString.newUsAsciiStringShared(runtime, ((RubyEncoding) list[e.value.getIndex()]).name)
              .freeze(context);
      result.fastASet(alias, name);
    }

    result.fastASet(
        runtime.newString(EXTERNAL),
        runtime.newString(new ByteList(runtime.getDefaultExternalEncoding().getName())));
    result.fastASet(
        runtime.newString(LOCALE),
        runtime.newString(new ByteList(service.getLocaleEncoding().getName())));

    return result;
  }
Esempio n. 2
0
  @JRubyMethod(name = "locale_charmap", meta = true)
  public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv) {
    Ruby runtime = context.runtime;
    EncodingService service = runtime.getEncodingService();
    ByteList name = new ByteList(service.getLocaleEncoding().getName());

    return RubyString.newUsAsciiStringNoCopy(runtime, name);
  }
Esempio n. 3
0
 public Encoding toEncoding(Ruby runtime) {
   EncodingService service = runtime.getEncodingService();
   switch (this) {
     case LOCALE:
       return service.getLocaleEncoding();
     case EXTERNAL:
       return runtime.getDefaultExternalEncoding();
     case INTERNAL:
       return runtime.getDefaultInternalEncoding();
     case FILESYSTEM:
       // This needs to do something different on Windows. See encoding.c,
       // in the enc_set_filesystem_encoding function.
       return runtime.getDefaultExternalEncoding();
     default:
       throw new RuntimeException("invalid SpecialEncoding: " + this);
   }
 }