mirror of
https://github.com/github/semantic.git
synced 2024-12-27 00:44:57 +03:00
Move actualLines
/actualLineRanges
into the Source module.
This commit is contained in:
parent
d355f268e6
commit
cfeb9e4ee8
@ -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
|
||||
|
13
src/Split.hs
13
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
|
||||
|
Loading…
Reference in New Issue
Block a user