@@ -99,10 +99,12 @@ def charpos
99
99
def check ( pattern )
100
100
scan_internal pattern , false , true , true
101
101
end
102
+ Primitive . always_split self , :check
102
103
103
104
def check_until ( pattern )
104
105
scan_internal pattern , false , true , false
105
106
end
107
+ Primitive . always_split self , :check_until
106
108
107
109
def clear
108
110
warn 'StringScanner#clear is obsolete; use #terminate instead' if $VERBOSE
@@ -128,6 +130,7 @@ def eos?
128
130
def exist? ( pattern )
129
131
scan_internal pattern , false , false , false
130
132
end
133
+ Primitive . always_split self , :exist?
131
134
132
135
def fixed_anchor?
133
136
@fixed_anchor
@@ -192,6 +195,7 @@ def inspect
192
195
def match? ( pattern )
193
196
scan_internal pattern , false , false , true
194
197
end
198
+ Primitive . always_split self , :match?
195
199
196
200
def matched
197
201
@match &.to_s
@@ -247,6 +251,7 @@ def restsize
247
251
def scan ( pattern )
248
252
scan_internal pattern , true , true , true
249
253
end
254
+ Primitive . always_split self , :scan
250
255
251
256
def scan_byte
252
257
if eos?
@@ -277,21 +282,24 @@ def scan_integer(base: 10)
277
282
end
278
283
279
284
if substr
280
- Primitive . string_to_inum ( substr , base , true , true )
285
+ substr . to_i ( base )
281
286
end
282
287
end
283
288
284
289
def scan_until ( pattern )
285
290
scan_internal pattern , true , true , false
286
291
end
292
+ Primitive . always_split self , :scan_until
287
293
288
294
def scan_full ( pattern , advance_pos , getstr )
289
295
scan_internal pattern , advance_pos , getstr , true
290
296
end
297
+ Primitive . always_split self , :scan_full
291
298
292
299
def search_full ( pattern , advance_pos , getstr )
293
300
scan_internal pattern , advance_pos , getstr , false
294
301
end
302
+ Primitive . always_split self , :search_full
295
303
296
304
def self . must_C_version
297
305
self
@@ -304,10 +312,12 @@ def size
304
312
def skip ( pattern )
305
313
scan_internal pattern , true , false , true
306
314
end
315
+ Primitive . always_split self , :skip
307
316
308
317
def skip_until ( pattern )
309
318
scan_internal pattern , true , false , false
310
319
end
320
+ Primitive . always_split self , :skip_until
311
321
312
322
def string
313
323
@original
@@ -332,7 +342,7 @@ def terminate
332
342
end
333
343
334
344
def unscan
335
- raise ScanError if Primitive . nil? ( @match )
345
+ raise ScanError unless @match
336
346
@pos = @prev_pos
337
347
@prev_pos = nil
338
348
@match = nil
@@ -358,7 +368,7 @@ def peep(len)
358
368
peek len
359
369
end
360
370
361
- private def scan_check_args ( pattern , headonly )
371
+ private def scan_check_args ( pattern )
362
372
unless Primitive . is_a? ( pattern , Regexp ) || Primitive . is_a? ( pattern , String )
363
373
raise TypeError , "bad pattern argument: #{ pattern . inspect } "
364
374
end
@@ -369,15 +379,18 @@ def peep(len)
369
379
# This method is kept very small so that it should fit within 100
370
380
# AST nodes and can be split. This is done to avoid indirect calls
371
381
# to TRegex.
372
- private def scan_internal ( pattern , advance_pos , getstr , headonly )
373
- scan_check_args ( pattern , headonly )
382
+ private def scan_internal ( pattern , advance_pos , getstr , only_match_at_start )
383
+ scan_check_args ( pattern )
374
384
375
385
if Primitive . is_a? ( pattern , String )
376
- md = scan_internal_string_pattern ( pattern , headonly )
386
+ md = scan_internal_string_pattern ( pattern , only_match_at_start )
377
387
else
378
388
start = @fixed_anchor ? 0 : @pos
379
- md = Truffle ::RegexpOperations . match_in_region pattern , @string , @pos , @string . bytesize , headonly , start
380
- Primitive . matchdata_fixup_positions ( md , start ) if md
389
+ if only_match_at_start
390
+ md = Primitive . regexp_match_at_start ( pattern , @string , @pos , start )
391
+ else
392
+ md = Primitive . regexp_search_with_start ( pattern , @string , @pos , start )
393
+ end
381
394
end
382
395
383
396
if md
@@ -387,11 +400,12 @@ def peep(len)
387
400
@match = nil
388
401
end
389
402
end
403
+ Primitive . always_split self , :scan_internal
390
404
391
- private def scan_internal_string_pattern ( pattern , headonly )
405
+ private def scan_internal_string_pattern ( pattern , only_match_at_start )
392
406
pos = @pos
393
407
394
- if headonly
408
+ if only_match_at_start
395
409
if @string . byteslice ( pos ..) . start_with? ( pattern )
396
410
Primitive . matchdata_create_single_group ( pattern , @string . dup , pos , pos + pattern . bytesize )
397
411
else
0 commit comments