Class: Sequence::OfString
Constant Summary
Constants included
from StringLike
StringLike::FFS_4BITTABLE
Constants inherited
from Sequence
SubSequence, VERSION
Instance Attribute Summary
Attributes inherited from Indexed
#data, #pos
Attributes inherited from Sequence
#last_match, #maxmatchlen
Instance Method Summary
collapse
Methods included from StringLike
#_anchor, #data_class, #ffs, #fixup_match_result, #fns, #group_anchors, #like, #match_fast, #push, #read_til_charset, #unshift
Methods inherited from Indexed
_orig_new, #_pos=, #eof?, #initialize, #maxmatchlen, #maxmatchlen=, #modify
Methods inherited from UseData
#read, #readahead, #readback, #readbehind, #size
Methods inherited from Sequence
#+, #-, #<<, [], #[], #[]=, #_adjust_pos_on_change, #_default_maxmatchlen, #_delete_position, #_normalize_pos, #_parse_slice_args, #_pos=, #all_data, #begin, #begin!, #check, #check_until, #checkback, #checkback_until, #close, #closed?, #delete, #each, #empty?, #end, #end!, #eof?, #exist?, #existback?, #first, #goto, #holding, #holding!, #holding?, #holding_position, #holding_position!, #holding_position?, #initialize, #insert, #last, #length, #match?, #matchback?, #modify, #more_data?, #move, #move!, #nearbegin, #nearend, #new, #notify_change, #on_change_notify, #original__new, #overwrite, #pop, #pos, #pos=, #pos?, #position, #position=, #position?, #pred, #prepend, #prop, #read, #read!, #read1, #readahead, #readahead1, #readback, #readback1, #readbehind, #readbehind1, #rest_size, #reversed, #shift, #size, #skip, #skip_literal, #skip_until, #skip_until_literal, #skipback, #skipback_until, #slice, #slice!, #slice1, #slice1!, #subseq, #succ, #to_sequence, #was_data?, #write, #writeahead, #writeback, #writebehind
Instance Method Details
#append(str) ⇒ Object
224
225
226
227
228
229
|
# File 'lib/sequence/indexed.rb', line 224
def append(str)
sz=size
@data << str
notify_change(self,sz,0,str.size)
self
end
|
#index(pat, offset = 0) ⇒ Object
215
216
217
|
# File 'lib/sequence/indexed.rb', line 215
def index(pat,offset=0)
@data.index(pat,offset)
end
|
#match(pat, anchored = true, len = size) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/sequence/indexed.rb', line 188
def match pat,anchored=true,len=size
len=size
anchored and pat=_anchor(pat)
self.last_match=Thread.current[:last_match]=
if pat.match @data[pos..-1]
newpos=@pos+$~.end(0)
fixup_match_result( $~,[],@pos,:post){
SubSeq.new(self,newpos,size-newpos)
}
end
end
|
#matchback(pat, anchored = true) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/sequence/indexed.rb', line 202
def matchback pat,anchored=true
anchored and pat=_anchor(pat,:back)
self.last_match=Thread.current[:last_match]=
if pat.match @data[0...pos]
fixup_match_result($~,[],0,:pre){
cu=SubSeq.new(self,0,pos=$~.pre_match.size)
cu.pos=pos
cu
}
end
end
|
#new_data ⇒ Object
231
232
233
|
# File 'lib/sequence/indexed.rb', line 231
def new_data
""
end
|
#rindex(pat, offset = 0) ⇒ Object
219
220
221
|
# File 'lib/sequence/indexed.rb', line 219
def rindex(pat,offset=0)
@data.rindex(pat,offset)
end
|
#scan(pat) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/sequence/indexed.rb', line 121
def scan(pat)
case pat
when Regexp
if (m=match pat,true)
@pos= m.end(0)
return m.to_s
end
when Integer
res=@data[@pos]
if res==pat
@pos+=1
return res.chr
end
when String
if @data[@pos...@pos+pat.size]==pat
@pos+=pat.size
return pat
end
end
end
|
#scan_until(pat) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/sequence/indexed.rb', line 163
def scan_until(pat)
if Regexp===pat
if (m=match pat,false)
@pos= m.end(0)
m.pre_match+m.to_s
end
else
i=@data.index(pat,pos) and
@data[@pos...@pos=i]
end
end
|
#scanback(pat) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/sequence/indexed.rb', line 142
def scanback(pat)
case pat
when Regexp
if (m=matchback pat,true)
@pos= m.begin(0)
return m.to_s
end
when Integer
res=@data[@pos]
if res==pat
@pos-=1
return res.chr
end
when String
if @data[@pos...@pos-pat.size]==pat
@pos-=pat.size
return pat
end
end
end
|
#scanback_until(pat) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/sequence/indexed.rb', line 175
def scanback_until(pat)
if Regexp===pat
if (m=matchback pat,true)
@pos= m.begin(0)
m.to_s+m.post_match
end
else
i=@data.rindex(pat,pos) or return
oldpos=@pos
@data[@pos=i...oldpos]
end
end
|