public static int encMbcput(ThreadContext context, int c, byte[] buf, int p, Encoding enc) { int len = enc.codeToMbc(c, buf, p); // in MRI, this check occurs within some of the individual encoding functions, such as the // US-ASCII check for values >= 0x80. In MRI, unlike in JRuby, we can't throw Ruby errors // from within encoding logic, so we try to reproduce the expected results via normal // error codes here. // See MRI's rb_enc_mbcput and related downstream encoding functions. if (len < 0) { switch (len) { case ErrorCodes.ERR_INVALID_CODE_POINT_VALUE: throw context.runtime.newRangeError("invalid codepoint " + Long.toHexString(c & 0xFFFFFFFFL) + " in " + enc); case ErrorCodes.ERR_TOO_BIG_WIDE_CHAR_VALUE: throw context.runtime.newRangeError("" + (c & 0xFFFFFFFFL) + " out of char range"); } throw context.runtime.newEncodingError(EncodingError.fromCode(len).getMessage()); } return len; }
public static int encMbcput(ThreadContext context, int c, byte[] buf, int p, Encoding enc) { int len = enc.codeToMbc(c, buf, p); // in MRI, this check occurs within some of the individual encoding functions, such as the // US-ASCII check for values >= 0x80. In MRI, unlike in JRuby, we can't throw Ruby errors // from within encoding logic, so we try to reproduce the expected results via normal // error codes here. // See MRI's rb_enc_mbcput and related downstream encoding functions. if (len < 0) { switch (len) { case ErrorCodes.ERR_INVALID_CODE_POINT_VALUE: throw context.runtime.newRangeError("invalid codepoint " + Long.toHexString(c & 0xFFFFFFFFL) + " in " + enc); case ErrorCodes.ERR_TOO_BIG_WIDE_CHAR_VALUE: throw context.runtime.newRangeError("" + (c & 0xFFFFFFFFL) + " out of char range"); } throw context.runtime.newEncodingError(EncodingError.fromCode(len).getMessage()); } return len; }
/** rb_str_intern * */ @JRubyMethod(name = {"to_sym", "intern"}) public RubySymbol intern() { final Ruby runtime = getRuntime(); if (scanForCodeRange() == CR_BROKEN) { throw runtime.newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect()); } RubySymbol symbol = runtime.getSymbolTable().getSymbol(value); if (symbol.getBytes() == value) shareLevel = SHARE_LEVEL_BYTELIST; return symbol; }
/** rb_str_intern * */ @JRubyMethod(name = {"to_sym", "intern"}) public RubySymbol intern() { final Ruby runtime = getRuntime(); if (scanForCodeRange() == CR_BROKEN) { throw runtime.newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect()); } RubySymbol symbol = runtime.getSymbolTable().getSymbol(value); if (symbol.getBytes() == value) shareLevel = SHARE_LEVEL_BYTELIST; return symbol; }