sequence 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -0
- data/History.txt +10 -0
- data/Makefile +1 -0
- data/README.txt +17 -13
- data/lib/assert.rb +1 -1
- data/lib/sequence.rb +591 -591
- data/lib/sequence/arraylike.rb +1 -1
- data/lib/sequence/buffered.rb +1 -1
- data/lib/sequence/circular.rb +48 -48
- data/lib/sequence/enum.rb +1 -1
- data/lib/sequence/file.rb +1 -8
- data/lib/sequence/functional.rb +2 -2
- data/lib/sequence/generator.rb +1 -0
- data/lib/sequence/indexed.rb +1 -1
- data/lib/sequence/io.rb +1 -1
- data/lib/sequence/list.rb +23 -10
- data/lib/sequence/ofhash.rb +1 -1
- data/lib/sequence/ofobjectivars.rb +1 -1
- data/lib/sequence/ofobjectmethods.rb +1 -1
- data/lib/sequence/position.rb +2 -2
- data/lib/sequence/reversed.rb +1 -1
- data/lib/sequence/shifting.rb +1 -1
- data/lib/sequence/singleitem.rb +1 -1
- data/lib/sequence/stringio.rb +9 -0
- data/lib/sequence/stringlike.rb +4 -2
- data/lib/sequence/subseq.rb +1 -1
- data/lib/sequence/usedata.rb +3 -3
- data/lib/sequence/version.rb +2 -2
- data/lib/sequence/weakrefset.rb +2 -2
- data/sequence.gemspec +5 -4
- data/test/test_all.rb +1 -1
- data/test/test_changes.rb +1 -1
- data/test/test_rexscan.rb +14 -17
- data/test/test_seqrex.rb +23 -16
- metadata +34 -31
data/lib/sequence/arraylike.rb
CHANGED
data/lib/sequence/buffered.rb
CHANGED
data/lib/sequence/circular.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
# $Id$
|
2
|
-
# Copyright (C) 2006 Caleb Clausen
|
2
|
+
# Copyright (C) 2006, 2011 Caleb Clausen
|
3
3
|
# Distributed under the terms of Ruby's license.
|
4
4
|
|
5
5
|
require 'sequence'
|
6
6
|
|
7
7
|
class Sequence
|
8
|
-
# This Sequence class is used to represent a circular buffer. You can think of
|
9
|
-
# this as having no beginning/end or the current location is always both at the
|
10
|
-
# beginning/end. Because of the circular nature, the methods
|
11
|
-
# #scan_until, #modify,
|
12
|
-
# #each, #collect!, and #map!
|
13
|
-
# are not defined.
|
14
|
-
class Circular < Sequence
|
8
|
+
# This Sequence class is used to represent a circular buffer. You can think of
|
9
|
+
# this as having no beginning/end or the current location is always both at the
|
10
|
+
# beginning/end. Because of the circular nature, the methods
|
11
|
+
# #scan_until, #modify,
|
12
|
+
# #each, #collect!, and #map!
|
13
|
+
# are not defined.
|
14
|
+
class Circular < Sequence
|
15
15
|
# Create a circular sequence from a normal finite one.
|
16
16
|
def initialize(sequence,pos=sequence.pos)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
#the default _parse_slice_args isn't forgiving enough about large
|
17
|
+
@seq = sequence
|
18
|
+
@pos=pos
|
19
|
+
@size=sequence.size
|
20
|
+
extend sequence.like
|
21
|
+
|
22
|
+
@seq.on_change_notify self
|
23
|
+
end
|
24
|
+
|
25
|
+
#the default _parse_slice_args isn't forgiving enough about large
|
26
26
|
#(positive or negative) indexes
|
27
27
|
def _normalize_pos pos, size=nil
|
28
28
|
pos
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def change_notification(cu,first,oldsize,newsize)
|
32
32
|
assert(cu.equal?( @seq ))
|
33
33
|
@pos =_adjust_pos_on_change(@pos, first,oldsize,newsize)
|
34
34
|
@size+=newsize-oldsize
|
35
35
|
assert @size==@seq.size
|
36
|
-
notify_change(self,first,oldsize,newsize)
|
36
|
+
notify_change(self,first,oldsize,newsize)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
=begin
|
40
40
|
def _adjust_delete(len=1,reverse=false)
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
pos = _pos(false)
|
42
|
+
ret = nil
|
43
|
+
@positions.each { |p| ret = p.__send__(:_deletion,pos,len,reverse,ret) }
|
44
44
|
end
|
45
45
|
def _adjust_insert(len=1)
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
pos = _pos(false)
|
47
|
+
ret = nil
|
48
|
+
@positions.each { |p| ret = p.__send__(:_insertion,pos,len,ret) }
|
49
49
|
end
|
50
50
|
=end
|
51
51
|
attr_reader :pos,:size
|
@@ -59,7 +59,7 @@ class Circular < Sequence
|
|
59
59
|
def new_data
|
60
60
|
@seq.new_data
|
61
61
|
end
|
62
|
-
=begin **
|
62
|
+
=begin **
|
63
63
|
def read1next
|
64
64
|
v0 = @seq.read1next
|
65
65
|
v0.nil? && @seq.move!(true) && (v0 = @seq.read1next)
|
@@ -186,21 +186,21 @@ class Circular < Sequence
|
|
186
186
|
end
|
187
187
|
alias end! begin!
|
188
188
|
alias end begin
|
189
|
-
# Compare to +other+.
|
189
|
+
# Compare to +other+.
|
190
190
|
def <=>(other)
|
191
|
-
|
191
|
+
position?(other) and pos<=>other.pos
|
192
192
|
end
|
193
193
|
|
194
194
|
=begin ***
|
195
195
|
# insert an element before the position and return self
|
196
196
|
def << (value)
|
197
|
-
|
198
|
-
|
197
|
+
insert1before(value)
|
198
|
+
self
|
199
199
|
end
|
200
200
|
# insert an element after the position and return self
|
201
201
|
def >> (value)
|
202
|
-
|
203
|
-
|
202
|
+
insert1after(value)
|
203
|
+
self
|
204
204
|
end
|
205
205
|
=end
|
206
206
|
# :stopdoc:
|
@@ -208,27 +208,27 @@ class Circular < Sequence
|
|
208
208
|
def data
|
209
209
|
@seq
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
def each
|
213
213
|
po=position
|
214
214
|
yield read1 until self==position
|
215
215
|
po.close
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
def eof?; false end
|
219
|
-
|
219
|
+
|
220
220
|
def readahead(len)
|
221
221
|
result=@seq[@pos%size,len]
|
222
222
|
len-=result.size
|
223
223
|
len.zero? and return result
|
224
224
|
loops=len/size
|
225
|
-
|
225
|
+
|
226
226
|
result+=@seq[0...size]*loops if loops.nonzero?
|
227
|
-
|
227
|
+
|
228
228
|
len%=size
|
229
|
-
|
229
|
+
|
230
230
|
len.zero? and return result
|
231
|
-
|
231
|
+
|
232
232
|
result+=@seq[0,len]
|
233
233
|
end
|
234
234
|
|
@@ -237,35 +237,35 @@ class Circular < Sequence
|
|
237
237
|
move len
|
238
238
|
result
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
def modify(*args)
|
242
242
|
data=args.last
|
243
243
|
first,len,only1=_parse_slice_args(*args[0...-1])
|
244
244
|
first %= size
|
245
|
-
|
245
|
+
|
246
246
|
len>size and raise( ArgumentError, "dst len too long")
|
247
247
|
first+len>size and raise( ArgumentError, "wraparound modify in circular")
|
248
248
|
|
249
249
|
@seq.modify(*args)
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
#when reversed and circular, always put the Circular outermost.
|
253
253
|
def reverse
|
254
254
|
Circular.new @seq.reverse
|
255
255
|
end
|
256
|
-
|
257
|
-
def nearbegin(len,at=pos)
|
256
|
+
|
257
|
+
def nearbegin(len,at=pos)
|
258
258
|
false
|
259
259
|
end
|
260
|
-
|
260
|
+
|
261
261
|
def nearend(len,at=pos)
|
262
262
|
false
|
263
263
|
end
|
264
|
-
|
264
|
+
|
265
265
|
def closed?
|
266
266
|
super or @seq.closed?
|
267
267
|
end
|
268
|
-
end
|
268
|
+
end
|
269
269
|
end
|
270
270
|
|
271
271
|
|
data/lib/sequence/enum.rb
CHANGED
data/lib/sequence/file.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2006 Caleb Clausen
|
1
|
+
# Copyright (C) 2006, 2011 Caleb Clausen
|
2
2
|
# Distributed under the terms of Ruby's license.
|
3
3
|
# $Id$
|
4
4
|
|
@@ -163,10 +163,3 @@ class File
|
|
163
163
|
Sequence::File.new(self)
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
167
|
-
class StringIO
|
168
|
-
# convert an StringIO to a seq
|
169
|
-
def to_sequence
|
170
|
-
Sequence::File.new(self)
|
171
|
-
end
|
172
|
-
end
|
data/lib/sequence/functional.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2006 Caleb Clausen
|
1
|
+
# Copyright (C) 2006, 2011 Caleb Clausen
|
2
2
|
# Distributed under the terms of Ruby's license.
|
3
3
|
|
4
4
|
class Sequence
|
@@ -149,4 +149,4 @@ end
|
|
149
149
|
class Proc
|
150
150
|
has_side_effect *%w[[] call]
|
151
151
|
no_side_effect "arity"
|
152
|
-
end
|
152
|
+
end
|
data/lib/sequence/generator.rb
CHANGED
data/lib/sequence/indexed.rb
CHANGED
data/lib/sequence/io.rb
CHANGED
data/lib/sequence/list.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
# Copyright (C) 2006,2008 Caleb Clausen
|
1
|
+
# Copyright (C) 2006,2008, 2011 Caleb Clausen
|
2
2
|
# Distributed under the terms of Ruby's license.
|
3
3
|
class Sequence
|
4
4
|
class Circular < Sequence; end
|
5
5
|
class List < Sequence
|
6
6
|
def initialize(seqs)
|
7
|
-
seqs.empty? and raise ArgumentError
|
7
|
+
seqs.empty? and raise( ArgumentError, 'empty List not allowed' )
|
8
8
|
@list=seqs
|
9
9
|
@current_idx=0
|
10
10
|
@pos=0
|
11
11
|
@start_pos=[0]
|
12
12
|
|
13
13
|
@list=@list.inject([]){|li,seq|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
seq=seq.to_sequence
|
15
|
+
case seq
|
16
|
+
when Circular; raise ArgumentError, 'no circular seqs in lists'
|
17
|
+
when List; li+seq.list
|
18
|
+
else li<<seq
|
19
|
+
end
|
17
20
|
}
|
18
21
|
@list.each{|seq| seq.on_change_notify(self) }
|
19
22
|
_rebuild_idxs
|
20
23
|
|
21
|
-
extend
|
24
|
+
extend @list.first.like
|
22
25
|
end
|
23
26
|
|
24
27
|
attr :list
|
@@ -170,7 +173,13 @@ class Sequence
|
|
170
173
|
return idx
|
171
174
|
end
|
172
175
|
|
173
|
-
|
176
|
+
module Overlaid
|
177
|
+
def overlaid?; true end
|
178
|
+
def subseq(*)
|
179
|
+
super.extend Overlaid
|
180
|
+
end
|
181
|
+
end
|
182
|
+
=begin was
|
174
183
|
Overlaid =proc do
|
175
184
|
class<<self
|
176
185
|
def overlaid?; true end
|
@@ -181,6 +190,7 @@ class Sequence
|
|
181
190
|
end
|
182
191
|
end
|
183
192
|
end
|
193
|
+
=end
|
184
194
|
|
185
195
|
def modify(*args)
|
186
196
|
result=repldata=args.pop
|
@@ -192,7 +202,8 @@ class Sequence
|
|
192
202
|
|
193
203
|
|
194
204
|
#mark replacement data as overlaid
|
195
|
-
repldata.instance_eval(&Overlaid)
|
205
|
+
#repldata.instance_eval(&Overlaid)
|
206
|
+
repldata.extend Overlaid
|
196
207
|
# end
|
197
208
|
replseqs=[repldata]
|
198
209
|
|
@@ -266,7 +277,8 @@ class Sequence
|
|
266
277
|
return self
|
267
278
|
end
|
268
279
|
data=data.dup.to_sequence
|
269
|
-
data.instance_eval(&Overlaid)
|
280
|
+
#data.instance_eval(&Overlaid)
|
281
|
+
data.extend Overlaid
|
270
282
|
@list<<data
|
271
283
|
@start_pos<<@start_pos.last+data.size
|
272
284
|
notify_change(self,@start_pos[-2], 0, data.size)
|
@@ -278,7 +290,8 @@ class Sequence
|
|
278
290
|
return self
|
279
291
|
end
|
280
292
|
data=data.dup.to_sequence
|
281
|
-
data.instance_eval(&Overlaid)
|
293
|
+
#data.instance_eval(&Overlaid)
|
294
|
+
data.extend Overlaid
|
282
295
|
@list[0,0]=data
|
283
296
|
|
284
297
|
#insert data.size into beginning of @start_pos
|
data/lib/sequence/ofhash.rb
CHANGED
data/lib/sequence/position.rb
CHANGED
data/lib/sequence/reversed.rb
CHANGED
data/lib/sequence/shifting.rb
CHANGED
data/lib/sequence/singleitem.rb
CHANGED
data/lib/sequence/stringlike.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2006,2008 Caleb Clausen
|
1
|
+
# Copyright (C) 2006,2008, 2011 Caleb Clausen
|
2
2
|
# Distributed under the terms of Ruby's license.
|
3
3
|
require 'sequence/subseq'
|
4
4
|
|
@@ -216,7 +216,9 @@ class Sequence
|
|
216
216
|
def _anchor(str,backwards=false,cache=true)
|
217
217
|
cache and result=@@anchor_cache[[str,backwards]] and return result
|
218
218
|
result=backwards ? "(?:#{str})\\Z" : "\\A(?:#{str})"
|
219
|
-
cache and return @@anchor_cache[[str,backwards]]||=Regexp.new( result )
|
219
|
+
cache and return @@anchor_cache[[str,backwards]]||=Regexp.new( result, 0, 'n' )
|
220
|
+
#is it really correct to force regexp to be binary encoding here? not sure
|
221
|
+
#maybe encoding of str should be detected and reused?
|
220
222
|
return result
|
221
223
|
end
|
222
224
|
|
data/lib/sequence/subseq.rb
CHANGED
data/lib/sequence/usedata.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Copyright (C) 2006 Caleb Clausen
|
1
|
+
# Copyright (C) 2006, 2011 Caleb Clausen
|
2
2
|
# Distributed under the terms of Ruby's license.
|
3
|
-
require 'sequence'
|
3
|
+
#require 'sequence'
|
4
4
|
class Sequence
|
5
5
|
# define #read in terms of #data and @pos.
|
6
6
|
# #data must support #[]
|
@@ -32,4 +32,4 @@ class Sequence
|
|
32
32
|
def_delegators :@data, :<<
|
33
33
|
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|