/** int_chr * */ @JRubyMethod(name = "chr", compat = CompatVersion.RUBY1_8) public RubyString chr(ThreadContext context) { Ruby runtime = context.runtime; long value = getLongValue(); if (value < 0 || value > 0xff) throw runtime.newRangeError(this.toString() + " out of char range"); return RubyString.newStringShared(runtime, SINGLE_CHAR_BYTELISTS[(int)value]); }
/** int_chr * */ @JRubyMethod(name = "chr", compat = CompatVersion.RUBY1_8) public RubyString chr(ThreadContext context) { Ruby runtime = context.runtime; long value = getLongValue(); if (value < 0 || value > 0xff) throw runtime.newRangeError(this.toString() + " out of char range"); return RubyString.newStringShared(runtime, SINGLE_CHAR_BYTELISTS[(int)value]); }
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); try { enc.codeToMbc(value, bytes.getUnsafeBytes(), 0); } catch (EncodingException e) { throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName()); } bytes.setRealSize(n); return bytes; }
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); try { enc.codeToMbc(value, bytes.getUnsafeBytes(), 0); } catch (EncodingException e) { throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName()); } bytes.setRealSize(n); return bytes; }
/** int_chr * */ @JRubyMethod(name = "chr") public RubyString chr(ThreadContext context) { Ruby runtime = context.runtime; // rb_num_to_uint long i = getLongValue() & 0xFFFFFFFFL; int c = (int) i; Encoding enc; if (i > 0xff) { enc = runtime.getDefaultInternalEncoding(); if (enc == null) { throw runtime.newRangeError(toString() + " out of char range"); } return chrCommon(context, c, enc); } return RubyString.newStringShared(runtime, SINGLE_CHAR_BYTELISTS[c]); }
/** int_chr * */ @JRubyMethod(name = "chr") public RubyString chr(ThreadContext context) { Ruby runtime = context.runtime; // rb_num_to_uint long i = getLongValue() & 0xFFFFFFFFL; int c = (int) i; Encoding enc; if (i > 0xff) { enc = runtime.getDefaultInternalEncoding(); if (enc == null) { throw runtime.newRangeError(toString() + " out of char range"); } return chrCommon(context, c, enc); } return RubyString.newStringShared(runtime, SINGLE_CHAR_BYTELISTS[c]); }
@JRubyMethod(name = "chr", compat = CompatVersion.RUBY1_9) public RubyString chr19(ThreadContext context) { Ruby runtime = context.runtime; int value = (int)getLongValue(); if (value >= 0 && value <= 0xFF) { ByteList bytes = SINGLE_CHAR_BYTELISTS19[value]; return RubyString.newStringShared(runtime, bytes, bytes.getEncoding()); } else { Encoding enc = runtime.getDefaultInternalEncoding(); if (value > 0xFF && (enc == null || enc == ASCIIEncoding.INSTANCE)) { throw runtime.newRangeError(this.toString() + " out of char range"); } else { if (enc == null) enc = USASCIIEncoding.INSTANCE; return RubyString.newStringNoCopy(runtime, fromEncodedBytes(runtime, enc, (int)value), enc, 0); } } }
@JRubyMethod(name = "chr", compat = CompatVersion.RUBY1_9) public RubyString chr19(ThreadContext context) { Ruby runtime = context.runtime; int value = (int)getLongValue(); if (value >= 0 && value <= 0xFF) { ByteList bytes = SINGLE_CHAR_BYTELISTS19[value]; return RubyString.newStringShared(runtime, bytes, bytes.getEncoding()); } else { Encoding enc = runtime.getDefaultInternalEncoding(); if (value > 0xFF && (enc == null || enc == ASCIIEncoding.INSTANCE)) { throw runtime.newRangeError(this.toString() + " out of char range"); } else { if (enc == null) enc = USASCIIEncoding.INSTANCE; return RubyString.newStringNoCopy(runtime, fromEncodedBytes(runtime, enc, (int)value), enc, 0); } } }