1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Flip lineRangesWithin.

This commit is contained in:
Rob Rix 2019-09-20 15:24:57 -04:00
parent 8aae3128c6
commit ca6a785ae3
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -110,17 +110,17 @@ lines source = slice source <$> lineRanges source
-- | Compute the 'Range's of each line in a 'Source'.
lineRanges :: Source -> [Range]
lineRanges source = lineRangesWithin (totalRange source) source
lineRanges source = lineRangesWithin source (totalRange source)
-- | Compute the 'Range's of each line in a 'Range' of a 'Source'.
lineRangesWithin :: Range -> Source -> [Range]
lineRangesWithin range
lineRangesWithin :: Source -> Range -> [Range]
lineRangesWithin source range
= uncurry (zipWith Range)
. ((start range:) &&& (<> [ end range ]))
. fmap (+ succ (start range))
. newlineIndices
. sourceBytes
. flip slice range
$ slice source range
-- | Return all indices of newlines ('\n', '\r', and '\r\n') in the 'ByteString'.
newlineIndices :: B.ByteString -> [Int]