strscan 1.0.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/strscan/strscan.c +36 -35
  3. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 126a67b7200ba8c3f3aeb661e55a30a37b23bdd9fe68c3f8ebfc4ad9f6c2cdcb
4
- data.tar.gz: d0fafda0d3353b100c32a1437ee58258742f914a2dbb49dfde267cb15974f9f5
3
+ metadata.gz: e443bcd2ee3d9977ccea68da318cd5343d2078361dc982b4fe7ae07870724357
4
+ data.tar.gz: 56b245ed46702f4c9e70717b5b128eb82075f691da29bdb6124fac39a031065d
5
5
  SHA512:
6
- metadata.gz: ef088b41a17fd9afbee17734527fa911aea8f5b16b6f4547efb6246648f1b81ce54c6c09ebddd8c1d5b9d8c02b997d9e12f83d32214a2f25bcb5854238ad9f0d
7
- data.tar.gz: 4d93362e2c96ffd62c8ccfdbfff4d77558d1948173901176ff80f0b0c12b272bd6787a6016146756bb71b19a68a00d6add0de3cb95086cec78142873584ff6c6
6
+ metadata.gz: c227d8b94557246a238ef7134daba7f2653e1f5bbd1641c49f3f483a263d8a1818913def8e2e458af70c066fba2c8c60a88b39968105f150bb837929dcdcd413
7
+ data.tar.gz: 66025407f9af8fe655d43e0320e6d95c896527cefed2d840a383a14bf503c9ea34b78222103b8be4abe7e0c5948e488f9f9fe374663494fb170aec9578623503
@@ -4,8 +4,8 @@
4
4
  Copyright (c) 1999-2006 Minero Aoki
5
5
 
6
6
  This program is free software.
7
- You can distribute/modify this program under the terms of
8
- the Ruby License. For details, see the file COPYING.
7
+ You can redistribute this program under the terms of the Ruby's or 2-clause
8
+ BSD License. For details, see the COPYING and LICENSE.txt files.
9
9
  */
10
10
 
11
11
  #include "ruby/ruby.h"
@@ -22,7 +22,7 @@ extern size_t onig_region_memsize(const struct re_registers *regs);
22
22
 
23
23
  #include <stdbool.h>
24
24
 
25
- #define STRSCAN_VERSION "1.0.3"
25
+ #define STRSCAN_VERSION "3.0.0"
26
26
 
27
27
  /* =======================================================================
28
28
  Data Type Definitions
@@ -77,7 +77,6 @@ struct strscanner
77
77
  ======================================================================= */
78
78
 
79
79
  static inline long minl _((const long n, const long x));
80
- static VALUE infect _((VALUE str, struct strscanner *p));
81
80
  static VALUE extract_range _((struct strscanner *p, long beg_i, long end_i));
82
81
  static VALUE extract_beg_len _((struct strscanner *p, long beg_i, long len));
83
82
 
@@ -138,13 +137,6 @@ static VALUE inspect2 _((struct strscanner *p));
138
137
  Utils
139
138
  ======================================================================= */
140
139
 
141
- static VALUE
142
- infect(VALUE str, struct strscanner *p)
143
- {
144
- OBJ_INFECT(str, p->str);
145
- return str;
146
- }
147
-
148
140
  static VALUE
149
141
  str_new(struct strscanner *p, const char *ptr, long len)
150
142
  {
@@ -164,7 +156,7 @@ extract_range(struct strscanner *p, long beg_i, long end_i)
164
156
  {
165
157
  if (beg_i > S_LEN(p)) return Qnil;
166
158
  end_i = minl(end_i, S_LEN(p));
167
- return infect(str_new(p, S_PBEG(p) + beg_i, end_i - beg_i), p);
159
+ return str_new(p, S_PBEG(p) + beg_i, end_i - beg_i);
168
160
  }
169
161
 
170
162
  static VALUE
@@ -172,7 +164,7 @@ extract_beg_len(struct strscanner *p, long beg_i, long len)
172
164
  {
173
165
  if (beg_i > S_LEN(p)) return Qnil;
174
166
  len = minl(len, S_LEN(p) - beg_i);
175
- return infect(str_new(p, S_PBEG(p) + beg_i, len), p);
167
+ return str_new(p, S_PBEG(p) + beg_i, len);
176
168
  }
177
169
 
178
170
  /* =======================================================================
@@ -184,6 +176,7 @@ strscan_mark(void *ptr)
184
176
  {
185
177
  struct strscanner *p = ptr;
186
178
  rb_gc_mark(p->str);
179
+ rb_gc_mark(p->regex);
187
180
  }
188
181
 
189
182
  static void
@@ -220,6 +213,7 @@ strscan_s_allocate(VALUE klass)
220
213
  CLEAR_MATCH_STATUS(p);
221
214
  onig_region_init(&(p->regs));
222
215
  p->str = Qnil;
216
+ p->regex = Qnil;
223
217
  return obj;
224
218
  }
225
219
 
@@ -455,7 +449,7 @@ strscan_get_charpos(VALUE self)
455
449
 
456
450
  GET_SCANNER(self, p);
457
451
 
458
- substr = rb_funcall(p->str, id_byteslice, 2, INT2FIX(0), INT2NUM(p->curr));
452
+ substr = rb_funcall(p->str, id_byteslice, 2, INT2FIX(0), LONG2NUM(p->curr));
459
453
 
460
454
  return rb_str_length(substr);
461
455
  }
@@ -481,7 +475,7 @@ strscan_set_pos(VALUE self, VALUE v)
481
475
  if (i < 0) rb_raise(rb_eRangeError, "index out of range");
482
476
  if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
483
477
  p->curr = i;
484
- return INT2NUM(i);
478
+ return LONG2NUM(i);
485
479
  }
486
480
 
487
481
  static inline UChar *
@@ -499,13 +493,17 @@ match_target(struct strscanner *p)
499
493
  static inline void
500
494
  set_registers(struct strscanner *p, size_t length)
501
495
  {
502
- onig_region_clear(&(p->regs));
496
+ const int at = 0;
497
+ OnigRegion *regs = &(p->regs);
498
+ onig_region_clear(regs);
499
+ if (onig_region_set(regs, at, 0, 0)) return;
503
500
  if (p->fixed_anchor_p) {
504
- onig_region_set(&(p->regs), 0, p->curr, p->curr + length);
501
+ regs->beg[at] = p->curr;
502
+ regs->end[at] = p->curr + length;
505
503
  }
506
504
  else
507
505
  {
508
- onig_region_set(&(p->regs), 0, 0, length);
506
+ regs->end[at] = length;
509
507
  }
510
508
  }
511
509
 
@@ -852,9 +850,8 @@ adjust_registers_to_matched(struct strscanner *p)
852
850
  * s.getch # => "b"
853
851
  * s.getch # => nil
854
852
  *
855
- * $KCODE = 'EUC'
856
- * s = StringScanner.new("\244\242")
857
- * s.getch # => "\244\242" # Japanese hira-kana "A" in EUC-JP
853
+ * s = StringScanner.new("\244\242".force_encoding("euc-jp"))
854
+ * s.getch # => "\x{A4A2}" # Japanese hira-kana "A" in EUC-JP
858
855
  * s.getch # => nil
859
856
  */
860
857
  static VALUE
@@ -889,10 +886,9 @@ strscan_getch(VALUE self)
889
886
  * s.get_byte # => "b"
890
887
  * s.get_byte # => nil
891
888
  *
892
- * $KCODE = 'EUC'
893
- * s = StringScanner.new("\244\242")
894
- * s.get_byte # => "\244"
895
- * s.get_byte # => "\242"
889
+ * s = StringScanner.new("\244\242".force_encoding("euc-jp"))
890
+ * s.get_byte # => "\xA4"
891
+ * s.get_byte # => "\xA2"
896
892
  * s.get_byte # => nil
897
893
  */
898
894
  static VALUE
@@ -946,7 +942,7 @@ strscan_peek(VALUE self, VALUE vlen)
946
942
 
947
943
  len = NUM2LONG(vlen);
948
944
  if (EOS_P(p))
949
- return infect(str_new(p, "", 0), p);
945
+ return str_new(p, "", 0);
950
946
 
951
947
  len = minl(len, S_RESTLEN(p));
952
948
  return extract_beg_len(p, p->curr, len);
@@ -1095,8 +1091,9 @@ strscan_matched(VALUE self)
1095
1091
  }
1096
1092
 
1097
1093
  /*
1098
- * Returns the size of the most recent match (see #matched), or +nil+ if there
1099
- * was no recent match.
1094
+ * Returns the size of the most recent match in bytes, or +nil+ if there
1095
+ * was no recent match. This is different than <tt>matched.size</tt>,
1096
+ * which will return the size in characters.
1100
1097
  *
1101
1098
  * s = StringScanner.new('test string')
1102
1099
  * s.check /\w+/ # -> "test"
@@ -1111,7 +1108,7 @@ strscan_matched_size(VALUE self)
1111
1108
 
1112
1109
  GET_SCANNER(self, p);
1113
1110
  if (! MATCHED_P(p)) return Qnil;
1114
- return INT2NUM(p->regs.end[0] - p->regs.beg[0]);
1111
+ return LONG2NUM(p->regs.end[0] - p->regs.beg[0]);
1115
1112
  }
1116
1113
 
1117
1114
  static int
@@ -1173,7 +1170,7 @@ strscan_aref(VALUE self, VALUE idx)
1173
1170
  idx = rb_sym2str(idx);
1174
1171
  /* fall through */
1175
1172
  case T_STRING:
1176
- if (!p->regex) return Qnil;
1173
+ if (!RTEST(p->regex)) return Qnil;
1177
1174
  RSTRING_GETMEM(idx, name, i);
1178
1175
  i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx));
1179
1176
  break;
@@ -1332,7 +1329,7 @@ strscan_rest(VALUE self)
1332
1329
 
1333
1330
  GET_SCANNER(self, p);
1334
1331
  if (EOS_P(p)) {
1335
- return infect(str_new(p, "", 0), p);
1332
+ return str_new(p, "", 0);
1336
1333
  }
1337
1334
  return extract_range(p, p->curr, S_LEN(p));
1338
1335
  }
@@ -1387,11 +1384,11 @@ strscan_inspect(VALUE self)
1387
1384
  p = check_strscan(self);
1388
1385
  if (NIL_P(p->str)) {
1389
1386
  a = rb_sprintf("#<%"PRIsVALUE" (uninitialized)>", rb_obj_class(self));
1390
- return infect(a, p);
1387
+ return a;
1391
1388
  }
1392
1389
  if (EOS_P(p)) {
1393
1390
  a = rb_sprintf("#<%"PRIsVALUE" fin>", rb_obj_class(self));
1394
- return infect(a, p);
1391
+ return a;
1395
1392
  }
1396
1393
  if (p->curr == 0) {
1397
1394
  b = inspect2(p);
@@ -1399,7 +1396,7 @@ strscan_inspect(VALUE self)
1399
1396
  rb_obj_class(self),
1400
1397
  p->curr, S_LEN(p),
1401
1398
  b);
1402
- return infect(a, p);
1399
+ return a;
1403
1400
  }
1404
1401
  a = inspect1(p);
1405
1402
  b = inspect2(p);
@@ -1407,7 +1404,7 @@ strscan_inspect(VALUE self)
1407
1404
  rb_obj_class(self),
1408
1405
  p->curr, S_LEN(p),
1409
1406
  a, b);
1410
- return infect(a, p);
1407
+ return a;
1411
1408
  }
1412
1409
 
1413
1410
  static VALUE
@@ -1574,6 +1571,10 @@ strscan_fixed_anchor_p(VALUE self)
1574
1571
  void
1575
1572
  Init_strscan(void)
1576
1573
  {
1574
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
1575
+ rb_ext_ractor_safe(true);
1576
+ #endif
1577
+
1577
1578
  #undef rb_intern
1578
1579
  ID id_scanerr = rb_intern("ScanError");
1579
1580
  VALUE tmp;
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: 1.0.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-13 00:00:00.000000000 Z
12
+ date: 2020-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: test-unit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  description: Provides lexical scanning operations on a String.
43
57
  email:
44
58
  -
@@ -52,6 +66,7 @@ files:
52
66
  - ext/strscan/strscan.c
53
67
  homepage: https://github.com/ruby/strscan
54
68
  licenses:
69
+ - Ruby
55
70
  - BSD-2-Clause
56
71
  metadata: {}
57
72
  post_install_message:
@@ -69,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
84
  - !ruby/object:Gem::Version
70
85
  version: '0'
71
86
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.7.6.2
87
+ rubygems_version: 3.1.4
74
88
  signing_key:
75
89
  specification_version: 4
76
90
  summary: Provides lexical scanning operations on a String.