strscan 3.1.2 → 3.1.3

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: 73c77caa81f5b813c59e442c9499b5a7ab4ea7b1150beb9ec2c74e77db6594df
4
- data.tar.gz: 06cc976fa2b5da016adee87d62d306c96c64da26ff32cc38c01de113e20403f6
3
+ metadata.gz: 721eeedd937d05ca382b444254fba9a33c4b5c31851e50c4dbdd577bf6500cbc
4
+ data.tar.gz: 60b383fe5478479a7888f1c11da32abbcbc98e223697b4255b9bff88f97adb55
5
5
  SHA512:
6
- metadata.gz: 68e02c4724557b03798d0c13761cc84c604278ad482c693208fc448459270faa6653069139757a9b4095c6d0fdecdff75982e8a47172e2602d1173dd6c7bf61c
7
- data.tar.gz: f6df1e074a2a6330058d3c8f4b7961a1ab0b3f077860940feadc0515e95deab8fcae3c06fccb4d3482f2127a4479b12e0c1e0482fd638decd047f770331fad47
6
+ metadata.gz: af10ae102cc3b960eec9bad084d434a436a847effbc265c03e63aeafbcfae537a45c902af4a05499f424a9a050053cc630477eca652b5a1e031548228e796ae8
7
+ data.tar.gz: 101a27af7c1f3d9eb46a2ee3e6e62b279d934d02f2e0e89d756c36699205ab66d3316e49692a19a2a872ac4c34810d9f11c58e8314d8546f4c4b69614c0db240
@@ -112,11 +112,11 @@ and a zero-based <i>character position</i>.
112
112
 
113
113
  Each of these methods explicitly sets positions:
114
114
 
115
- | Method | Effect |
116
- |--------------------------|----------------------------------------------------------|
117
- | #reset | Sets both positions to zero (begining of stored string). |
118
- | #terminate | Sets both positions to the end of the stored string. |
119
- | #pos=(new_byte_position) | Sets byte position; adjusts character position. |
115
+ | Method | Effect |
116
+ |--------------------------|-----------------------------------------------------------|
117
+ | #reset | Sets both positions to zero (beginning of stored string). |
118
+ | #terminate | Sets both positions to the end of the stored string. |
119
+ | #pos=(new_byte_position) | Sets byte position; adjusts character position. |
120
120
 
121
121
  ### Byte Position (Position)
122
122
 
@@ -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 "3.1.2"
25
+ #define STRSCAN_VERSION "3.1.3"
26
26
 
27
27
  /* =======================================================================
28
28
  Data Type Definitions
@@ -58,8 +58,13 @@ struct strscanner
58
58
  };
59
59
 
60
60
  #define MATCHED_P(s) ((s)->flags & FLAG_MATCHED)
61
- #define MATCHED(s) (s)->flags |= FLAG_MATCHED
62
- #define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED
61
+ #define MATCHED(s) ((s)->flags |= FLAG_MATCHED)
62
+ #define CLEAR_MATCHED(s) ((s)->flags &= ~FLAG_MATCHED)
63
+ #define CLEAR_NAMED_CAPTURES(s) ((s)->regex = Qnil)
64
+ #define CLEAR_MATCH_STATUS(s) do {\
65
+ CLEAR_MATCHED(s);\
66
+ CLEAR_NAMED_CAPTURES(s);\
67
+ } while (0)
63
68
 
64
69
  #define S_PBEG(s) (RSTRING_PTR((s)->str))
65
70
  #define S_LEN(s) (RSTRING_LEN((s)->str))
@@ -216,7 +221,6 @@ strscan_s_allocate(VALUE klass)
216
221
  CLEAR_MATCH_STATUS(p);
217
222
  onig_region_init(&(p->regs));
218
223
  p->str = Qnil;
219
- p->regex = Qnil;
220
224
  return obj;
221
225
  }
222
226
 
@@ -520,7 +524,7 @@ strscan_get_pos(VALUE self)
520
524
  struct strscanner *p;
521
525
 
522
526
  GET_SCANNER(self, p);
523
- return INT2FIX(p->curr);
527
+ return LONG2NUM(p->curr);
524
528
  }
525
529
 
526
530
  /*
@@ -550,7 +554,7 @@ strscan_set_pos(VALUE self, VALUE v)
550
554
  long i;
551
555
 
552
556
  GET_SCANNER(self, p);
553
- i = NUM2INT(v);
557
+ i = NUM2LONG(v);
554
558
  if (i < 0) i += S_LEN(p);
555
559
  if (i < 0) rb_raise(rb_eRangeError, "index out of range");
556
560
  if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
@@ -571,19 +575,20 @@ match_target(struct strscanner *p)
571
575
  }
572
576
 
573
577
  static inline void
574
- set_registers(struct strscanner *p, size_t length)
578
+ set_registers(struct strscanner *p, size_t pos, size_t length)
575
579
  {
576
580
  const int at = 0;
577
581
  OnigRegion *regs = &(p->regs);
578
582
  onig_region_clear(regs);
579
583
  if (onig_region_set(regs, at, 0, 0)) return;
580
584
  if (p->fixed_anchor_p) {
581
- regs->beg[at] = p->curr;
582
- regs->end[at] = p->curr + length;
585
+ regs->beg[at] = pos + p->curr;
586
+ regs->end[at] = pos + p->curr + length;
583
587
  }
584
588
  else
585
589
  {
586
- regs->end[at] = length;
590
+ regs->beg[at] = pos;
591
+ regs->end[at] = pos + length;
587
592
  }
588
593
  }
589
594
 
@@ -731,7 +736,7 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
731
736
  if (memcmp(CURPTR(p), RSTRING_PTR(pattern), RSTRING_LEN(pattern)) != 0) {
732
737
  return Qnil;
733
738
  }
734
- set_registers(p, RSTRING_LEN(pattern));
739
+ set_registers(p, 0, RSTRING_LEN(pattern));
735
740
  }
736
741
  else {
737
742
  rb_encoding *enc = rb_enc_check(p->str, pattern);
@@ -740,7 +745,7 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
740
745
  if (pos == -1) {
741
746
  return Qnil;
742
747
  }
743
- set_registers(p, RSTRING_LEN(pattern) + pos);
748
+ set_registers(p, pos, RSTRING_LEN(pattern));
744
749
  }
745
750
  }
746
751
 
@@ -1292,6 +1297,10 @@ strscan_parse_integer(struct strscanner *p, int base, long len)
1292
1297
  integer = rb_cstr2inum(buffer, base);
1293
1298
  RB_ALLOCV_END(buffer_v);
1294
1299
  p->curr += len;
1300
+
1301
+ MATCHED(p);
1302
+ adjust_registers_to_matched(p);
1303
+
1295
1304
  return integer;
1296
1305
  }
1297
1306
 
@@ -1341,7 +1350,6 @@ strscan_scan_base10_integer(VALUE self)
1341
1350
  return Qnil;
1342
1351
  }
1343
1352
 
1344
- MATCHED(p);
1345
1353
  p->prev = p->curr;
1346
1354
 
1347
1355
  while (len < remaining_len && rb_isdigit(ptr[len])) {
@@ -1375,7 +1383,7 @@ strscan_scan_base16_integer(VALUE self)
1375
1383
  len++;
1376
1384
  }
1377
1385
 
1378
- if ((remaining_len >= (len + 2)) && ptr[len] == '0' && ptr[len + 1] == 'x') {
1386
+ if ((remaining_len >= (len + 3)) && ptr[len] == '0' && ptr[len + 1] == 'x' && rb_isxdigit(ptr[len + 2])) {
1379
1387
  len += 2;
1380
1388
  }
1381
1389
 
@@ -1383,7 +1391,6 @@ strscan_scan_base16_integer(VALUE self)
1383
1391
  return Qnil;
1384
1392
  }
1385
1393
 
1386
- MATCHED(p);
1387
1394
  p->prev = p->curr;
1388
1395
 
1389
1396
  while (len < remaining_len && rb_isxdigit(ptr[len])) {
@@ -1660,19 +1667,17 @@ strscan_matched_size(VALUE self)
1660
1667
  static int
1661
1668
  name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end, rb_encoding *enc)
1662
1669
  {
1663
- int num;
1664
-
1665
- num = onig_name_to_backref_number(RREGEXP_PTR(regexp),
1666
- (const unsigned char* )name, (const unsigned char* )name_end, regs);
1667
- if (num >= 1) {
1668
- return num;
1669
- }
1670
- else {
1671
- rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
1672
- rb_long2int(name_end - name), name);
1670
+ if (RTEST(regexp)) {
1671
+ int num = onig_name_to_backref_number(RREGEXP_PTR(regexp),
1672
+ (const unsigned char* )name,
1673
+ (const unsigned char* )name_end,
1674
+ regs);
1675
+ if (num >= 1) {
1676
+ return num;
1677
+ }
1673
1678
  }
1674
-
1675
- UNREACHABLE;
1679
+ rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
1680
+ rb_long2int(name_end - name), name);
1676
1681
  }
1677
1682
 
1678
1683
  /*
@@ -1761,7 +1766,6 @@ strscan_aref(VALUE self, VALUE idx)
1761
1766
  idx = rb_sym2str(idx);
1762
1767
  /* fall through */
1763
1768
  case T_STRING:
1764
- if (!RTEST(p->regex)) return Qnil;
1765
1769
  RSTRING_GETMEM(idx, name, i);
1766
1770
  i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx));
1767
1771
  break;
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  - Sutou Kouhei
9
9
  - Charles Oliver Nutter
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-12-15 00:00:00.000000000 Z
12
+ date: 2025-04-13 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Provides lexical scanning operations on a String.
16
15
  email:
@@ -60,7 +59,6 @@ licenses:
60
59
  - Ruby
61
60
  - BSD-2-Clause
62
61
  metadata: {}
63
- post_install_message:
64
62
  rdoc_options:
65
63
  - "-idoc"
66
64
  require_paths:
@@ -76,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
74
  - !ruby/object:Gem::Version
77
75
  version: '0'
78
76
  requirements: []
79
- rubygems_version: 3.5.22
80
- signing_key:
77
+ rubygems_version: 3.6.2
81
78
  specification_version: 4
82
79
  summary: Provides lexical scanning operations on a String.
83
80
  test_files: []