strscan 3.1.7-java → 3.1.8-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd9202c80c60ffa3cc2b73d493664f079ad148e9447d8d1bc7e1b40c9782001a
4
- data.tar.gz: 4b5ed5b3f0fb4768b60a6ec335af13a763dd1e44f43d370a2ce6d1108d414870
3
+ metadata.gz: c0bb452c91ad7a49f925536724d2669bddd179b75d278d80dd51eed2a1abe29b
4
+ data.tar.gz: 1ede39d02bb081f3fdb65df2ecbb03df8d4c60883ea9115bf5ebad6f4873f137
5
5
  SHA512:
6
- metadata.gz: bf5799a6a75f8ce3835af2b23eb52f88b67371a68a2dea39f8a36718ac1c50e593794feaadd3e7389ab423c6458553b46d5bd71cf4e40b501b0927ffe6176d3b
7
- data.tar.gz: 443ceb8e8ad5c44970239d170ae32e390099638be5b022419220772b17f2d528330f4e304c0f39c45637a5150f045edf050f666ff5f8dbc45366c2975def9a13
6
+ metadata.gz: 55ba0d01b7937de29ead5df47cf48bce11420958c8bd4c4a554597c929078697620fc1f74967c8e05e0a78b78424dcbc6130d9dc17797226c3c88388d0799c15
7
+ data.tar.gz: 2b40a614cd9dee1ae3266d5072a29d04f74188fd15a8bf01e219f79c064dad352f0ea479cadf39d89b0ffe672d5dc55b31704e4d62da17e2af8f4b53566e8b22
@@ -0,0 +1,423 @@
1
+ # frozen_string_literal: true
2
+ # truffleruby_primitives: true
3
+
4
+ class StringScanner
5
+ class Error < StandardError
6
+ end
7
+ # :stopdoc:
8
+ unless ::Object.const_defined?(:ScanError)
9
+ ::Object::ScanError = Error
10
+ ::Object.deprecate_constant :ScanError
11
+ end
12
+
13
+ Version = '3.1.8'
14
+ Id = '$Id$'
15
+
16
+ def self.must_C_version = self
17
+ # :startdoc:
18
+
19
+ attr_reader :string, :pos
20
+ alias_method :pointer, :pos
21
+
22
+ def initialize(string, options = nil, fixed_anchor: false)
23
+ @string = Primitive.convert_with_to_str(string)
24
+ @fixed_anchor = Primitive.as_boolean(fixed_anchor)
25
+ @pos = 0
26
+ @last_match = nil
27
+ end
28
+
29
+ def inspect
30
+ return "#<#{Primitive.class(self)} (uninitialized)>" unless @string
31
+ return "#<#{Primitive.class(self)} fin>" if eos?
32
+
33
+ before =
34
+ if @pos == 0
35
+ ''
36
+ elsif @pos < 5
37
+ "#{@string.byteslice(0, @pos).inspect} "
38
+ else
39
+ "#{('...' + @string.byteslice(@pos - 5, 5)).inspect} "
40
+ end
41
+
42
+ after =
43
+ if @pos >= @string.bytesize - 5
44
+ " #{@string.byteslice(@pos..).inspect}"
45
+ else
46
+ " #{(@string.byteslice(@pos, 5) + '...').inspect}"
47
+ end
48
+
49
+ "#<#{Primitive.class(self)} #{@pos}/#{@string.bytesize} #{before}@#{after}>"
50
+ end
51
+
52
+ def pos=(new_pos)
53
+ if new_pos < 0
54
+ new_pos += @string.bytesize
55
+ end
56
+ raise RangeError, 'index out of range' if new_pos < 0
57
+ raise RangeError, 'index out of range' if new_pos > @string.bytesize
58
+ @pos = new_pos
59
+ end
60
+ alias_method :pointer=, :pos=
61
+
62
+ def charpos = Primitive.string_byte_index_to_character_index(@string, @pos)
63
+
64
+ def rest = @string.byteslice(@pos, @string.bytesize)
65
+
66
+ def rest_size = @string.bytesize - @pos
67
+
68
+ def concat(more_string)
69
+ @string.concat(Primitive.convert_with_to_str(more_string))
70
+ self
71
+ end
72
+ alias_method :<<, :concat
73
+
74
+ def string=(other_string)
75
+ @string = Primitive.convert_with_to_str(other_string)
76
+ @pos = 0
77
+ @last_match = nil
78
+ other_string
79
+ end
80
+
81
+ def reset
82
+ @pos = 0
83
+ @last_match = nil
84
+ self
85
+ end
86
+
87
+ def terminate
88
+ @pos = @string.bytesize
89
+ @last_match = nil
90
+ self
91
+ end
92
+
93
+ def unscan
94
+ if @last_match
95
+ @pos = Primitive.match_data_byte_begin(@last_match, 0)
96
+ @last_match = nil
97
+ self
98
+ else
99
+ raise Error, 'unscan failed: previous match record not exist'
100
+ end
101
+ end
102
+
103
+ # Predicates
104
+
105
+ def fixed_anchor? = @fixed_anchor
106
+
107
+ def beginning_of_line?
108
+ @pos == 0 or @string.byteslice(@pos-1, 1) == "\n"
109
+ end
110
+ alias_method :bol?, :beginning_of_line?
111
+
112
+ def eos?
113
+ @pos >= @string.bytesize
114
+ end
115
+
116
+ def rest?
117
+ !eos?
118
+ end
119
+
120
+ # MatchData-like methods
121
+
122
+ def matched? = !Primitive.nil?(@last_match)
123
+
124
+ def matched = @last_match&.to_s
125
+
126
+ def [](group)
127
+ raise TypeError, 'no implicit conversion of Range into Integer' if Primitive.is_a?(group, Range)
128
+
129
+ if @last_match
130
+ @last_match[group]
131
+ else
132
+ nil
133
+ end
134
+ end
135
+
136
+ def values_at(*groups) = @last_match&.values_at(*groups)
137
+
138
+ def captures = @last_match&.captures
139
+
140
+ def size = @last_match&.size
141
+
142
+ def pre_match = @last_match&.pre_match
143
+
144
+ def post_match = @last_match&.post_match
145
+
146
+ def named_captures = @last_match&.named_captures || {}
147
+
148
+ def matched_size
149
+ if @last_match
150
+ Primitive.match_data_byte_end(@last_match, 0) - Primitive.match_data_byte_begin(@last_match, 0)
151
+ end
152
+ end
153
+
154
+ # Scan-like methods
155
+
156
+ def peek(length)
157
+ raise ArgumentError, 'negative string size (or size too big)' if length < 0
158
+ @string.byteslice(@pos, length)
159
+ end
160
+
161
+ def peek_byte = @string.getbyte(@pos)
162
+
163
+ def get_byte
164
+ return nil if eos?
165
+
166
+ byte = @string.byteslice(@pos, 1)
167
+ to = @pos + 1
168
+ @last_match = Primitive.matchdata_create_single_group(byte, @string, @pos, to)
169
+ @pos = to
170
+ byte
171
+ end
172
+
173
+ def scan_byte
174
+ return nil if eos?
175
+
176
+ byte_value = @string.getbyte(@pos)
177
+ get_byte
178
+ byte_value
179
+ end
180
+
181
+ def getch = scan(/./m)
182
+
183
+ def scan_integer(base: 10)
184
+ case base
185
+ when 10
186
+ scan(/[+-]?\d+/)&.to_i
187
+ when 16
188
+ scan(/[+-]?(0x)?[0-9a-fA-F]+/)&.to_i(16)
189
+ else
190
+ raise ArgumentError, "Unsupported integer base: #{base.inspect}, expected 10 or 16"
191
+ end
192
+ end
193
+
194
+ def scan_full(pattern, advance_pointer, return_string)
195
+ if advance_pointer
196
+ if return_string
197
+ scan(pattern)
198
+ else
199
+ skip(pattern)
200
+ end
201
+ else
202
+ if return_string
203
+ check(pattern)
204
+ else
205
+ match?(pattern)
206
+ end
207
+ end
208
+ end
209
+ Primitive.always_split self, :scan_full
210
+
211
+ def search_full(pattern, advance_pointer, return_string)
212
+ if advance_pointer
213
+ if return_string
214
+ scan_until(pattern)
215
+ else
216
+ skip_until(pattern)
217
+ end
218
+ else
219
+ if return_string
220
+ check_until(pattern)
221
+ else
222
+ exist?(pattern)
223
+ end
224
+ end
225
+ end
226
+ Primitive.always_split self, :search_full
227
+
228
+ # Keep the following 8 methods in sync, they are small variations of one another
229
+
230
+ # Matches at start methods
231
+
232
+ # Matches at start, returns matched string, does not advance position
233
+ def check(pattern)
234
+ prev = @pos
235
+ if Primitive.is_a?(pattern, Regexp)
236
+ start = @fixed_anchor ? 0 : prev
237
+ @last_match = Primitive.regexp_match_at_start(pattern, @string, prev, start)
238
+ if @last_match
239
+ @last_match.to_s
240
+ end
241
+ else
242
+ pattern = Primitive.convert_with_to_str(pattern)
243
+ if rest.start_with?(pattern)
244
+ to = prev + pattern.bytesize
245
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, prev, to)
246
+ pattern
247
+ else
248
+ @last_match = nil
249
+ end
250
+ end
251
+ end
252
+ Primitive.always_split self, :check
253
+
254
+ # Matches at start, returns matched string, advances position
255
+ def scan(pattern)
256
+ prev = @pos
257
+ if Primitive.is_a?(pattern, Regexp)
258
+ start = @fixed_anchor ? 0 : prev
259
+ @last_match = Primitive.regexp_match_at_start(pattern, @string, prev, start)
260
+ if @last_match
261
+ @pos = Primitive.match_data_byte_end(@last_match, 0)
262
+ @last_match.to_s
263
+ end
264
+ else
265
+ pattern = Primitive.convert_with_to_str(pattern)
266
+ if rest.start_with?(pattern)
267
+ to = prev + pattern.bytesize
268
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, prev, to)
269
+ @pos = to
270
+ pattern
271
+ else
272
+ @last_match = nil
273
+ end
274
+ end
275
+ end
276
+ Primitive.always_split self, :scan
277
+
278
+ # Matches at start, returns matched bytesize, does not advance position
279
+ def match?(pattern)
280
+ prev = @pos
281
+ if Primitive.is_a?(pattern, Regexp)
282
+ start = @fixed_anchor ? 0 : prev
283
+ @last_match = Primitive.regexp_match_at_start(pattern, @string, prev, start)
284
+ if @last_match
285
+ to = Primitive.match_data_byte_end(@last_match, 0)
286
+ to - prev
287
+ end
288
+ else
289
+ pattern = Primitive.convert_with_to_str(pattern)
290
+ if rest.start_with?(pattern)
291
+ to = prev + pattern.bytesize
292
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, prev, to)
293
+ to - prev
294
+ else
295
+ @last_match = nil
296
+ end
297
+ end
298
+ end
299
+ Primitive.always_split self, :match?
300
+
301
+ # Matches at start, returns matched bytesize, advances position
302
+ def skip(pattern)
303
+ prev = @pos
304
+ if Primitive.is_a?(pattern, Regexp)
305
+ start = @fixed_anchor ? 0 : prev
306
+ @last_match = Primitive.regexp_match_at_start(pattern, @string, prev, start)
307
+ if @last_match
308
+ to = Primitive.match_data_byte_end(@last_match, 0)
309
+ @pos = to
310
+ to - prev
311
+ end
312
+ else
313
+ pattern = Primitive.convert_with_to_str(pattern)
314
+ if rest.start_with?(pattern)
315
+ to = prev + pattern.bytesize
316
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, prev, to)
317
+ @pos = to
318
+ to - prev
319
+ else
320
+ @last_match = nil
321
+ end
322
+ end
323
+ end
324
+ Primitive.always_split self, :skip
325
+
326
+ # Matches anywhere methods
327
+
328
+ # Matches anywhere, returns matched string, does not advance position
329
+ def check_until(pattern)
330
+ prev = @pos
331
+ if Primitive.is_a?(pattern, Regexp)
332
+ start = @fixed_anchor ? 0 : prev
333
+ @last_match = Primitive.regexp_search_with_start(pattern, @string, prev, start)
334
+ if @last_match
335
+ to = Primitive.match_data_byte_end(@last_match, 0)
336
+ @string.byteslice(prev, to - prev)
337
+ end
338
+ else
339
+ pattern = Primitive.convert_with_to_str(pattern)
340
+ if from = @string.byteindex(pattern, prev)
341
+ to = from + pattern.bytesize
342
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, from, to)
343
+ @string.byteslice(prev, to - prev)
344
+ else
345
+ @last_match = nil
346
+ end
347
+ end
348
+ end
349
+ Primitive.always_split self, :check_until
350
+
351
+ # Matches anywhere, returns matched string, advances position
352
+ def scan_until(pattern)
353
+ prev = @pos
354
+ if Primitive.is_a?(pattern, Regexp)
355
+ start = @fixed_anchor ? 0 : prev
356
+ @last_match = Primitive.regexp_search_with_start(pattern, @string, prev, start)
357
+ if @last_match
358
+ to = Primitive.match_data_byte_end(@last_match, 0)
359
+ @pos = to
360
+ @string.byteslice(prev, to - prev)
361
+ end
362
+ else
363
+ pattern = Primitive.convert_with_to_str(pattern)
364
+ if from = @string.byteindex(pattern, prev)
365
+ to = from + pattern.bytesize
366
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, from, to)
367
+ @pos = to
368
+ @string.byteslice(prev, to - prev)
369
+ else
370
+ @last_match = nil
371
+ end
372
+ end
373
+ end
374
+ Primitive.always_split self, :scan_until
375
+
376
+ # Matches anywhere, returns matched bytesize, does not advance position
377
+ def exist?(pattern)
378
+ prev = @pos
379
+ if Primitive.is_a?(pattern, Regexp)
380
+ start = @fixed_anchor ? 0 : prev
381
+ @last_match = Primitive.regexp_search_with_start(pattern, @string, prev, start)
382
+ if @last_match
383
+ to = Primitive.match_data_byte_end(@last_match, 0)
384
+ to - prev
385
+ end
386
+ else
387
+ pattern = Primitive.convert_with_to_str(pattern)
388
+ if from = @string.byteindex(pattern, prev)
389
+ to = from + pattern.bytesize
390
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, from, to)
391
+ to - prev
392
+ else
393
+ @last_match = nil
394
+ end
395
+ end
396
+ end
397
+ Primitive.always_split self, :exist?
398
+
399
+ # Matches anywhere, returns matched bytesize, advances position
400
+ def skip_until(pattern)
401
+ prev = @pos
402
+ if Primitive.is_a?(pattern, Regexp)
403
+ start = @fixed_anchor ? 0 : prev
404
+ @last_match = Primitive.regexp_search_with_start(pattern, @string, prev, start)
405
+ if @last_match
406
+ to = Primitive.match_data_byte_end(@last_match, 0)
407
+ @pos = to
408
+ to - prev
409
+ end
410
+ else
411
+ pattern = Primitive.convert_with_to_str(pattern)
412
+ if from = @string.byteindex(pattern, prev)
413
+ to = from + pattern.bytesize
414
+ @last_match = Primitive.matchdata_create_single_group(pattern, @string, from, to)
415
+ @pos = to
416
+ to - prev
417
+ else
418
+ @last_match = nil
419
+ end
420
+ end
421
+ end
422
+ Primitive.always_split self, :skip_until
423
+ end
data/lib/strscan.jar CHANGED
Binary file
data/lib/strscan.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ case RUBY_ENGINE
4
+ when 'ruby'
5
+ require 'strscan.so'
6
+ require_relative 'strscan/strscan'
7
+ when 'jruby'
8
+ require 'strscan.jar'
9
+ JRuby::Util.load_ext('org.jruby.ext.strscan.StringScannerLibrary')
10
+ require_relative 'strscan/strscan'
11
+ when 'truffleruby'
12
+ if RUBY_ENGINE_VERSION.to_i >= 34
13
+ require 'strscan/truffleruby'
14
+ else
15
+ $LOAD_PATH.delete __dir__
16
+ require 'strscan'
17
+ end
18
+ else
19
+ raise NotImplementedError, "Unknown Ruby: #{RUBY_ENGINE}"
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.7
4
+ version: 3.1.8
5
5
  platform: java
6
6
  authors:
7
7
  - Minero Aoki
@@ -22,9 +22,10 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - COPYING
24
24
  - LICENSE.txt
25
- - ext/jruby/lib/strscan.rb
26
25
  - lib/strscan.jar
26
+ - lib/strscan.rb
27
27
  - lib/strscan/strscan.rb
28
+ - lib/strscan/truffleruby.rb
28
29
  homepage: https://github.com/ruby/strscan
29
30
  licenses:
30
31
  - Ruby
@@ -33,7 +34,6 @@ metadata: {}
33
34
  rdoc_options: []
34
35
  require_paths:
35
36
  - lib
36
- - ext/jruby/lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.6.9
48
+ rubygems_version: 3.7.2
49
49
  specification_version: 4
50
50
  summary: Provides lexical scanning operations on a String.
51
51
  test_files: []
@@ -1,3 +0,0 @@
1
- require 'strscan.jar'
2
- JRuby::Util.load_ext("org.jruby.ext.strscan.StringScannerLibrary")
3
- require "strscan/strscan"