Skip to content

Commit 4f68344

Browse files
committed
Fix up results from non-zero starting position and minor code cleanup.
1 parent 15bb22a commit 4f68344

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/truffle/strscan.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def peep(len)
325325
private def scan_internal(pattern, advance_pos, getstr, headonly)
326326
scan_check_args(pattern, headonly)
327327

328-
if String === pattern
328+
if Primitive.object_kind_of?(pattern, String)
329329
md = scan_internal_string_pattern(pattern, headonly)
330330
else
331331
md = Truffle::RegexpOperations.match_in_region pattern, @string, pos, @string.bytesize, headonly, pos
@@ -340,7 +340,11 @@ def peep(len)
340340
end
341341

342342
private def scan_internal_string_pattern(pattern, headonly)
343-
@string[pos..].start_with?(pattern) ? Primitive.matchdata_create_single_group(pattern, @string.dup, pos, pos + pattern.bytesize) : nil
343+
if @string[pos..].start_with?(pattern)
344+
Primitive.matchdata_create_single_group(pattern, @string.dup, 0, pattern.bytesize)
345+
else
346+
nil
347+
end
344348
end
345349

346350
private def scan_internal_set_pos_and_str(advance_pos, getstr, md)

0 commit comments

Comments
 (0)