add toString function in ROPE signature defined in rope.sml
This commit is contained in:
16
rope.sml
16
rope.sml
@@ -5,6 +5,7 @@ sig
|
|||||||
val fromString: string -> t
|
val fromString: string -> t
|
||||||
val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a
|
val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a
|
||||||
val insert: int * string * t -> t
|
val insert: int * string * t -> t
|
||||||
|
val toString: t -> string
|
||||||
|
|
||||||
(* This below function verifies that line metadata is as expected,
|
(* This below function verifies that line metadata is as expected,
|
||||||
* raising an exception if it is different,
|
* raising an exception if it is different,
|
||||||
@@ -291,7 +292,7 @@ struct
|
|||||||
val total = oldLen + newLen
|
val total = oldLen + newLen
|
||||||
val newStrLen = String.size newStr
|
val newStrLen = String.size newStr
|
||||||
in
|
in
|
||||||
Vector.tabulate (total, (fn (idx) =>
|
Vector.tabulate (total, (fn idx =>
|
||||||
if idx < newLen then Vector.sub (newVec, idx)
|
if idx < newLen then Vector.sub (newVec, idx)
|
||||||
else Vector.sub (oldVec, idx - newLen) + newStrLen))
|
else Vector.sub (oldVec, idx - newLen) + newStrLen))
|
||||||
end
|
end
|
||||||
@@ -303,7 +304,7 @@ struct
|
|||||||
val total = oldLen + newLen
|
val total = oldLen + newLen
|
||||||
val oldStrLen = String.size oldStr
|
val oldStrLen = String.size oldStr
|
||||||
in
|
in
|
||||||
Vector.tabulate (total, (fn (idx) =>
|
Vector.tabulate (total, (fn idx =>
|
||||||
if idx < oldLen then Vector.sub (oldVec, idx)
|
if idx < oldLen then Vector.sub (oldVec, idx)
|
||||||
else Vector.sub (newVec, idx - oldLen) + oldStrLen))
|
else Vector.sub (newVec, idx - oldLen) + oldStrLen))
|
||||||
end
|
end
|
||||||
@@ -493,15 +494,18 @@ struct
|
|||||||
insLeaf (curIdx, newStr, newVec, rope, oldStr, oldVec)
|
insLeaf (curIdx, newStr, newVec, rope, oldStr, oldVec)
|
||||||
| _ => raise AuxConstructor
|
| _ => raise AuxConstructor
|
||||||
|
|
||||||
|
fun endInsert (rope, action) =
|
||||||
|
case action of
|
||||||
|
NoAction => rope
|
||||||
|
| AddedNode => insRoot rope
|
||||||
|
| DeletedNode => delRoot rope
|
||||||
|
|
||||||
fun insert (index, str, rope) =
|
fun insert (index, str, rope) =
|
||||||
let
|
let
|
||||||
val newVec = countLineBreaks str
|
val newVec = countLineBreaks str
|
||||||
val (rope, action) = ins (index, str, newVec, rope)
|
val (rope, action) = ins (index, str, newVec, rope)
|
||||||
in
|
in
|
||||||
(case action of
|
endInsert (rope, action)
|
||||||
NoAction => rope
|
|
||||||
| AddedNode => insRoot rope
|
|
||||||
| DeletedNode => delRoot rope)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun verifyLines rope =
|
fun verifyLines rope =
|
||||||
|
|||||||
Reference in New Issue
Block a user