zscan 0.4 → 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/zscan.c +17 -3
- data/lib/zscan.rb +1 -36
- data/readme.md +6 -2
- data/zscan.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 743c9b854996ff1714f83f805a8d975b261993b5
|
4
|
+
data.tar.gz: 65254b0e114cd41b727e5481da48704b28ee2bf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 028d305bcee7917a29caadbe8a4ff1254e682de582c5316ba0267d95ab0dd5fe01a47198fc5fda3aa5ba0e6c66ccd813d17fa464986c25bf528c3fc460a1e55d
|
7
|
+
data.tar.gz: eb2f9bff39078f3a835868147f3e36e388544ea6a939a053b0db3298cfef8d56945b06a78fba102b9b04345fef5ac5464e70d16f2999a25cd72f16c6489268ad
|
data/ext/zscan.c
CHANGED
@@ -104,11 +104,15 @@ static VALUE zscan_bytepos(VALUE self) {
|
|
104
104
|
|
105
105
|
static VALUE zscan_bytepos_eq(VALUE self, VALUE v_bytepos) {
|
106
106
|
P;
|
107
|
-
|
108
|
-
size_t from, to;
|
107
|
+
long signed_bytepos = NUM2LONG(v_bytepos);
|
108
|
+
size_t from, to, bytepos;
|
109
109
|
|
110
|
-
if (
|
110
|
+
if (signed_bytepos > RSTRING_LEN(p->s)) {
|
111
111
|
bytepos = RSTRING_LEN(p->s);
|
112
|
+
} else if (signed_bytepos < 0) {
|
113
|
+
bytepos = 0;
|
114
|
+
} else {
|
115
|
+
bytepos = signed_bytepos;
|
112
116
|
}
|
113
117
|
|
114
118
|
if (bytepos > p->bytepos) {
|
@@ -229,6 +233,15 @@ static VALUE zscan_drop_top(VALUE self) {
|
|
229
233
|
return self;
|
230
234
|
}
|
231
235
|
|
236
|
+
static VALUE zscan_resume_top(VALUE self) {
|
237
|
+
P;
|
238
|
+
if (p->stack_i) {
|
239
|
+
p->pos = p->stack[p->stack_i].pos;
|
240
|
+
p->bytepos = p->stack[p->stack_i].bytepos;
|
241
|
+
}
|
242
|
+
return self;
|
243
|
+
}
|
244
|
+
|
232
245
|
void Init_zscan() {
|
233
246
|
VALUE zscan = rb_define_class("ZScan", rb_cObject);
|
234
247
|
rb_define_alloc_func(zscan, zscan_alloc);
|
@@ -244,4 +257,5 @@ void Init_zscan() {
|
|
244
257
|
rb_define_method(zscan, "push_pos", zscan_push_pos, 0);
|
245
258
|
rb_define_method(zscan, "pop_pos", zscan_pop_pos, 0);
|
246
259
|
rb_define_method(zscan, "drop_top", zscan_drop_top, 0);
|
260
|
+
rb_define_method(zscan, "resume_top", zscan_resume_top, 0);
|
247
261
|
}
|
data/lib/zscan.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "../ext/zscan"
|
2
2
|
|
3
3
|
class ZScan
|
4
|
-
VERSION = '0.
|
4
|
+
VERSION = '0.5'
|
5
5
|
|
6
6
|
def initialize s, dup=false
|
7
7
|
_internal_init dup ? s.dup : s
|
@@ -35,38 +35,3 @@ class ZScan
|
|
35
35
|
|
36
36
|
private :_internal_init, :_internal_string
|
37
37
|
end
|
38
|
-
|
39
|
-
# coding: utf-8
|
40
|
-
if __FILE__ == $PROGRAM_NAME
|
41
|
-
GC.stress = true
|
42
|
-
def assert a, b
|
43
|
-
raise "expected #{a.inspect} == #{b.inspect}" if a != b
|
44
|
-
end
|
45
|
-
z = ZScan.new 'ab你好'
|
46
|
-
assert 2, z.bmatch?('ab')
|
47
|
-
z.pos = 4
|
48
|
-
assert 8, z.bytepos
|
49
|
-
z.push_pos
|
50
|
-
assert nil, z.scan(/ab你/)
|
51
|
-
z.pos = 0
|
52
|
-
assert 'ab你', z.scan(/ab你/)
|
53
|
-
assert 3, z.pos
|
54
|
-
assert 5, z.bytepos
|
55
|
-
z.pop_pos
|
56
|
-
assert 4, z.pos
|
57
|
-
assert 8, z.bytepos
|
58
|
-
z.bytepos = 2
|
59
|
-
assert '你', z.scan('你')
|
60
|
-
assert '好', z.rest
|
61
|
-
|
62
|
-
z.bytepos = 20
|
63
|
-
assert 8, z.bytepos
|
64
|
-
|
65
|
-
z.skip('ab')
|
66
|
-
assert 8, z.bytepos
|
67
|
-
assert 4, z.pos
|
68
|
-
|
69
|
-
z = ZScan.new "a x:b+ $ \\k<x>"
|
70
|
-
z.pos = 1
|
71
|
-
assert ' ', z.scan(/\s*(\#.*$\s*)*/)
|
72
|
-
end
|
data/readme.md
CHANGED
@@ -47,6 +47,10 @@ See also https://bugs.ruby-lang.org/issues/7092
|
|
47
47
|
- `bytepos`
|
48
48
|
- `bytepos= new_bytepos` note: complexity ~ `abs(new_bytepos - bytepos)`.
|
49
49
|
- `advance n` move forward `n` codepoints, if `n < 0`, move backward. Stops at beginning or end.
|
50
|
-
|
51
|
-
|
50
|
+
|
51
|
+
## Efficient pos stack manipulation
|
52
|
+
|
53
|
+
- `push_pos` pushes current pos into the stack.
|
54
|
+
- `pop_pos` sets current pos to top of the stack, and pops it.
|
52
55
|
- `drop_top` drops top of pos stack without changing current pos.
|
56
|
+
- `resume_top` sets current pos to top of the stack.
|
data/zscan.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zete Lui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: improved string scanner
|
14
14
|
email:
|