Пример #1
0
  @SuppressWarnings("unchecked")
  @JRubyMethod(name = "name_list", meta = true)
  public static IRubyObject name_list(ThreadContext context, IRubyObject recv) {
    Ruby runtime = context.runtime;
    EncodingService service = runtime.getEncodingService();

    RubyArray result =
        runtime.newArray(service.getEncodings().size() + service.getAliases().size());
    HashEntryIterator i;
    i = service.getEncodings().entryIterator();
    while (i.hasNext()) {
      CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
          ((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>) i.next());
      result.append(
          RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
    }
    i = service.getAliases().entryIterator();
    while (i.hasNext()) {
      CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
          ((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>) i.next());
      result.append(
          RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
    }

    result.append(runtime.newString(EXTERNAL));
    result.append(runtime.newString(LOCALE));

    return result;
  }
Пример #2
0
  @SuppressWarnings("unchecked")
  @JRubyMethod(name = "names")
  public IRubyObject names(ThreadContext context) {
    Ruby runtime = context.runtime;
    EncodingService service = runtime.getEncodingService();
    Entry entry = service.findEncodingOrAliasEntry(name);

    RubyArray result = runtime.newArray();
    HashEntryIterator i;
    i = service.getEncodings().entryIterator();
    while (i.hasNext()) {
      CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
          ((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>) i.next());
      if (e.value == entry) {
        result.append(
            RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
      }
    }
    i = service.getAliases().entryIterator();
    while (i.hasNext()) {
      CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
          ((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>) i.next());
      if (e.value == entry) {
        result.append(
            RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
      }
    }
    result.append(runtime.newString(EXTERNAL));
    result.append(runtime.newString(LOCALE));

    return result;
  }