final byte[] spBytes = value.getUnsafeBytes();
final int sp = value.getBegin();
final int spLen = value.getRealSize();
final Matcher matcher = prepared.matcher(spBytes, sp, sp + spLen);
int beg = RubyRegexp.matcherSearch(runtime, matcher, sp, sp + spLen, Option.NONE);
if (beg < 0) {
if (useBackref) context.setBackRef(runtime.getNil());
return bang ? runtime.getNil() : strDup(runtime); /* bang: true, no match, no substitution */
}
offset = 0;
n = 0;
blen = value.getRealSize() + 30;
RubyString dest = new RubyString(runtime, getMetaClass(), new ByteList(blen));
int slen = value.getRealSize();
cp = sp;
Encoding str_enc = value.getEncoding();
dest.setEncoding(str_enc);
dest.setCodeRange(str_enc.isAsciiCompatible() ? CR_7BIT : CR_VALID);
RubyMatchData match = null;
do {
n++;
final RubyString val;
int begz = matcher.getBegin();
int endz = matcher.getEnd();
if (repl != null) { // string given
val = RubyRegexp.regsub19(context, repl, this, matcher, pattern);
} else {
final RubyString substr = makeShared19(runtime, begz, endz - begz);