strscan 3.0.4 → 3.0.5
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 +4 -4
- data/ext/strscan/strscan.c +51 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe8ee5b0a51823c49758ecd996c0fa9217d604d9c660604e5fa3effb5278ec0
|
4
|
+
data.tar.gz: f86c26d87e5d20e166510bec395ab80c0a88bd4196caad32a54d8f5dbf3454a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a285597a6003600b406da55681439a6c2f49e433f48a30a562bbdf61834ba9e3496c8fc4919a80cda38cb17801cf7d0567b0e368b01df2b09b2a529af9f51a98
|
7
|
+
data.tar.gz: c034d307b742a613ce3762fe1ef1481ea063741dfd747d1294c6f11401381a0981a8fdc967211b118ea28f737769e67626dc5772d486a174f808a66c447a4836
|
data/ext/strscan/strscan.c
CHANGED
@@ -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.
|
25
|
+
#define STRSCAN_VERSION "3.0.5"
|
26
26
|
|
27
27
|
/* =======================================================================
|
28
28
|
Data Type Definitions
|
@@ -1458,6 +1458,54 @@ strscan_fixed_anchor_p(VALUE self)
|
|
1458
1458
|
return p->fixed_anchor_p ? Qtrue : Qfalse;
|
1459
1459
|
}
|
1460
1460
|
|
1461
|
+
typedef struct {
|
1462
|
+
VALUE self;
|
1463
|
+
VALUE captures;
|
1464
|
+
} named_captures_data;
|
1465
|
+
|
1466
|
+
static int
|
1467
|
+
named_captures_iter(const OnigUChar *name,
|
1468
|
+
const OnigUChar *name_end,
|
1469
|
+
int back_num,
|
1470
|
+
int *back_refs,
|
1471
|
+
OnigRegex regex,
|
1472
|
+
void *arg)
|
1473
|
+
{
|
1474
|
+
named_captures_data *data = arg;
|
1475
|
+
|
1476
|
+
VALUE key = rb_str_new((const char *)name, name_end - name);
|
1477
|
+
VALUE value = RUBY_Qnil;
|
1478
|
+
int i;
|
1479
|
+
for (i = 0; i < back_num; i++) {
|
1480
|
+
value = strscan_aref(data->self, INT2NUM(back_refs[i]));
|
1481
|
+
}
|
1482
|
+
rb_hash_aset(data->captures, key, value);
|
1483
|
+
return 0;
|
1484
|
+
}
|
1485
|
+
|
1486
|
+
/*
|
1487
|
+
* call-seq:
|
1488
|
+
* scanner.named_captures -> hash
|
1489
|
+
*
|
1490
|
+
* Returns a hash of string variables matching the regular expression.
|
1491
|
+
*
|
1492
|
+
* scan = StringScanner.new('foobarbaz')
|
1493
|
+
* scan.match?(/(?<f>foo)(?<r>bar)(?<z>baz)/)
|
1494
|
+
* scan.named_captures # -> {"f"=>"foo", "r"=>"bar", "z"=>"baz"}
|
1495
|
+
*/
|
1496
|
+
static VALUE
|
1497
|
+
strscan_named_captures(VALUE self)
|
1498
|
+
{
|
1499
|
+
struct strscanner *p;
|
1500
|
+
GET_SCANNER(self, p);
|
1501
|
+
named_captures_data data;
|
1502
|
+
data.self = self;
|
1503
|
+
data.captures = rb_hash_new();
|
1504
|
+
onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
|
1505
|
+
|
1506
|
+
return data.captures;
|
1507
|
+
}
|
1508
|
+
|
1461
1509
|
/* =======================================================================
|
1462
1510
|
Ruby Interface
|
1463
1511
|
======================================================================= */
|
@@ -1652,4 +1700,6 @@ Init_strscan(void)
|
|
1652
1700
|
rb_define_method(StringScanner, "inspect", strscan_inspect, 0);
|
1653
1701
|
|
1654
1702
|
rb_define_method(StringScanner, "fixed_anchor?", strscan_fixed_anchor_p, 0);
|
1703
|
+
|
1704
|
+
rb_define_method(StringScanner, "named_captures", strscan_named_captures, 0);
|
1655
1705
|
}
|
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.
|
4
|
+
version: 3.0.5
|
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: 2022-
|
13
|
+
date: 2022-12-08 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Provides lexical scanning operations on a String.
|
16
16
|
email:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
rubygems_version: 3.3.
|
49
|
+
rubygems_version: 3.3.26
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: Provides lexical scanning operations on a String.
|