Пример #1
0
  /**
   * Find an encoding given a Ruby object, coercing it to a String in the process.
   *
   * @param str the object to coerce and use to look up encoding. The coerced String must be
   *     ASCII-compatible.
   * @return the Encoding object found, nil (for internal), or raises ArgumentError
   */
  public Entry findEntry(IRubyObject str) {
    ByteList name = str.convertToString().getByteList();
    checkAsciiEncodingName(name);

    SpecialEncoding special = SpecialEncoding.valueOf(name);
    if (special != null) {
      return findEntryFromEncoding(special.toEncoding(runtime));
    }

    return findEntryWithError(name);
  }
Пример #2
0
  public Encoding getEncodingFromString(String string) {
    if (string == null) return null;

    ByteList name = new ByteList(ByteList.plain(string));
    checkAsciiEncodingName(name);

    SpecialEncoding special = SpecialEncoding.valueOf(name);
    if (special != null) {
      return special.toEncoding(runtime);
    }

    return findEncodingWithError(name);
  }