Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ public IRubyObject scan_base10_integer(ThreadContext context) {
return context.nil;
}

setMatched();
prev = ptr;

while (len < remaining_len && Character.isDigit(bytes.get(ptr + len))) {
Expand Down Expand Up @@ -625,8 +624,6 @@ public IRubyObject scan_base16_integer(ThreadContext context) {
return context.nil;
}

setMatched();
adjustRegisters();
prev = ptr;

while (len < remaining_len && isHexChar(bytes.get(ptr + len))) {
Expand All @@ -639,6 +636,9 @@ public IRubyObject scan_base16_integer(ThreadContext context) {
private RubyInteger strscanParseInteger(Ruby runtime, ByteList bytes, int ptr, int len, int base) {
this.curr = ptr + len;

setMatched();
adjustRegisters();

return ConvertBytes.byteListToInum(runtime, bytes, ptr, len, base, true);
}

Expand Down
6 changes: 4 additions & 2 deletions ext/strscan/strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,10 @@ strscan_parse_integer(struct strscanner *p, int base, long len)
integer = rb_cstr2inum(buffer, base);
RB_ALLOCV_END(buffer_v);
p->curr += len;

MATCHED(p);
adjust_registers_to_matched(p);

return integer;
}

Expand Down Expand Up @@ -1341,7 +1345,6 @@ strscan_scan_base10_integer(VALUE self)
return Qnil;
}

MATCHED(p);
p->prev = p->curr;

while (len < remaining_len && rb_isdigit(ptr[len])) {
Expand Down Expand Up @@ -1383,7 +1386,6 @@ strscan_scan_base16_integer(VALUE self)
return Qnil;
}

MATCHED(p);
p->prev = p->curr;

while (len < remaining_len && rb_isxdigit(ptr[len])) {
Expand Down
12 changes: 12 additions & 0 deletions test/strscan/test_stringscanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,18 @@ def test_scan_integer_encoding
end
end

def test_scan_integer_matched
omit("not implemented on TruffleRuby") if RUBY_ENGINE == "truffleruby"

s = create_string_scanner("42abc")
assert_equal(42, s.scan_integer)
assert_equal("42", s.matched)

s = create_string_scanner("42abc")
assert_equal(0x42abc, s.scan_integer(base: 16))
assert_equal("42abc", s.matched)
end

def test_scan_integer_base_16
omit("scan_integer isn't implemented on TruffleRuby yet") if RUBY_ENGINE == "truffleruby"

Expand Down