private IRubyObject scanIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, Block block, int begin, int range, int tuFlags) {
Ruby runtime = context.getRuntime();
byte[]bytes = value.getUnsafeBytes();
int size = value.getRealSize();
RubyMatchData match = null;
DynamicScope scope = context.getCurrentScope();
int end = 0;
if (pattern.numberOfCaptures() == 0) {
while (matcher.search(begin + end, range, Option.NONE) >= 0) {
end = positionEnd(matcher, enc, begin, range);
match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
substr.infectBy(tuFlags);
match.infectBy(tuFlags);
block.yield(context, substr);
modifyCheck(bytes, size);
}
} else {
while (matcher.search(begin + end, range, Option.NONE) >= 0) {
end = positionEnd(matcher, enc, begin, range);
match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
match.infectBy(tuFlags);
block.yield(context, populateCapturesForScan(runtime, matcher, range, tuFlags, false));
modifyCheck(bytes, size);
}
}
scope.setBackRef(match == null ? runtime.getNil() : match);
return this;
}