From 599252e5ed916406e5554e5f635bf017632a4fc5 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 5 Oct 2024 00:57:12 +0100 Subject: [PATCH] add function to create a LineGap.t from a string (although, for performance reasons, it's best to use this function when string is shorter than 1024 chars) --- src/line_gap.sml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/line_gap.sml b/src/line_gap.sml index 2ab6f94..acec188 100644 --- a/src/line_gap.sml +++ b/src/line_gap.sml @@ -10,11 +10,14 @@ sig , rightLines: int vector list } - val delete: int * int * t -> t val empty: t - val insert: int * string * t -> t + + val fromString: string -> t val toString: t -> string + val delete: int * int * t -> t + val insert: int * string * t -> t + (* for testing *) val verifyIndex: t -> unit val verifyLines: t -> unit @@ -75,6 +78,15 @@ struct , rightLines = [] } + fun fromString str = + { idx = 0 + , leftStrings = [] + , rightStrings = [str] + , line = 0 + , leftLines = [] + , rightLines = [countLineBreaks str] + } + local fun helpToString (acc, input) = case input of