strscan 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0451e93aa90b5c3384fd0c026e22709b673cf06f172d737c3e7b4ba347a0026
4
- data.tar.gz: 2772b7377b8c885632e0b0fe2132f9b0ae143c4dfc25a2806a59fe3ef917eb59
3
+ metadata.gz: 966671b1cf9f378e37f9294dd7274648172ca82bfed40b3507d7776d53e3f948
4
+ data.tar.gz: 91d0a754b9365f048dd3abcb8f4d3faf20b7c747fe27c0989531266f5610982f
5
5
  SHA512:
6
- metadata.gz: 119a3269f50a35ace7e62c1f8e7d817ae70fe3e40a724385a7891d355ab62b7f7cac46689b62ff7d0267db524b4621c3b15f90f5bb0f2a359b11d70d4eaaf477
7
- data.tar.gz: f9439f76c7b1b6f866afbfa7c064ce0ad0f4a5f3582ef773a7da2fab2d15c2cf36e578661e0330268a649bf1fdf03843c306ce295f0ebc3ed5cddee5f4b15aed
6
+ metadata.gz: aa2d55b49aad4e56dad583ec5c5b1fdc6ad0278c16ecfd2d730dd3ad198fd7b1ea112d625e647147cacf6dae1a670b34f4037a7552cc519f856e081975286d99
7
+ data.tar.gz: 5282025fe064fc0088721ce5d0b701f6145e483e5f1d26837a2c710a5da54f5415e669fd0081d00ea84f790362ed14453f487662f25b8e29616d51f0f6b1eb75
@@ -3,6 +3,7 @@ require 'mkmf'
3
3
  if RUBY_ENGINE == 'ruby'
4
4
  $INCFLAGS << " -I$(top_srcdir)" if $extmk
5
5
  have_func("onig_region_memsize", "ruby.h")
6
+ have_func("rb_reg_onig_match", "ruby.h")
6
7
  create_makefile 'strscan'
7
8
  else
8
9
  File.write('Makefile', dummy_makefile("").join)
@@ -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.0.6"
25
+ #define STRSCAN_VERSION "3.0.7"
26
26
 
27
27
  /* =======================================================================
28
28
  Data Type Definitions
@@ -539,6 +539,68 @@ adjust_register_position(struct strscanner *p, long position)
539
539
  }
540
540
  }
541
541
 
542
+ /* rb_reg_onig_match is available in Ruby 3.3 and later. */
543
+ #ifndef HAVE_RB_REG_ONIG_MATCH
544
+ static OnigPosition
545
+ rb_reg_onig_match(VALUE re, VALUE str,
546
+ OnigPosition (*match)(regex_t *reg, VALUE str, struct re_registers *regs, void *args),
547
+ void *args, struct re_registers *regs)
548
+ {
549
+ regex_t *reg = rb_reg_prepare_re(re, str);
550
+
551
+ bool tmpreg = reg != RREGEXP_PTR(re);
552
+ if (!tmpreg) RREGEXP(re)->usecnt++;
553
+
554
+ OnigPosition result = match(reg, str, regs, args);
555
+
556
+ if (!tmpreg) RREGEXP(re)->usecnt--;
557
+ if (tmpreg) {
558
+ if (RREGEXP(re)->usecnt) {
559
+ onig_free(reg);
560
+ }
561
+ else {
562
+ onig_free(RREGEXP_PTR(re));
563
+ RREGEXP_PTR(re) = reg;
564
+ }
565
+ }
566
+
567
+ if (result < 0) {
568
+ if (result != ONIG_MISMATCH) {
569
+ rb_raise(ScanError, "regexp buffer overflow");
570
+ }
571
+ }
572
+
573
+ return result;
574
+ }
575
+ #endif
576
+
577
+ static OnigPosition
578
+ strscan_match(regex_t *reg, VALUE str, struct re_registers *regs, void *args_ptr)
579
+ {
580
+ struct strscanner *p = (struct strscanner *)args_ptr;
581
+
582
+ return onig_match(reg,
583
+ match_target(p),
584
+ (UChar* )(CURPTR(p) + S_RESTLEN(p)),
585
+ (UChar* )CURPTR(p),
586
+ regs,
587
+ ONIG_OPTION_NONE);
588
+ }
589
+
590
+ static OnigPosition
591
+ strscan_search(regex_t *reg, VALUE str, struct re_registers *regs, void *args_ptr)
592
+ {
593
+ struct strscanner *p = (struct strscanner *)args_ptr;
594
+
595
+ return onig_search(reg,
596
+ match_target(p),
597
+ (UChar *)(CURPTR(p) + S_RESTLEN(p)),
598
+ (UChar *)CURPTR(p),
599
+ (UChar *)(CURPTR(p) + S_RESTLEN(p)),
600
+ regs,
601
+ ONIG_OPTION_NONE);
602
+ }
603
+
542
604
  static VALUE
543
605
  strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly)
544
606
  {
@@ -560,47 +622,14 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
560
622
  }
561
623
 
562
624
  if (RB_TYPE_P(pattern, T_REGEXP)) {
563
- regex_t *rb_reg_prepare_re(VALUE re, VALUE str);
564
- regex_t *re;
565
- long ret;
566
- int tmpreg;
567
-
568
625
  p->regex = pattern;
569
- re = rb_reg_prepare_re(pattern, p->str);
570
- tmpreg = re != RREGEXP_PTR(pattern);
571
- if (!tmpreg) RREGEXP(pattern)->usecnt++;
572
-
573
- if (headonly) {
574
- ret = onig_match(re,
575
- match_target(p),
576
- (UChar* )(CURPTR(p) + S_RESTLEN(p)),
577
- (UChar* )CURPTR(p),
578
- &(p->regs),
579
- ONIG_OPTION_NONE);
580
- }
581
- else {
582
- ret = onig_search(re,
583
- match_target(p),
584
- (UChar* )(CURPTR(p) + S_RESTLEN(p)),
585
- (UChar* )CURPTR(p),
586
- (UChar* )(CURPTR(p) + S_RESTLEN(p)),
587
- &(p->regs),
588
- ONIG_OPTION_NONE);
589
- }
590
- if (!tmpreg) RREGEXP(pattern)->usecnt--;
591
- if (tmpreg) {
592
- if (RREGEXP(pattern)->usecnt) {
593
- onig_free(re);
594
- }
595
- else {
596
- onig_free(RREGEXP_PTR(pattern));
597
- RREGEXP_PTR(pattern) = re;
598
- }
599
- }
626
+ OnigPosition ret = rb_reg_onig_match(pattern,
627
+ p->str,
628
+ headonly ? strscan_match : strscan_search,
629
+ (void *)p,
630
+ &(p->regs));
600
631
 
601
- if (ret == -2) rb_raise(ScanError, "regexp buffer overflow");
602
- if (ret < 0) {
603
- /* not matched */
632
+ if (ret == ONIG_MISMATCH) {
604
633
  return Qnil;
605
634
  }
606
635
  }
@@ -1502,7 +1531,9 @@ strscan_named_captures(VALUE self)
1502
1531
  named_captures_data data;
1503
1532
  data.self = self;
1504
1533
  data.captures = rb_hash_new();
1505
- onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
1534
+ if (!RB_NIL_P(p->regex)) {
1535
+ onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
1536
+ }
1506
1537
 
1507
1538
  return data.captures;
1508
1539
  }
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.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-02-08 00:00:00.000000000 Z
13
+ date: 2023-10-11 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Provides lexical scanning operations on a String.
16
16
  email: