1
1
mirror of https://github.com/github/semantic.git synced 2025-01-08 16:39:47 +03:00

Move safeRange into the Range module.

This commit is contained in:
Rob Rix 2016-03-02 18:54:12 -05:00
parent 49b6984d49
commit e630169833
2 changed files with 4 additions and 4 deletions

View File

@ -109,10 +109,6 @@ splitAnnotatedByLines sources ranges categories syntax = case syntax of
makeRanges :: Both Int -> Both Int -> Both Range
makeRanges a b = runBothWith safeRange <$> sequenceA (both a b)
-- | Constructs a Range such that its end is clamped to its start.
safeRange :: Int -> Int -> Range
safeRange start end = Range start (max start end)
-- | Produces the starting indices of a diff.
diffRanges :: Diff leaf Info -> Both (Maybe Range)
diffRanges (Free (Annotated infos _)) = Just . characterRange <$> infos

View File

@ -15,6 +15,10 @@ data Range = Range { start :: !Int, end :: !Int }
rangeAt :: Int -> Range
rangeAt a = Range a a
-- | Constructs a Range such that its end is clamped to its start.
safeRange :: Int -> Int -> Range
safeRange start end = Range start (max start end)
-- | Return the length of the range.
rangeLength :: Range -> Int
rangeLength range = end range - start range