Class: Sequence::OfString
- Inherits:
-
Indexed
show all
- Includes:
- StringLike
- Defined in:
- lib/sequence/indexed.rb
Constant Summary
Constants inherited
from Sequence
SubSequence, VERSION
Instance Attribute Summary
Attributes inherited from Indexed
#data, #pos
Instance Method Summary
collapse
Methods inherited from Indexed
_orig_new, #_pos=, #eof?, #initialize, #maxmatchlen, #maxmatchlen=, #modify
Methods inherited from UseData
#read, #readahead, #readback, #readbehind, #size
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
|