From 1ebe7bb5ed16b02b30244ba1e16d9634ffa0cb87 Mon Sep 17 00:00:00 2001 From: Matt Diephouse Date: Tue, 12 Jan 2016 11:52:38 -0500 Subject: [PATCH 1/2] Add a function to compute a range's length --- src/Range.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Range.hs b/src/Range.hs index 732603ed0..f44916da4 100644 --- a/src/Range.hs +++ b/src/Range.hs @@ -9,11 +9,14 @@ import Data.Maybe (fromMaybe) data Range = Range { start :: !Int, end :: !Int } deriving (Eq, Show) +rangeLength :: Range -> Int +rangeLength range = end range - start range + substring :: Range -> T.Text -> T.Text -substring range = T.take (end range - start range) . T.drop (start range) +substring range = T.take (rangeLength range) . T.drop (start range) sublist :: Range -> [a] -> [a] -sublist range = take (end range - start range) . drop (start range) +sublist range = take (rangeLength range) . drop (start range) totalRange :: T.Text -> Range totalRange t = Range 0 $ T.length t From f3dfe1c4049810c2a7df572315a16e9da4bab449 Mon Sep 17 00:00:00 2001 From: Matt Diephouse Date: Tue, 12 Jan 2016 11:56:36 -0500 Subject: [PATCH 2/2] Use rangeLength --- src/Source.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Source.hs b/src/Source.hs index cb005af96..9c5630179 100644 --- a/src/Source.hs +++ b/src/Source.hs @@ -18,7 +18,7 @@ toList :: Source a -> [a] toList = Vector.toList . getVector slice :: Range -> Source a -> Source a -slice range = Source . Vector.slice (start range) (end range - start range) . getVector +slice range = Source . Vector.slice (start range) (rangeLength range) . getVector toString :: Source Char -> String toString = toList