private RubyString replaceCommon(IRubyObject other) { modifyCheck(); RubyString otherStr = other.convertToString(); otherStr.shareLevel = shareLevel = SHARE_LEVEL_BYTELIST; value = otherStr.value; infectBy(otherStr); return otherStr; }
@JRubyMethod(name = "inspect") public RubyString inspect(final ThreadContext context) { RubyString i1 = inspectValue(context, begin).strDup(context.runtime); RubyString i2 = inspectValue(context, end); i1.cat(DOTDOTDOT, 0, isExclusive ? 3 : 2); i1.append(i2); i1.infectBy(i2); i1.infectBy(this); return i1; }
private IRubyObject inspect(String msg) { RubyString result = getRuntime().newString("#<" + getMetaClass() + " " + msg + ">"); if (str != null) result.infectBy(str); return result; }
/** inspect_hash * */ private IRubyObject inspectHash(final ThreadContext context) { final RubyString str = RubyString.newStringLight(context.runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE); str.infectBy(this); str.cat((byte)'{'); visitAll(context, InspectVisitor, str); str.cat((byte)'}'); return str; }
public final RubyString makeIndependent() { RubyClass klass = metaClass; RubyString str = strDup(klass.getClassRuntime(), klass); str.modify(); str.setFrozen(true); str.infectBy(this); return str; }
/** inspect_hash * */ private IRubyObject inspectHash(final ThreadContext context) { final RubyString str = RubyString.newStringLight(context.runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE); str.infectBy(this); str.cat((byte)'{'); visitAll(context, InspectVisitor, str); str.cat((byte)'}'); return str; }
public final RubyString makeIndependent() { RubyClass klass = metaClass; RubyString str = strDup(klass.getClassRuntime(), klass); str.modify(); str.setFrozen(true); str.infectBy(this); return str; }
/** match_post_match * */ @JRubyMethod public IRubyObject post_match(ThreadContext context) { check(); if (begin == -1) return context.nil; final int strLen = str.getByteList().length(); return makeShared(context.runtime, str, end, strLen - end).infectBy(this); }
/** rb_reg_match_pre * */ public static IRubyObject match_pre(IRubyObject match) { if (match.isNil()) return match; RubyMatchData m = (RubyMatchData)match; m.check(); Ruby runtime = m.getRuntime(); if (m.begin == -1) return runtime.getNil(); return m.str.makeShared(runtime, 0, m.begin).infectBy(m); }
@JRubyMethod(required = 1, meta = true) public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRubyObject arg) { Ruby runtime = context.runtime; RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, arg)); String jfilename = filename.asJavaString(); return runtime.newString(dirname(context, jfilename)).infectBy(filename); }
/** match_post_match * */ @JRubyMethod(name = "post_match") public IRubyObject post_match(ThreadContext context) { check(); if (begin == -1) { return context.runtime.getNil(); } return makeShared(context.runtime, str, end, str.getByteList().length() - end).infectBy(this); }
@JRubyMethod(name = "to_s") public IRubyObject to_s(ThreadContext context) { RubyString str = RubyString.objAsString(context, begin).strDup(context.runtime); RubyString str2 = RubyString.objAsString(context, end); str.cat(isExclusive ? DOTDOTDOT : DOTDOT); str.concat(str2); str.infectBy(str2); return str; }
@JRubyMethod(name = "chop") public IRubyObject chop(ThreadContext context) { Ruby runtime = context.runtime; if (value.getRealSize() == 0) return newEmptyString(runtime, getMetaClass(), value.getEncoding()).infectBy(this); return makeShared(runtime, 0, StringSupport.choppedLength(this)); }
@JRubyMethod(name = "chop", compat = RUBY1_9) public IRubyObject chop19(ThreadContext context) { Ruby runtime = context.runtime; if (value.getRealSize() == 0) return newEmptyString(runtime, getMetaClass(), value.getEncoding()).infectBy(this); return makeShared19(runtime, 0, choppedLength19(runtime)); }
/** rb_reg_match_post * */ public static IRubyObject match_post(IRubyObject match) { if (match.isNil()) return match; RubyMatchData m = (RubyMatchData)match; m.check(); Ruby runtime = m.getRuntime(); if (m.begin == -1) return runtime.getNil(); return m.str.makeShared(runtime, m.end, m.str.getByteList().getRealSize() - m.end).infectBy(m); }
@JRubyMethod(name = {"succ", "next"}) public IRubyObject succ(ThreadContext context) { Ruby runtime = context.runtime; final RubyString str; if (value.getRealSize() > 0) { str = new RubyString(runtime, getMetaClass(), StringSupport.succCommon(runtime, value)); // TODO: rescan code range ? } else { str = newEmptyString(runtime, getType(), value.getEncoding()); } return str.infectBy(this); }
/** rb_reg_source * */ @JRubyMethod public IRubyObject source() { check(); Encoding enc = (pattern == null) ? str.getEncoding() : pattern.getEncoding(); ByteList newStr = str.dup(); newStr.setEncoding(enc); return RubyString.newString(getRuntime(), newStr).infectBy(this); }
@JRubyMethod(name = "peek", required = 1) public IRubyObject peek(ThreadContext context, IRubyObject length) { check(); int len = RubyNumeric.num2int(length); if (len < 0) { throw context.runtime.newArgumentError("negative string size (or size too big)"); } ByteList value = str.getByteList(); if (pos >= value.getRealSize()) return RubyString.newEmptyString(context.runtime).infectBy(str); if (pos + len > value.getRealSize()) len = value.getRealSize() - pos; return extractBegLen(context.runtime, pos, len); }
@JRubyMethod(name = "peek", required = 1) public IRubyObject peek(ThreadContext context, IRubyObject length) { check(); int len = RubyNumeric.num2int(length); if (len < 0) { throw context.runtime.newArgumentError("negative string size (or size too big)"); } ByteList value = str.getByteList(); if (pos >= value.getRealSize()) return RubyString.newEmptyString(getRuntime()).infectBy(str); if (pos + len > value.getRealSize()) len = value.getRealSize() - pos; return extractBegLen(context.runtime, pos, len); }