{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_HADDOCK hide #-}
module Core.Text.Parsing
( calculatePositionEnd
)
where
import Data.Foldable (foldl')
import qualified Data.Text.Short as S (ShortText, foldl')
import Core.Text.Rope
calculatePositionEnd :: Rope -> (Int,Int)
calculatePositionEnd text =
let
x = unRope text
(l,c) = foldl' calculateChunk (1,1) x
in
(l,c)
calculateChunk :: (Int,Int) -> S.ShortText -> (Int,Int)
calculateChunk loc piece =
S.foldl' f loc piece
where
f :: (Int,Int) -> Char -> (Int,Int)
f !(!l,!c) ch = if ch == '\n'
then (l+1,1)
else (l,c+1)