mirror of
https://github.com/github/semantic.git
synced 2024-12-01 00:33:59 +03:00
Merge pull request #397 from github/range-length
Add a function to compute a range's length
This commit is contained in:
commit
b60a232bd6
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user