class Sequence::OfString
Public Instance Methods
append(str)
click to toggle source
# 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)
click to toggle source
# File lib/sequence/indexed.rb, line 215 def index(pat,offset=0) @data.index(pat,offset) end
match(pat,anchored=true,len=size)
click to toggle source
# File lib/sequence/indexed.rb, line 188 def match pat,anchored=true,len=size len=size anchored and pat=_anchor(pat) #pat.last_match= self.last_match=Thread.current[:last_match]= #can't use String#index here... doesn't do anchors right 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)
click to toggle source
# File lib/sequence/indexed.rb, line 202 def matchback pat,anchored=true anchored and pat=_anchor(pat,:back) #pat.last_match= 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()
click to toggle source
# File lib/sequence/indexed.rb, line 231 def new_data "" end
rindex(pat,offset=0)
click to toggle source
# File lib/sequence/indexed.rb, line 219 def rindex(pat,offset=0) @data.rindex(pat,offset) end
scan(pat)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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