zscan 0.1 → 0.2
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 +4 -1
- data/lib/zscan.rb +19 -4
- data/zscan.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 009307140540b30af03fa7d83fc942d4a9aa920a
|
4
|
+
data.tar.gz: 414f4fd5ee5b063da7cdb3ad5eb10d21a2b5dcbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d0f608b91d1f2269bc043b57e9969dd5f40dcc3b6ce332fbb2de1131217f1c9bc97e042c6f0f3103996e14eaa7b7b2dfa4e43e27f795ecde0f273590dd2374
|
7
|
+
data.tar.gz: a8f5a611bd5d6cec996fc5d8f956eda707f6c185204dadf918160faf4db620fec786edd8aec0e981e839483eeeaa41b6ff4cda3965e2c7db37a34b440d29be67
|
data/ext/zscan.c
CHANGED
@@ -157,7 +157,10 @@ regex_t *rb_reg_prepare_re(VALUE re, VALUE str);
|
|
157
157
|
static VALUE zscan_bmatch_p(VALUE self, VALUE pattern) {
|
158
158
|
P;
|
159
159
|
if (TYPE(pattern) == T_STRING) {
|
160
|
-
|
160
|
+
volatile VALUE ss = rb_funcall(self, rb_intern("rest"), 0);
|
161
|
+
if (RTEST(rb_funcall(ss, rb_intern("start_with?"), 1, pattern))) {
|
162
|
+
return ULONG2NUM(RSTRING_LEN(pattern));
|
163
|
+
}
|
161
164
|
} else if (TYPE(pattern) == T_REGEXP) {
|
162
165
|
regex_t *re = rb_reg_prepare_re(pattern, p->s);
|
163
166
|
int tmpreg = re != RREGEXP(pattern)->ptr;
|
data/lib/zscan.rb
CHANGED
@@ -30,7 +30,7 @@ class ZScan
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def rest
|
33
|
-
_internal_string.byteslice bytepos
|
33
|
+
_internal_string.byteslice bytepos, _internal_string.bytesize
|
34
34
|
end
|
35
35
|
|
36
36
|
private :_internal_init, :_internal_string
|
@@ -38,10 +38,25 @@ end
|
|
38
38
|
|
39
39
|
# coding: utf-8
|
40
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
|
41
45
|
z = ZScan.new 'ab你好'
|
46
|
+
assert 2, z.bmatch?('ab')
|
47
|
+
z.pos = 4
|
48
|
+
assert 8, z.bytepos
|
42
49
|
z.push_pos
|
43
|
-
z.scan
|
44
|
-
|
45
|
-
|
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
|
46
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
|
+
z = nil
|
47
62
|
end
|
data/zscan.gemspec
CHANGED