frame.setBackRef(context.getRuntime().getNil());
return bang ? context.getRuntime().getNil() : strDup(context.getRuntime()); /* bang: true, no match, no substitution */
}
int blen = value.realSize + 30; /* len + margin */
ByteList dest = new ByteList(blen);
dest.realSize = blen;
int buf = 0;
int bp = 0;
int cp = begin;
int offset = 0;
RubyString val;
RubyMatchData match = null;
while (beg >= 0) {
final int begz;
final int endz;
if (iter) {
byte[] bytes = value.bytes;
int size = value.realSize;
match = rubyRegex.updateBackRef(context, this, frame, matcher);
match.use();
if (regex.numberOfCaptures() == 0) {
begz = matcher.getBegin();
endz = matcher.getEnd();
val = objAsString(context, block.yield(context, substr(context.getRuntime(), begz, endz - begz)));
} else {
Region region = matcher.getRegion();
begz = region.beg[0];
endz = region.end[0];
val = objAsString(context, block.yield(context, substr(context.getRuntime(), begz, endz - begz)));
}
modifyCheck(bytes, size);
if (bang) {
frozenCheck();
}
} else {
val = rubyRegex.regsub((RubyString) repl, this, matcher);
if (regex.numberOfCaptures() == 0) {
begz = matcher.getBegin();
endz = matcher.getEnd();
} else {
Region region = matcher.getRegion();
begz = region.beg[0];
endz = region.end[0];
}
}
if (val.isTaint()) {
tainted = true;
}
ByteList vbuf = val.value;
int len = (bp - buf) + (beg - offset) + vbuf.realSize + 3;
if (blen < len) {
while (blen < len) {
blen <<= 1;
}