strscan 1.0.3 → 3.0.2.pre1
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 +47 -49
- metadata +9 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9fd5b208e7aacf23888bbe6a3f8b935b094c1baef2ab4756b9e7b41804a1b8c
|
4
|
+
data.tar.gz: 709f8ad4e2d4d8832e2d85e1be00654f621312533646df6f5234f0cb9ea414db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a08b38d5075dee6450a14904b6e0220423247609d78e84e28272e1f257235d45d4902de656db61286d98e03dcfc1231a60174cdf5eb26b5e2b6735c59dda9a6
|
7
|
+
data.tar.gz: cc2b8c1637db23c98a590f1d20f59a56ac64b3372afba40dd7aee85fa98fe47708e40238d70ca322a9e93e4d89c216f82a7c9d545c7189e177b5b0e7d0feec77
|
data/ext/strscan/strscan.c
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
Copyright (c) 1999-2006 Minero Aoki
|
5
5
|
|
6
6
|
This program is free software.
|
7
|
-
You can
|
8
|
-
|
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 "
|
25
|
+
#define STRSCAN_VERSION "3.0.2.pre1"
|
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
|
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
|
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
|
|
@@ -441,23 +435,20 @@ strscan_get_pos(VALUE self)
|
|
441
435
|
*
|
442
436
|
* In short, it's a 0-based index into the string.
|
443
437
|
*
|
444
|
-
* s = StringScanner.new("
|
445
|
-
* s.charpos
|
446
|
-
* s.scan_until(
|
447
|
-
* s.pos
|
448
|
-
* s.charpos
|
438
|
+
* s = StringScanner.new("abc\u00e4def\u00f6ghi")
|
439
|
+
* s.charpos # -> 0
|
440
|
+
* s.scan_until(/\u00e4/) # -> "abc\u00E4"
|
441
|
+
* s.pos # -> 5
|
442
|
+
* s.charpos # -> 4
|
449
443
|
*/
|
450
444
|
static VALUE
|
451
445
|
strscan_get_charpos(VALUE self)
|
452
446
|
{
|
453
447
|
struct strscanner *p;
|
454
|
-
VALUE substr;
|
455
448
|
|
456
449
|
GET_SCANNER(self, p);
|
457
450
|
|
458
|
-
|
459
|
-
|
460
|
-
return rb_str_length(substr);
|
451
|
+
return LONG2NUM(rb_enc_strlen(S_PBEG(p), CURPTR(p), rb_enc_get(p->str)));
|
461
452
|
}
|
462
453
|
|
463
454
|
/*
|
@@ -481,7 +472,7 @@ strscan_set_pos(VALUE self, VALUE v)
|
|
481
472
|
if (i < 0) rb_raise(rb_eRangeError, "index out of range");
|
482
473
|
if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
|
483
474
|
p->curr = i;
|
484
|
-
return
|
475
|
+
return LONG2NUM(i);
|
485
476
|
}
|
486
477
|
|
487
478
|
static inline UChar *
|
@@ -499,13 +490,17 @@ match_target(struct strscanner *p)
|
|
499
490
|
static inline void
|
500
491
|
set_registers(struct strscanner *p, size_t length)
|
501
492
|
{
|
502
|
-
|
493
|
+
const int at = 0;
|
494
|
+
OnigRegion *regs = &(p->regs);
|
495
|
+
onig_region_clear(regs);
|
496
|
+
if (onig_region_set(regs, at, 0, 0)) return;
|
503
497
|
if (p->fixed_anchor_p) {
|
504
|
-
|
498
|
+
regs->beg[at] = p->curr;
|
499
|
+
regs->end[at] = p->curr + length;
|
505
500
|
}
|
506
501
|
else
|
507
502
|
{
|
508
|
-
|
503
|
+
regs->end[at] = length;
|
509
504
|
}
|
510
505
|
}
|
511
506
|
|
@@ -852,9 +847,8 @@ adjust_registers_to_matched(struct strscanner *p)
|
|
852
847
|
* s.getch # => "b"
|
853
848
|
* s.getch # => nil
|
854
849
|
*
|
855
|
-
*
|
856
|
-
* s
|
857
|
-
* s.getch # => "\244\242" # Japanese hira-kana "A" in EUC-JP
|
850
|
+
* s = StringScanner.new("\244\242".force_encoding("euc-jp"))
|
851
|
+
* s.getch # => "\x{A4A2}" # Japanese hira-kana "A" in EUC-JP
|
858
852
|
* s.getch # => nil
|
859
853
|
*/
|
860
854
|
static VALUE
|
@@ -889,10 +883,9 @@ strscan_getch(VALUE self)
|
|
889
883
|
* s.get_byte # => "b"
|
890
884
|
* s.get_byte # => nil
|
891
885
|
*
|
892
|
-
*
|
893
|
-
* s
|
894
|
-
* s.get_byte # => "\
|
895
|
-
* s.get_byte # => "\242"
|
886
|
+
* s = StringScanner.new("\244\242".force_encoding("euc-jp"))
|
887
|
+
* s.get_byte # => "\xA4"
|
888
|
+
* s.get_byte # => "\xA2"
|
896
889
|
* s.get_byte # => nil
|
897
890
|
*/
|
898
891
|
static VALUE
|
@@ -946,7 +939,7 @@ strscan_peek(VALUE self, VALUE vlen)
|
|
946
939
|
|
947
940
|
len = NUM2LONG(vlen);
|
948
941
|
if (EOS_P(p))
|
949
|
-
return
|
942
|
+
return str_new(p, "", 0);
|
950
943
|
|
951
944
|
len = minl(len, S_RESTLEN(p));
|
952
945
|
return extract_beg_len(p, p->curr, len);
|
@@ -988,7 +981,7 @@ strscan_unscan(VALUE self)
|
|
988
981
|
}
|
989
982
|
|
990
983
|
/*
|
991
|
-
* Returns +true+
|
984
|
+
* Returns +true+ if and only if the scan pointer is at the beginning of the line.
|
992
985
|
*
|
993
986
|
* s = StringScanner.new("test\ntest\n")
|
994
987
|
* s.bol? # => true
|
@@ -1041,7 +1034,7 @@ strscan_empty_p(VALUE self)
|
|
1041
1034
|
}
|
1042
1035
|
|
1043
1036
|
/*
|
1044
|
-
* Returns true
|
1037
|
+
* Returns true if and only if there is more data in the string. See #eos?.
|
1045
1038
|
* This method is obsolete; use #eos? instead.
|
1046
1039
|
*
|
1047
1040
|
* s = StringScanner.new('test string')
|
@@ -1058,7 +1051,7 @@ strscan_rest_p(VALUE self)
|
|
1058
1051
|
}
|
1059
1052
|
|
1060
1053
|
/*
|
1061
|
-
* Returns +true+
|
1054
|
+
* Returns +true+ if and only if the last match was successful.
|
1062
1055
|
*
|
1063
1056
|
* s = StringScanner.new('test string')
|
1064
1057
|
* s.match?(/\w+/) # => 4
|
@@ -1095,8 +1088,9 @@ strscan_matched(VALUE self)
|
|
1095
1088
|
}
|
1096
1089
|
|
1097
1090
|
/*
|
1098
|
-
* Returns the size of the most recent match
|
1099
|
-
* was no recent match.
|
1091
|
+
* Returns the size of the most recent match in bytes, or +nil+ if there
|
1092
|
+
* was no recent match. This is different than <tt>matched.size</tt>,
|
1093
|
+
* which will return the size in characters.
|
1100
1094
|
*
|
1101
1095
|
* s = StringScanner.new('test string')
|
1102
1096
|
* s.check /\w+/ # -> "test"
|
@@ -1111,7 +1105,7 @@ strscan_matched_size(VALUE self)
|
|
1111
1105
|
|
1112
1106
|
GET_SCANNER(self, p);
|
1113
1107
|
if (! MATCHED_P(p)) return Qnil;
|
1114
|
-
return
|
1108
|
+
return LONG2NUM(p->regs.end[0] - p->regs.beg[0]);
|
1115
1109
|
}
|
1116
1110
|
|
1117
1111
|
static int
|
@@ -1173,7 +1167,7 @@ strscan_aref(VALUE self, VALUE idx)
|
|
1173
1167
|
idx = rb_sym2str(idx);
|
1174
1168
|
/* fall through */
|
1175
1169
|
case T_STRING:
|
1176
|
-
if (!p->regex) return Qnil;
|
1170
|
+
if (!RTEST(p->regex)) return Qnil;
|
1177
1171
|
RSTRING_GETMEM(idx, name, i);
|
1178
1172
|
i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx));
|
1179
1173
|
break;
|
@@ -1332,7 +1326,7 @@ strscan_rest(VALUE self)
|
|
1332
1326
|
|
1333
1327
|
GET_SCANNER(self, p);
|
1334
1328
|
if (EOS_P(p)) {
|
1335
|
-
return
|
1329
|
+
return str_new(p, "", 0);
|
1336
1330
|
}
|
1337
1331
|
return extract_range(p, p->curr, S_LEN(p));
|
1338
1332
|
}
|
@@ -1387,11 +1381,11 @@ strscan_inspect(VALUE self)
|
|
1387
1381
|
p = check_strscan(self);
|
1388
1382
|
if (NIL_P(p->str)) {
|
1389
1383
|
a = rb_sprintf("#<%"PRIsVALUE" (uninitialized)>", rb_obj_class(self));
|
1390
|
-
return
|
1384
|
+
return a;
|
1391
1385
|
}
|
1392
1386
|
if (EOS_P(p)) {
|
1393
1387
|
a = rb_sprintf("#<%"PRIsVALUE" fin>", rb_obj_class(self));
|
1394
|
-
return
|
1388
|
+
return a;
|
1395
1389
|
}
|
1396
1390
|
if (p->curr == 0) {
|
1397
1391
|
b = inspect2(p);
|
@@ -1399,7 +1393,7 @@ strscan_inspect(VALUE self)
|
|
1399
1393
|
rb_obj_class(self),
|
1400
1394
|
p->curr, S_LEN(p),
|
1401
1395
|
b);
|
1402
|
-
return
|
1396
|
+
return a;
|
1403
1397
|
}
|
1404
1398
|
a = inspect1(p);
|
1405
1399
|
b = inspect2(p);
|
@@ -1407,7 +1401,7 @@ strscan_inspect(VALUE self)
|
|
1407
1401
|
rb_obj_class(self),
|
1408
1402
|
p->curr, S_LEN(p),
|
1409
1403
|
a, b);
|
1410
|
-
return
|
1404
|
+
return a;
|
1411
1405
|
}
|
1412
1406
|
|
1413
1407
|
static VALUE
|
@@ -1540,7 +1534,7 @@ strscan_fixed_anchor_p(VALUE self)
|
|
1540
1534
|
*
|
1541
1535
|
* === Finding Where we Are
|
1542
1536
|
*
|
1543
|
-
* - #beginning_of_line? (
|
1537
|
+
* - #beginning_of_line? (<tt>#bol?</tt>)
|
1544
1538
|
* - #eos?
|
1545
1539
|
* - #rest?
|
1546
1540
|
* - #rest_size
|
@@ -1557,13 +1551,13 @@ strscan_fixed_anchor_p(VALUE self)
|
|
1557
1551
|
* - #matched
|
1558
1552
|
* - #matched?
|
1559
1553
|
* - #matched_size
|
1560
|
-
* - []
|
1554
|
+
* - <tt>#[]</tt>
|
1561
1555
|
* - #pre_match
|
1562
1556
|
* - #post_match
|
1563
1557
|
*
|
1564
1558
|
* === Miscellaneous
|
1565
1559
|
*
|
1566
|
-
* -
|
1560
|
+
* - <tt><<</tt>
|
1567
1561
|
* - #concat
|
1568
1562
|
* - #string
|
1569
1563
|
* - #string=
|
@@ -1574,6 +1568,10 @@ strscan_fixed_anchor_p(VALUE self)
|
|
1574
1568
|
void
|
1575
1569
|
Init_strscan(void)
|
1576
1570
|
{
|
1571
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1572
|
+
rb_ext_ractor_safe(true);
|
1573
|
+
#endif
|
1574
|
+
|
1577
1575
|
#undef rb_intern
|
1578
1576
|
ID id_scanerr = rb_intern("ScanError");
|
1579
1577
|
VALUE tmp;
|
metadata
CHANGED
@@ -1,48 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
8
8
|
- Sutou Kouhei
|
9
|
+
- Charles Oliver Nutter
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rake-compiler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: benchmark-driver
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
13
|
+
date: 2022-04-19 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
42
15
|
description: Provides lexical scanning operations on a String.
|
43
16
|
email:
|
44
17
|
-
|
45
18
|
- kou@cozmixng.org
|
19
|
+
- headius@headius.com
|
46
20
|
executables: []
|
47
21
|
extensions:
|
48
22
|
- ext/strscan/extconf.rb
|
@@ -52,6 +26,7 @@ files:
|
|
52
26
|
- ext/strscan/strscan.c
|
53
27
|
homepage: https://github.com/ruby/strscan
|
54
28
|
licenses:
|
29
|
+
- Ruby
|
55
30
|
- BSD-2-Clause
|
56
31
|
metadata: {}
|
57
32
|
post_install_message:
|
@@ -65,12 +40,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
40
|
version: 2.4.0
|
66
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
42
|
requirements:
|
68
|
-
- - "
|
43
|
+
- - ">"
|
69
44
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
45
|
+
version: 1.3.1
|
71
46
|
requirements: []
|
72
|
-
|
73
|
-
rubygems_version: 2.7.6.2
|
47
|
+
rubygems_version: 3.3.7
|
74
48
|
signing_key:
|
75
49
|
specification_version: 4
|
76
50
|
summary: Provides lexical scanning operations on a String.
|