module Data.Text.Internal.Private
(
runText
, span_
) where
import Control.Monad.ST (ST, runST)
import Data.Text.Internal (Text(..), text)
import Data.Text.Unsafe (Iter(..), iter)
import qualified Data.Text.Array as A
#if defined(ASSERTS)
import GHC.Stack (HasCallStack)
#endif
span_ :: (Char -> Bool) -> Text -> (# Text, Text #)
span_ p t@(Text arr off len) = (# hd,tl #)
where hd = text arr off k
tl = text arr (off+k) (lenk)
!k = loop 0
loop !i | i < len && p c = loop (i+d)
| otherwise = i
where Iter c d = iter t i
runText ::
#if defined(ASSERTS)
HasCallStack =>
#endif
(forall s. (A.MArray s -> Int -> ST s Text) -> ST s Text) -> Text
runText act = runST (act $ \ !marr !len -> do
arr <- A.unsafeFreeze marr
return $! text arr 0 len)