Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ private void adjustRegisters() {
}
}

private int adjustRegisterPosition(int position) {
if (fixedAnchor) {
return position;
} else {
return prev + position;
}
}

@JRubyMethod(name = "getch")
public IRubyObject getch(ThreadContext context) {
return getchCommon(context);
Expand Down Expand Up @@ -577,8 +585,8 @@ public IRubyObject getchCommon(ThreadContext context) {
adjustRegisters();

return extractRange(runtime,
prev + REGION_ADAPTER.getBeg(regs, 0),
prev + REGION_ADAPTER.getEnd(regs, 0));
adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, 0)),
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, 0)));
}

@JRubyMethod(name = "get_byte")
Expand All @@ -593,7 +601,9 @@ public IRubyObject get_byte(ThreadContext context) {
setMatched();
adjustRegisters();

return extractRange(context.runtime, prev + REGION_ADAPTER.getBeg(regs, 0), prev + REGION_ADAPTER.getEnd(regs, 0));
return extractRange(context.runtime,
adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, 0)),
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, 0)));
}

@JRubyMethod(name = "getbyte")
Expand Down Expand Up @@ -688,7 +698,9 @@ public RubyBoolean matched_p(ThreadContext context) {
public IRubyObject matched(ThreadContext context) {
check(context);
if (!isMatched()) return context.nil;
return extractRange(context.runtime, prev + REGION_ADAPTER.getBeg(regs, 0), prev + REGION_ADAPTER.getEnd(regs, 0));
return extractRange(context.runtime,
adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, 0)),
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, 0)));
}

@JRubyMethod(name = "matched_size")
Expand Down Expand Up @@ -734,7 +746,9 @@ private IRubyObject extractRegion(ThreadContext context, int i) {
return context.nil;
}

return extractRange(context.runtime, prev + REGION_ADAPTER.getBeg(regs, i), prev + REGION_ADAPTER.getEnd(regs, i));
return extractRange(context.runtime,
adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, i)),
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, i)));
}

@JRubyMethod(name = "pre_match")
Expand All @@ -743,7 +757,7 @@ public IRubyObject pre_match(ThreadContext context) {
if (!isMatched()) {
return context.nil;
}
return extractRange(context.runtime, 0, prev + REGION_ADAPTER.getBeg(regs, 0));
return extractRange(context.runtime, 0, adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, 0)));
}

@JRubyMethod(name = "post_match")
Expand All @@ -754,7 +768,9 @@ public IRubyObject post_match(ThreadContext context) {
return context.nil;
}

return extractRange(context.runtime, prev + REGION_ADAPTER.getEnd(regs, 0), str.getByteList().getRealSize());
return extractRange(context.runtime,
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, 0)),
str.getByteList().getRealSize());
}

@JRubyMethod(name = "rest")
Expand Down Expand Up @@ -877,7 +893,9 @@ public IRubyObject captures(ThreadContext context) {
newAry = RubyArray.newArray(runtime, numRegs);

for (i = 1; i < numRegs; i++) {
IRubyObject str = extractRange(runtime, prev + REGION_ADAPTER.getBeg(regs, i), prev + REGION_ADAPTER.getEnd(regs, i));
IRubyObject str = extractRange(runtime,
adjustRegisterPosition(REGION_ADAPTER.getBeg(regs, i)),
adjustRegisterPosition(REGION_ADAPTER.getEnd(regs, i)));
newAry.push(str);
}

Expand Down