Added insert function
This commit is contained in:
parent
06944142d6
commit
5804a6a74d
@ -189,6 +189,32 @@ module Parfait
|
|||||||
def padded_length
|
def padded_length
|
||||||
Object.padded( 4 * get_type().instance_length + @char_length )
|
Object.padded( 4 * get_type().instance_length + @char_length )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def insert(index, other)
|
||||||
|
if index<0
|
||||||
|
index = self.length()+1+index
|
||||||
|
end
|
||||||
|
cpy = Word.new( self.length()+other.length() )
|
||||||
|
cpy_ind=0
|
||||||
|
str_ind=0
|
||||||
|
while ( str_ind<index )
|
||||||
|
cpy.set_char(cpy_ind,self.get_char(str_ind))
|
||||||
|
cpy_ind=cpy_ind+1
|
||||||
|
str_ind=str_ind+1
|
||||||
|
end
|
||||||
|
oth_ind=0
|
||||||
|
while ( oth_ind<other.length() )
|
||||||
|
cpy.set_char(cpy_ind,other.get_char(oth_ind))
|
||||||
|
cpy_ind=cpy_ind+1
|
||||||
|
oth_ind=oth_ind+1
|
||||||
|
end
|
||||||
|
while ( str_ind<self.length() )
|
||||||
|
cpy.set_char(cpy_ind,self.get_char(str_ind))
|
||||||
|
str_ind=str_ind+1
|
||||||
|
cpy_ind=cpy_ind+1
|
||||||
|
end
|
||||||
|
cpy
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_length
|
def check_length
|
||||||
|
Loading…
Reference in New Issue
Block a user