Example #1
0
  private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, int value) {
    int n;
    try {
      n = value < 0 ? 0 : enc.codeToMbcLength(value);
    } catch (EncodingException ee) {
      n = 0;
    }

    if (n <= 0) throw runtime.newRangeError(this.toString() + " out of char range");

    ByteList bytes = new ByteList(n);
    enc.codeToMbc(value, bytes.getUnsafeBytes(), 0);
    bytes.setRealSize(n);
    return bytes;
  }