@Deprecated // no-longer used + confusing argument order public static IRubyObject stringOrNil(ByteList value, ThreadContext context) { if (value == null) return context.nil; return RubyString.newStringShared(context.runtime, value); }
@Deprecated // no-longer used + confusing argument order public static IRubyObject stringOrNil(ByteList value, ThreadContext context) { if (value == null) return context.nil; return RubyString.newStringShared(context.runtime, value); }
private static RubyString newStringShared(Ruby runtime, ByteList bytes, Encoding encoding, int cr) { RubyString str = newStringShared(runtime, runtime.getString(), bytes, encoding); str.flags |= cr; return str; }
public final RubyString getFrozenString(ThreadContext context, int bytelistIndex, int stringIndex, int codeRange) { RubyString str = frozenStrings[stringIndex]; if (str == null) { str = frozenStrings[stringIndex] = context.runtime.freezeAndDedupString((RubyString) RubyString.newStringShared(context.runtime, getByteList(bytelistIndex), codeRange).freeze(context)); } return str; }
@JRubyMethod(meta = true) public static IRubyObject ver(ThreadContext context, IRubyObject recv) { context.runtime.getWarnings().warn(IRubyWarnings.ID.DEPRECATED_METHOD, "BigDecimal.ver is deprecated; use BigDecimal::VERSION instead"); return RubyString.newStringShared(context.runtime, VERSION); }
/** rb_str_s_new * */ public static RubyString newInstance(IRubyObject recv, IRubyObject[] args, Block block) { RubyString newString = newStringShared(recv.getRuntime(), ByteList.EMPTY_BYTELIST); newString.setMetaClass((RubyClass) recv); newString.callInit(args, block); return newString; }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, meta = true) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject arg) { final RubyString str = operandCheck(arg); return RubyString.newStringShared(context.runtime, quote(str)); }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, meta = true) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject arg) { final RubyString str = operandCheck(arg); return RubyString.newStringShared(context.runtime, quote(str)); }
@JRubyMethod(meta = true) public static IRubyObject ver(ThreadContext context, IRubyObject recv) { context.runtime.getWarnings().warn(IRubyWarnings.ID.DEPRECATED_METHOD, "BigDecimal.ver is deprecated; use BigDecimal::VERSION instead"); return RubyString.newStringShared(context.runtime, VERSION); }
public final RubyString getFrozenString(ThreadContext context, int bytelistIndex, int stringIndex, int codeRange) { RubyString str = frozenStrings[stringIndex]; if (str == null) { str = frozenStrings[stringIndex] = context.runtime.freezeAndDedupString((RubyString) RubyString.newStringShared(context.runtime, getByteList(bytelistIndex), codeRange).freeze(context)); } return str; }
private static RubyNumeric convertString(ThreadContext context, final IRubyObject s, RubyFixnum zero) { if (s == context.nil) return zero; final Ruby runtime = context.runtime; if (s.callMethod(context, "include?", RubyString.newStringShared(runtime, SEP)).isTrue()) { return (RubyNumeric) f_to_r(context, s); } if (f_gt_p(context, s.callMethod(context, "count", RubyString.newStringShared(runtime, _eE)), zero)) { return (RubyNumeric) f_to_f(context, s); } return (RubyNumeric) f_to_i(context, s); }
private static RubyNumeric convertString(ThreadContext context, final IRubyObject s, RubyFixnum zero) { if (s == context.nil) return zero; final Ruby runtime = context.runtime; if (s.callMethod(context, "include?", RubyString.newStringShared(runtime, SEP)).isTrue()) { return (RubyNumeric) f_to_r(context, s); } if (f_gt_p(context, s.callMethod(context, "count", RubyString.newStringShared(runtime, _eE)), zero)) { return (RubyNumeric) f_to_f(context, s); } return (RubyNumeric) f_to_i(context, s); }
/** * Check if HOME environment variable is not nil nor empty * @param context */ private static RubyString checkHome(ThreadContext context) { Ruby runtime = context.runtime; IRubyObject home = runtime.getENV().fastARef(RubyString.newStringShared(runtime, RubyDir.HOME)); if (home == null || home == context.nil || ((RubyString) home).size() == 0) { throw runtime.newArgumentError("couldn't find HOME environment -- expanding `~'"); } return (RubyString) home; }
private static IRubyObject rbThrowInternal(ThreadContext context, IRubyObject tag, IRubyObject arg) { final Ruby runtime = context.runtime; runtime.getGlobalVariables().set("$!", context.nil); RubyContinuation.Continuation continuation = context.getActiveCatch(tag); if (continuation != null) { continuation.args = arg == null ? IRubyObject.NULL_ARRAY : new IRubyObject[] { arg }; throw continuation; } // No catch active for this throw IRubyObject value = arg == null ? context.nil : arg; throw uncaughtThrow(runtime, tag, value, RubyString.newStringShared(runtime, uncaught_throw_p)); }
private static IRubyObject rbThrowInternal(ThreadContext context, IRubyObject tag, IRubyObject arg) { final Ruby runtime = context.runtime; runtime.getGlobalVariables().set("$!", context.nil); RubyContinuation.Continuation continuation = context.getActiveCatch(tag); if (continuation != null) { continuation.args = arg == null ? IRubyObject.NULL_ARRAY : new IRubyObject[] { arg }; throw continuation; } // No catch active for this throw IRubyObject value = arg == null ? context.nil : arg; throw uncaughtThrow(runtime, tag, value, RubyString.newStringShared(runtime, uncaught_throw_p)); }
public static RubyString string(MutableCallSite site, ByteList value, int cr, ThreadContext context) throws Throwable { MethodHandle handle = SmartBinder .from(STRING_SIGNATURE) .invoke(NEW_STRING_SHARED_HANDLE.apply("byteList", value)) .handle(); site.setTarget(handle); return RubyString.newStringShared(context.runtime, value, cr); }
public static RubyString newStringShared(Ruby runtime, RubyClass clazz, ByteList bytes, Encoding encoding) { if (bytes.getEncoding() == encoding) return newStringShared(runtime, clazz, bytes); RubyString str = new RubyString(runtime, clazz, bytes.makeShared(bytes.getBegin(), bytes.getRealSize()), encoding); str.shareLevel = SHARE_LEVEL_BUFFER; // since passing an encoding in does bytes.setEncoding(encoding) return str; }
public static IRubyObject putc(ThreadContext context, IRubyObject maybeIO, IRubyObject object) { if (maybeIO instanceof RubyIO) { ((RubyIO) maybeIO).putc(context, object); } else { byte c = RubyNumeric.num2chr(object); IRubyObject str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList(c)); sites(context).write.call(context, maybeIO, maybeIO, str); } return object; }
@JRubyMethod(required = 1) public IRubyObject putc(ThreadContext context, IRubyObject ch) { IRubyObject str; if (ch instanceof RubyString) { str = ((RubyString) ch).substr(context.runtime, 0, 1); } else { str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList(RubyNumeric.num2chr(ch))); } sites(context).write.call(context, this, this, str); return ch; }
@JRubyMethod(required = 1) public IRubyObject putc(ThreadContext context, IRubyObject ch) { IRubyObject str; if (ch instanceof RubyString) { str = ((RubyString) ch).substr(context.runtime, 0, 1); } else { str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList(RubyNumeric.num2chr(ch))); } sites(context).write.call(context, this, this, str); return ch; }