1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
-- Provide a fake API, mimicking Data.Text from text package,
-- but actually backed by type Text = String. It is used only in rare
-- circumstances, when prettyprinter is built with -text flag.
--
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Data.Text where
import Prelude hiding (head, length, null, replicate)
import qualified Data.Char
import qualified Data.List
type Text = String
cons = (:)
dropWhileEnd = Data.List.dropWhileEnd
head = Data.List.head
intercalate = Data.List.intercalate
length = Data.List.length :: [Char] -> Int
lines = Data.List.lines
map = Data.List.map
null = Data.List.null :: [Char] -> Bool
pack = id
replicate = (Data.List.concat .) . Data.List.replicate
singleton = (:[])
snoc xs x = xs ++ [x]
stripEnd = dropWhileEnd Data.Char.isSpace
unlines = Data.List.unlines
unpack = id
words = Data.List.words
uncons :: Text -> Maybe (Char, Text)
uncons [] = Nothing
uncons (x : xs) = Just (x, xs)
splitOn :: Text -> Text -> [Text]
splitOn pat src
| null pat = error "splitOn: empty pattern"
| otherwise = go [] src
where
go acc [] = [reverse acc]
go acc xs@(y : ys)
| pat `Data.List.isPrefixOf` xs
= reverse acc : go [] (drop (length pat) xs)
| otherwise
= go (y : acc) ys
|