strscan 3.1.2 → 3.1.7
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/.rdoc_options +2 -0
- data/doc/strscan/strscan.md +8 -8
- data/ext/strscan/extconf.rb +3 -2
- data/ext/strscan/strscan.c +64 -130
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd2dcf02f3109bb80e827faa389189e0418661d1ad3e2891b3427de98ff91fb2
|
|
4
|
+
data.tar.gz: cdb3b869dd71609de50939b362ab5d9817222ed01d1c6993ac9a68bab898526b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4157babafccbe1e81200a97fbc700ea17d4d6ed7f9853d2b3eae8d7ed1a8092d8178819de820c001f922f95ea31283b14e262a60041039323c1c2aa8743fb83
|
|
7
|
+
data.tar.gz: 53eb84583f0e59b3dd866b1811c8e7481bb0e505bb152fffe157aa08938779cd37e82d8153a82eb57f0f3c858235966a8ee2b5912dfa70576c9624d483816b32
|
data/.rdoc_options
CHANGED
data/doc/strscan/strscan.md
CHANGED
|
@@ -37,7 +37,7 @@ Some examples here assume that certain helper methods are defined:
|
|
|
37
37
|
- `match_values_cleared?(scanner)`:
|
|
38
38
|
Returns whether the scanner's [match values][9] are cleared.
|
|
39
39
|
|
|
40
|
-
See examples [
|
|
40
|
+
See examples at [helper methods](helper_methods.md).
|
|
41
41
|
|
|
42
42
|
## The `StringScanner` \Object
|
|
43
43
|
|
|
@@ -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 (
|
|
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
|
|
|
@@ -204,7 +204,7 @@ put_situation(scanner)
|
|
|
204
204
|
|
|
205
205
|
## Target Substring
|
|
206
206
|
|
|
207
|
-
The target substring is the
|
|
207
|
+
The target substring is the part of the [stored string][1]
|
|
208
208
|
that extends from the current [byte position][2] to the end of the stored string;
|
|
209
209
|
it is always either:
|
|
210
210
|
|
|
@@ -417,7 +417,7 @@ Each of these methods returns a captured match value:
|
|
|
417
417
|
| Method | Return After Match | Return After No Match |
|
|
418
418
|
|-----------------|-----------------------------------------|-----------------------|
|
|
419
419
|
| #size | Count of captured substrings. | +nil+. |
|
|
420
|
-
|
|
|
420
|
+
| #\[\](n) | <tt>n</tt>th captured substring. | +nil+. |
|
|
421
421
|
| #captures | Array of all captured substrings. | +nil+. |
|
|
422
422
|
| #values_at(*n) | Array of specified captured substrings. | +nil+. |
|
|
423
423
|
| #named_captures | Hash of named captures. | <tt>{}</tt>. |
|
data/ext/strscan/extconf.rb
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
require 'mkmf'
|
|
3
3
|
if RUBY_ENGINE == 'ruby'
|
|
4
4
|
$INCFLAGS << " -I$(top_srcdir)" if $extmk
|
|
5
|
-
have_func("onig_region_memsize"
|
|
6
|
-
have_func("rb_reg_onig_match", "ruby.h")
|
|
5
|
+
have_func("onig_region_memsize(NULL)")
|
|
6
|
+
have_func("rb_reg_onig_match", "ruby/re.h")
|
|
7
|
+
have_func("rb_deprecate_constant")
|
|
7
8
|
create_makefile 'strscan'
|
|
8
9
|
else
|
|
9
10
|
File.write('Makefile', dummy_makefile("").join)
|
data/ext/strscan/strscan.c
CHANGED
|
@@ -22,7 +22,15 @@ 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.
|
|
25
|
+
#define STRSCAN_VERSION "3.1.7"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#ifdef HAVE_RB_DEPRECATE_CONSTANT
|
|
29
|
+
/* In ruby 3.0, defined but exposed in external headers */
|
|
30
|
+
extern void rb_deprecate_constant(VALUE mod, const char *name);
|
|
31
|
+
#else
|
|
32
|
+
# define rb_deprecate_constant(mod, name) ((void)0)
|
|
33
|
+
#endif
|
|
26
34
|
|
|
27
35
|
/* =======================================================================
|
|
28
36
|
Data Type Definitions
|
|
@@ -30,7 +38,6 @@ extern size_t onig_region_memsize(const struct re_registers *regs);
|
|
|
30
38
|
|
|
31
39
|
static VALUE StringScanner;
|
|
32
40
|
static VALUE ScanError;
|
|
33
|
-
static ID id_byteslice;
|
|
34
41
|
|
|
35
42
|
static int usascii_encindex, utf8_encindex, binary_encindex;
|
|
36
43
|
|
|
@@ -58,8 +65,13 @@ struct strscanner
|
|
|
58
65
|
};
|
|
59
66
|
|
|
60
67
|
#define MATCHED_P(s) ((s)->flags & FLAG_MATCHED)
|
|
61
|
-
#define MATCHED(s)
|
|
62
|
-
#define
|
|
68
|
+
#define MATCHED(s) ((s)->flags |= FLAG_MATCHED)
|
|
69
|
+
#define CLEAR_MATCHED(s) ((s)->flags &= ~FLAG_MATCHED)
|
|
70
|
+
#define CLEAR_NAMED_CAPTURES(s) ((s)->regex = Qnil)
|
|
71
|
+
#define CLEAR_MATCH_STATUS(s) do {\
|
|
72
|
+
CLEAR_MATCHED(s);\
|
|
73
|
+
CLEAR_NAMED_CAPTURES(s);\
|
|
74
|
+
} while (0)
|
|
63
75
|
|
|
64
76
|
#define S_PBEG(s) (RSTRING_PTR((s)->str))
|
|
65
77
|
#define S_LEN(s) (RSTRING_LEN((s)->str))
|
|
@@ -92,7 +104,6 @@ static VALUE strscan_init_copy _((VALUE vself, VALUE vorig));
|
|
|
92
104
|
|
|
93
105
|
static VALUE strscan_s_mustc _((VALUE self));
|
|
94
106
|
static VALUE strscan_terminate _((VALUE self));
|
|
95
|
-
static VALUE strscan_clear _((VALUE self));
|
|
96
107
|
static VALUE strscan_get_string _((VALUE self));
|
|
97
108
|
static VALUE strscan_set_string _((VALUE self, VALUE str));
|
|
98
109
|
static VALUE strscan_concat _((VALUE self, VALUE str));
|
|
@@ -114,14 +125,11 @@ static VALUE strscan_search_full _((VALUE self, VALUE re,
|
|
|
114
125
|
static void adjust_registers_to_matched _((struct strscanner *p));
|
|
115
126
|
static VALUE strscan_getch _((VALUE self));
|
|
116
127
|
static VALUE strscan_get_byte _((VALUE self));
|
|
117
|
-
static VALUE strscan_getbyte _((VALUE self));
|
|
118
128
|
static VALUE strscan_peek _((VALUE self, VALUE len));
|
|
119
|
-
static VALUE strscan_peep _((VALUE self, VALUE len));
|
|
120
129
|
static VALUE strscan_scan_base10_integer _((VALUE self));
|
|
121
130
|
static VALUE strscan_unscan _((VALUE self));
|
|
122
131
|
static VALUE strscan_bol_p _((VALUE self));
|
|
123
132
|
static VALUE strscan_eos_p _((VALUE self));
|
|
124
|
-
static VALUE strscan_empty_p _((VALUE self));
|
|
125
133
|
static VALUE strscan_rest_p _((VALUE self));
|
|
126
134
|
static VALUE strscan_matched_p _((VALUE self));
|
|
127
135
|
static VALUE strscan_matched _((VALUE self));
|
|
@@ -204,7 +212,7 @@ strscan_memsize(const void *ptr)
|
|
|
204
212
|
static const rb_data_type_t strscanner_type = {
|
|
205
213
|
"StringScanner",
|
|
206
214
|
{strscan_mark, strscan_free, strscan_memsize},
|
|
207
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
215
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
|
208
216
|
};
|
|
209
217
|
|
|
210
218
|
static VALUE
|
|
@@ -216,7 +224,6 @@ strscan_s_allocate(VALUE klass)
|
|
|
216
224
|
CLEAR_MATCH_STATUS(p);
|
|
217
225
|
onig_region_init(&(p->regs));
|
|
218
226
|
p->str = Qnil;
|
|
219
|
-
p->regex = Qnil;
|
|
220
227
|
return obj;
|
|
221
228
|
}
|
|
222
229
|
|
|
@@ -269,7 +276,7 @@ strscan_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
269
276
|
p->fixed_anchor_p = false;
|
|
270
277
|
}
|
|
271
278
|
StringValue(str);
|
|
272
|
-
p->str
|
|
279
|
+
RB_OBJ_WRITE(self, &p->str, str);
|
|
273
280
|
|
|
274
281
|
return self;
|
|
275
282
|
}
|
|
@@ -299,7 +306,7 @@ strscan_init_copy(VALUE vself, VALUE vorig)
|
|
|
299
306
|
orig = check_strscan(vorig);
|
|
300
307
|
if (self != orig) {
|
|
301
308
|
self->flags = orig->flags;
|
|
302
|
-
self->str
|
|
309
|
+
RB_OBJ_WRITE(vself, &self->str, orig->str);
|
|
303
310
|
self->prev = orig->prev;
|
|
304
311
|
self->curr = orig->curr;
|
|
305
312
|
if (rb_reg_region_copy(&self->regs, &orig->regs))
|
|
@@ -381,21 +388,6 @@ strscan_terminate(VALUE self)
|
|
|
381
388
|
return self;
|
|
382
389
|
}
|
|
383
390
|
|
|
384
|
-
/*
|
|
385
|
-
* call-seq:
|
|
386
|
-
* clear -> self
|
|
387
|
-
*
|
|
388
|
-
* This method is obsolete; use the equivalent method StringScanner#terminate.
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
|
-
/* :nodoc: */
|
|
392
|
-
static VALUE
|
|
393
|
-
strscan_clear(VALUE self)
|
|
394
|
-
{
|
|
395
|
-
rb_warning("StringScanner#clear is obsolete; use #terminate instead");
|
|
396
|
-
return strscan_terminate(self);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
391
|
/*
|
|
400
392
|
* :markup: markdown
|
|
401
393
|
* :include: strscan/link_refs.txt
|
|
@@ -463,7 +455,7 @@ strscan_set_string(VALUE self, VALUE str)
|
|
|
463
455
|
struct strscanner *p = check_strscan(self);
|
|
464
456
|
|
|
465
457
|
StringValue(str);
|
|
466
|
-
p->str
|
|
458
|
+
RB_OBJ_WRITE(self, &p->str, str);
|
|
467
459
|
p->curr = 0;
|
|
468
460
|
CLEAR_MATCH_STATUS(p);
|
|
469
461
|
return str;
|
|
@@ -520,7 +512,7 @@ strscan_get_pos(VALUE self)
|
|
|
520
512
|
struct strscanner *p;
|
|
521
513
|
|
|
522
514
|
GET_SCANNER(self, p);
|
|
523
|
-
return
|
|
515
|
+
return LONG2NUM(p->curr);
|
|
524
516
|
}
|
|
525
517
|
|
|
526
518
|
/*
|
|
@@ -550,7 +542,7 @@ strscan_set_pos(VALUE self, VALUE v)
|
|
|
550
542
|
long i;
|
|
551
543
|
|
|
552
544
|
GET_SCANNER(self, p);
|
|
553
|
-
i =
|
|
545
|
+
i = NUM2LONG(v);
|
|
554
546
|
if (i < 0) i += S_LEN(p);
|
|
555
547
|
if (i < 0) rb_raise(rb_eRangeError, "index out of range");
|
|
556
548
|
if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
|
|
@@ -571,19 +563,20 @@ match_target(struct strscanner *p)
|
|
|
571
563
|
}
|
|
572
564
|
|
|
573
565
|
static inline void
|
|
574
|
-
set_registers(struct strscanner *p, size_t length)
|
|
566
|
+
set_registers(struct strscanner *p, size_t pos, size_t length)
|
|
575
567
|
{
|
|
576
568
|
const int at = 0;
|
|
577
569
|
OnigRegion *regs = &(p->regs);
|
|
578
570
|
onig_region_clear(regs);
|
|
579
571
|
if (onig_region_set(regs, at, 0, 0)) return;
|
|
580
572
|
if (p->fixed_anchor_p) {
|
|
581
|
-
regs->beg[at] = p->curr;
|
|
582
|
-
regs->end[at] = p->curr + length;
|
|
573
|
+
regs->beg[at] = pos + p->curr;
|
|
574
|
+
regs->end[at] = pos + p->curr + length;
|
|
583
575
|
}
|
|
584
576
|
else
|
|
585
577
|
{
|
|
586
|
-
regs->
|
|
578
|
+
regs->beg[at] = pos;
|
|
579
|
+
regs->end[at] = pos + length;
|
|
587
580
|
}
|
|
588
581
|
}
|
|
589
582
|
|
|
@@ -707,7 +700,7 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
|
|
|
707
700
|
|
|
708
701
|
if (RB_TYPE_P(pattern, T_REGEXP)) {
|
|
709
702
|
OnigPosition ret;
|
|
710
|
-
p->regex
|
|
703
|
+
RB_OBJ_WRITE(self, &p->regex, pattern);
|
|
711
704
|
ret = rb_reg_onig_match(p->regex,
|
|
712
705
|
p->str,
|
|
713
706
|
headonly ? strscan_match : strscan_search,
|
|
@@ -731,7 +724,7 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
|
|
|
731
724
|
if (memcmp(CURPTR(p), RSTRING_PTR(pattern), RSTRING_LEN(pattern)) != 0) {
|
|
732
725
|
return Qnil;
|
|
733
726
|
}
|
|
734
|
-
set_registers(p, RSTRING_LEN(pattern));
|
|
727
|
+
set_registers(p, 0, RSTRING_LEN(pattern));
|
|
735
728
|
}
|
|
736
729
|
else {
|
|
737
730
|
rb_encoding *enc = rb_enc_check(p->str, pattern);
|
|
@@ -740,7 +733,7 @@ strscan_do_scan(VALUE self, VALUE pattern, int succptr, int getstr, int headonly
|
|
|
740
733
|
if (pos == -1) {
|
|
741
734
|
return Qnil;
|
|
742
735
|
}
|
|
743
|
-
set_registers(p, RSTRING_LEN(pattern)
|
|
736
|
+
set_registers(p, pos, RSTRING_LEN(pattern));
|
|
744
737
|
}
|
|
745
738
|
}
|
|
746
739
|
|
|
@@ -1213,22 +1206,6 @@ strscan_get_byte(VALUE self)
|
|
|
1213
1206
|
adjust_register_position(p, p->regs.end[0]));
|
|
1214
1207
|
}
|
|
1215
1208
|
|
|
1216
|
-
/*
|
|
1217
|
-
* call-seq:
|
|
1218
|
-
* getbyte
|
|
1219
|
-
*
|
|
1220
|
-
* Equivalent to #get_byte.
|
|
1221
|
-
* This method is obsolete; use #get_byte instead.
|
|
1222
|
-
*/
|
|
1223
|
-
|
|
1224
|
-
/* :nodoc: */
|
|
1225
|
-
static VALUE
|
|
1226
|
-
strscan_getbyte(VALUE self)
|
|
1227
|
-
{
|
|
1228
|
-
rb_warning("StringScanner#getbyte is obsolete; use #get_byte instead");
|
|
1229
|
-
return strscan_get_byte(self);
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
1209
|
/*
|
|
1233
1210
|
* :markup: markdown
|
|
1234
1211
|
* :include: strscan/link_refs.txt
|
|
@@ -1264,22 +1241,6 @@ strscan_peek(VALUE self, VALUE vlen)
|
|
|
1264
1241
|
return extract_beg_len(p, p->curr, len);
|
|
1265
1242
|
}
|
|
1266
1243
|
|
|
1267
|
-
/*
|
|
1268
|
-
* call-seq:
|
|
1269
|
-
* peep
|
|
1270
|
-
*
|
|
1271
|
-
* Equivalent to #peek.
|
|
1272
|
-
* This method is obsolete; use #peek instead.
|
|
1273
|
-
*/
|
|
1274
|
-
|
|
1275
|
-
/* :nodoc: */
|
|
1276
|
-
static VALUE
|
|
1277
|
-
strscan_peep(VALUE self, VALUE vlen)
|
|
1278
|
-
{
|
|
1279
|
-
rb_warning("StringScanner#peep is obsolete; use #peek instead");
|
|
1280
|
-
return strscan_peek(self, vlen);
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
1244
|
static VALUE
|
|
1284
1245
|
strscan_parse_integer(struct strscanner *p, int base, long len)
|
|
1285
1246
|
{
|
|
@@ -1292,6 +1253,10 @@ strscan_parse_integer(struct strscanner *p, int base, long len)
|
|
|
1292
1253
|
integer = rb_cstr2inum(buffer, base);
|
|
1293
1254
|
RB_ALLOCV_END(buffer_v);
|
|
1294
1255
|
p->curr += len;
|
|
1256
|
+
|
|
1257
|
+
MATCHED(p);
|
|
1258
|
+
adjust_registers_to_matched(p);
|
|
1259
|
+
|
|
1295
1260
|
return integer;
|
|
1296
1261
|
}
|
|
1297
1262
|
|
|
@@ -1313,11 +1278,12 @@ strscan_must_ascii_compat(VALUE str)
|
|
|
1313
1278
|
rb_must_asciicompat(str);
|
|
1314
1279
|
}
|
|
1315
1280
|
|
|
1281
|
+
/* :nodoc: */
|
|
1316
1282
|
static VALUE
|
|
1317
1283
|
strscan_scan_base10_integer(VALUE self)
|
|
1318
1284
|
{
|
|
1319
1285
|
char *ptr;
|
|
1320
|
-
long len = 0;
|
|
1286
|
+
long len = 0, remaining_len;
|
|
1321
1287
|
struct strscanner *p;
|
|
1322
1288
|
|
|
1323
1289
|
GET_SCANNER(self, p);
|
|
@@ -1327,7 +1293,7 @@ strscan_scan_base10_integer(VALUE self)
|
|
|
1327
1293
|
|
|
1328
1294
|
ptr = CURPTR(p);
|
|
1329
1295
|
|
|
1330
|
-
|
|
1296
|
+
remaining_len = S_RESTLEN(p);
|
|
1331
1297
|
|
|
1332
1298
|
if (remaining_len <= 0) {
|
|
1333
1299
|
return Qnil;
|
|
@@ -1341,7 +1307,6 @@ strscan_scan_base10_integer(VALUE self)
|
|
|
1341
1307
|
return Qnil;
|
|
1342
1308
|
}
|
|
1343
1309
|
|
|
1344
|
-
MATCHED(p);
|
|
1345
1310
|
p->prev = p->curr;
|
|
1346
1311
|
|
|
1347
1312
|
while (len < remaining_len && rb_isdigit(ptr[len])) {
|
|
@@ -1351,11 +1316,12 @@ strscan_scan_base10_integer(VALUE self)
|
|
|
1351
1316
|
return strscan_parse_integer(p, 10, len);
|
|
1352
1317
|
}
|
|
1353
1318
|
|
|
1319
|
+
/* :nodoc: */
|
|
1354
1320
|
static VALUE
|
|
1355
1321
|
strscan_scan_base16_integer(VALUE self)
|
|
1356
1322
|
{
|
|
1357
1323
|
char *ptr;
|
|
1358
|
-
long len = 0;
|
|
1324
|
+
long len = 0, remaining_len;
|
|
1359
1325
|
struct strscanner *p;
|
|
1360
1326
|
|
|
1361
1327
|
GET_SCANNER(self, p);
|
|
@@ -1365,7 +1331,7 @@ strscan_scan_base16_integer(VALUE self)
|
|
|
1365
1331
|
|
|
1366
1332
|
ptr = CURPTR(p);
|
|
1367
1333
|
|
|
1368
|
-
|
|
1334
|
+
remaining_len = S_RESTLEN(p);
|
|
1369
1335
|
|
|
1370
1336
|
if (remaining_len <= 0) {
|
|
1371
1337
|
return Qnil;
|
|
@@ -1375,7 +1341,7 @@ strscan_scan_base16_integer(VALUE self)
|
|
|
1375
1341
|
len++;
|
|
1376
1342
|
}
|
|
1377
1343
|
|
|
1378
|
-
if ((remaining_len >= (len +
|
|
1344
|
+
if ((remaining_len >= (len + 3)) && ptr[len] == '0' && ptr[len + 1] == 'x' && rb_isxdigit(ptr[len + 2])) {
|
|
1379
1345
|
len += 2;
|
|
1380
1346
|
}
|
|
1381
1347
|
|
|
@@ -1383,7 +1349,6 @@ strscan_scan_base16_integer(VALUE self)
|
|
|
1383
1349
|
return Qnil;
|
|
1384
1350
|
}
|
|
1385
1351
|
|
|
1386
|
-
MATCHED(p);
|
|
1387
1352
|
p->prev = p->curr;
|
|
1388
1353
|
|
|
1389
1354
|
while (len < remaining_len && rb_isxdigit(ptr[len])) {
|
|
@@ -1517,28 +1482,11 @@ strscan_eos_p(VALUE self)
|
|
|
1517
1482
|
return EOS_P(p) ? Qtrue : Qfalse;
|
|
1518
1483
|
}
|
|
1519
1484
|
|
|
1520
|
-
/*
|
|
1521
|
-
* call-seq:
|
|
1522
|
-
* empty?
|
|
1523
|
-
*
|
|
1524
|
-
* Equivalent to #eos?.
|
|
1525
|
-
* This method is obsolete, use #eos? instead.
|
|
1526
|
-
*/
|
|
1527
|
-
|
|
1528
|
-
/* :nodoc: */
|
|
1529
|
-
static VALUE
|
|
1530
|
-
strscan_empty_p(VALUE self)
|
|
1531
|
-
{
|
|
1532
|
-
rb_warning("StringScanner#empty? is obsolete; use #eos? instead");
|
|
1533
|
-
return strscan_eos_p(self);
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
1485
|
/*
|
|
1537
1486
|
* call-seq:
|
|
1538
1487
|
* rest?
|
|
1539
1488
|
*
|
|
1540
1489
|
* Returns true if and only if there is more data in the string. See #eos?.
|
|
1541
|
-
* This method is obsolete; use #eos? instead.
|
|
1542
1490
|
*
|
|
1543
1491
|
* s = StringScanner.new('test string')
|
|
1544
1492
|
* # These two are opposites
|
|
@@ -1660,19 +1608,17 @@ strscan_matched_size(VALUE self)
|
|
|
1660
1608
|
static int
|
|
1661
1609
|
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end, rb_encoding *enc)
|
|
1662
1610
|
{
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
|
|
1672
|
-
rb_long2int(name_end - name), name);
|
|
1611
|
+
if (RTEST(regexp)) {
|
|
1612
|
+
int num = onig_name_to_backref_number(RREGEXP_PTR(regexp),
|
|
1613
|
+
(const unsigned char* )name,
|
|
1614
|
+
(const unsigned char* )name_end,
|
|
1615
|
+
regs);
|
|
1616
|
+
if (num >= 1) {
|
|
1617
|
+
return num;
|
|
1618
|
+
}
|
|
1673
1619
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1620
|
+
rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
|
|
1621
|
+
rb_long2int(name_end - name), name);
|
|
1676
1622
|
}
|
|
1677
1623
|
|
|
1678
1624
|
/*
|
|
@@ -1761,7 +1707,6 @@ strscan_aref(VALUE self, VALUE idx)
|
|
|
1761
1707
|
idx = rb_sym2str(idx);
|
|
1762
1708
|
/* fall through */
|
|
1763
1709
|
case T_STRING:
|
|
1764
|
-
if (!RTEST(p->regex)) return Qnil;
|
|
1765
1710
|
RSTRING_GETMEM(idx, name, i);
|
|
1766
1711
|
i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx));
|
|
1767
1712
|
break;
|
|
@@ -2049,22 +1994,6 @@ strscan_rest_size(VALUE self)
|
|
|
2049
1994
|
return INT2FIX(i);
|
|
2050
1995
|
}
|
|
2051
1996
|
|
|
2052
|
-
/*
|
|
2053
|
-
* call-seq:
|
|
2054
|
-
* restsize
|
|
2055
|
-
*
|
|
2056
|
-
* <tt>s.restsize</tt> is equivalent to <tt>s.rest_size</tt>.
|
|
2057
|
-
* This method is obsolete; use #rest_size instead.
|
|
2058
|
-
*/
|
|
2059
|
-
|
|
2060
|
-
/* :nodoc: */
|
|
2061
|
-
static VALUE
|
|
2062
|
-
strscan_restsize(VALUE self)
|
|
2063
|
-
{
|
|
2064
|
-
rb_warning("StringScanner#restsize is obsolete; use #rest_size instead");
|
|
2065
|
-
return strscan_rest_size(self);
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
1997
|
#define INSPECT_LENGTH 5
|
|
2069
1998
|
|
|
2070
1999
|
/*
|
|
@@ -2207,7 +2136,10 @@ named_captures_iter(const OnigUChar *name,
|
|
|
2207
2136
|
VALUE value = RUBY_Qnil;
|
|
2208
2137
|
int i;
|
|
2209
2138
|
for (i = 0; i < back_num; i++) {
|
|
2210
|
-
|
|
2139
|
+
VALUE v = strscan_aref(data->self, INT2NUM(back_refs[i]));
|
|
2140
|
+
if (!RB_NIL_P(v)) {
|
|
2141
|
+
value = v;
|
|
2142
|
+
}
|
|
2211
2143
|
}
|
|
2212
2144
|
rb_hash_aset(data->captures, key, value);
|
|
2213
2145
|
return 0;
|
|
@@ -2260,6 +2192,13 @@ strscan_named_captures(VALUE self)
|
|
|
2260
2192
|
Ruby Interface
|
|
2261
2193
|
======================================================================= */
|
|
2262
2194
|
|
|
2195
|
+
/*
|
|
2196
|
+
* Document-class: StringScanner::Error
|
|
2197
|
+
*
|
|
2198
|
+
* The error class for StringScanner.
|
|
2199
|
+
* See StringScanner#unscan.
|
|
2200
|
+
*/
|
|
2201
|
+
|
|
2263
2202
|
/*
|
|
2264
2203
|
* Document-class: StringScanner
|
|
2265
2204
|
*
|
|
@@ -2280,8 +2219,6 @@ Init_strscan(void)
|
|
|
2280
2219
|
ID id_scanerr = rb_intern("ScanError");
|
|
2281
2220
|
VALUE tmp;
|
|
2282
2221
|
|
|
2283
|
-
id_byteslice = rb_intern("byteslice");
|
|
2284
|
-
|
|
2285
2222
|
usascii_encindex = rb_usascii_encindex();
|
|
2286
2223
|
utf8_encindex = rb_utf8_encindex();
|
|
2287
2224
|
binary_encindex = rb_ascii8bit_encindex();
|
|
@@ -2290,6 +2227,7 @@ Init_strscan(void)
|
|
|
2290
2227
|
ScanError = rb_define_class_under(StringScanner, "Error", rb_eStandardError);
|
|
2291
2228
|
if (!rb_const_defined(rb_cObject, id_scanerr)) {
|
|
2292
2229
|
rb_const_set(rb_cObject, id_scanerr, ScanError);
|
|
2230
|
+
rb_deprecate_constant(rb_cObject, "ScanError");
|
|
2293
2231
|
}
|
|
2294
2232
|
tmp = rb_str_new2(STRSCAN_VERSION);
|
|
2295
2233
|
rb_obj_freeze(tmp);
|
|
@@ -2297,6 +2235,7 @@ Init_strscan(void)
|
|
|
2297
2235
|
tmp = rb_str_new2("$Id$");
|
|
2298
2236
|
rb_obj_freeze(tmp);
|
|
2299
2237
|
rb_const_set(StringScanner, rb_intern("Id"), tmp);
|
|
2238
|
+
rb_deprecate_constant(StringScanner, "Id");
|
|
2300
2239
|
|
|
2301
2240
|
rb_define_alloc_func(StringScanner, strscan_s_allocate);
|
|
2302
2241
|
rb_define_private_method(StringScanner, "initialize", strscan_initialize, -1);
|
|
@@ -2304,7 +2243,6 @@ Init_strscan(void)
|
|
|
2304
2243
|
rb_define_singleton_method(StringScanner, "must_C_version", strscan_s_mustc, 0);
|
|
2305
2244
|
rb_define_method(StringScanner, "reset", strscan_reset, 0);
|
|
2306
2245
|
rb_define_method(StringScanner, "terminate", strscan_terminate, 0);
|
|
2307
|
-
rb_define_method(StringScanner, "clear", strscan_clear, 0);
|
|
2308
2246
|
rb_define_method(StringScanner, "string", strscan_get_string, 0);
|
|
2309
2247
|
rb_define_method(StringScanner, "string=", strscan_set_string, 1);
|
|
2310
2248
|
rb_define_method(StringScanner, "concat", strscan_concat, 1);
|
|
@@ -2329,11 +2267,9 @@ Init_strscan(void)
|
|
|
2329
2267
|
|
|
2330
2268
|
rb_define_method(StringScanner, "getch", strscan_getch, 0);
|
|
2331
2269
|
rb_define_method(StringScanner, "get_byte", strscan_get_byte, 0);
|
|
2332
|
-
rb_define_method(StringScanner, "getbyte", strscan_getbyte, 0);
|
|
2333
2270
|
rb_define_method(StringScanner, "scan_byte", strscan_scan_byte, 0);
|
|
2334
2271
|
rb_define_method(StringScanner, "peek", strscan_peek, 1);
|
|
2335
2272
|
rb_define_method(StringScanner, "peek_byte", strscan_peek_byte, 0);
|
|
2336
|
-
rb_define_method(StringScanner, "peep", strscan_peep, 1);
|
|
2337
2273
|
|
|
2338
2274
|
rb_define_private_method(StringScanner, "scan_base10_integer", strscan_scan_base10_integer, 0);
|
|
2339
2275
|
rb_define_private_method(StringScanner, "scan_base16_integer", strscan_scan_base16_integer, 0);
|
|
@@ -2343,7 +2279,6 @@ Init_strscan(void)
|
|
|
2343
2279
|
rb_define_method(StringScanner, "beginning_of_line?", strscan_bol_p, 0);
|
|
2344
2280
|
rb_alias(StringScanner, rb_intern("bol?"), rb_intern("beginning_of_line?"));
|
|
2345
2281
|
rb_define_method(StringScanner, "eos?", strscan_eos_p, 0);
|
|
2346
|
-
rb_define_method(StringScanner, "empty?", strscan_empty_p, 0);
|
|
2347
2282
|
rb_define_method(StringScanner, "rest?", strscan_rest_p, 0);
|
|
2348
2283
|
|
|
2349
2284
|
rb_define_method(StringScanner, "matched?", strscan_matched_p, 0);
|
|
@@ -2358,7 +2293,6 @@ Init_strscan(void)
|
|
|
2358
2293
|
|
|
2359
2294
|
rb_define_method(StringScanner, "rest", strscan_rest, 0);
|
|
2360
2295
|
rb_define_method(StringScanner, "rest_size", strscan_rest_size, 0);
|
|
2361
|
-
rb_define_method(StringScanner, "restsize", strscan_restsize, 0);
|
|
2362
2296
|
|
|
2363
2297
|
rb_define_method(StringScanner, "inspect", strscan_inspect, 0);
|
|
2364
2298
|
|
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.
|
|
4
|
+
version: 3.1.7
|
|
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:
|
|
12
|
+
date: 1980-01-02 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:
|
|
80
|
-
signing_key:
|
|
77
|
+
rubygems_version: 4.0.3
|
|
81
78
|
specification_version: 4
|
|
82
79
|
summary: Provides lexical scanning operations on a String.
|
|
83
80
|
test_files: []
|