From cfeb9e4ee81e66196e6251c72af649b25202f72f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 24 Dec 2015 00:08:17 -0500 Subject: [PATCH] Move `actualLines`/`actualLineRanges` into the Source module. --- src/Source.hs | 12 ++++++++++++ src/Split.hs | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Source.hs b/src/Source.hs index 4f081e628..82a67aeb6 100644 --- a/src/Source.hs +++ b/src/Source.hs @@ -35,3 +35,15 @@ break predicate (Source vector) = let (start, remainder) = Vector.break predicat (++) :: Source a -> Source a -> Source a (++) (Source a) = Source . (a Vector.++) . getVector + +actualLines :: Source Char -> [Source Char] +actualLines source | length source == 0 = [ source ] +actualLines source = case Source.break (== '\n') source of + (l, lines') -> case uncons lines' of + Nothing -> [ l ] + Just (_, lines') -> (l Source.++ fromList "\n") : actualLines lines' + +-- | Compute the line ranges within a given range of a string. +actualLineRanges :: Range -> Source Char -> [Range] +actualLineRanges range = drop 1 . scanl toRange (Range (start range) (start range)) . actualLines . slice range + where toRange previous string = Range (end previous) $ end previous + length string diff --git a/src/Split.hs b/src/Split.hs index f8c72d048..d224001a6 100644 --- a/src/Split.hs +++ b/src/Split.hs @@ -18,7 +18,6 @@ import Text.Blaze.Html.Renderer.Utf8 import Data.Monoid import qualified Data.Set as Set import Source hiding ((++)) -import qualified Source as Source ((++)) type ClassName = String @@ -153,15 +152,3 @@ openDiff source diff@(Pure term) = const diff <$> openTerm source term zipWithDefaults :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c] zipWithDefaults f da db a b = take (max (length a) (length b)) $ zipWith f (a ++ repeat da) (b ++ repeat db) - -actualLines :: Source Char -> [Source Char] -actualLines source | length source == 0 = [ source ] -actualLines source = case Source.break (== '\n') source of - (l, lines') -> case uncons lines' of - Nothing -> [ l ] - Just (_, lines') -> (l Source.++ fromList "\n") : actualLines lines' - --- | Compute the line ranges within a given range of a string. -actualLineRanges :: Range -> Source Char -> [Range] -actualLineRanges range = drop 1 . scanl toRange (Range (start range) (start range)) . actualLines . slice range - where toRange previous string = Range (end previous) $ end previous + length string