|
Packit |
5b08af |
{-# LANGUAGE FlexibleInstances #-}
|
|
Packit |
5b08af |
{-# LANGUAGE TypeSynonymInstances #-}
|
|
Packit |
5b08af |
{-# LANGUAGE OverloadedStrings #-}
|
|
Packit |
5b08af |
{-# LANGUAGE ViewPatterns #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{- |
|
|
Packit |
5b08af |
Copyright : Copyright (C) 2014- Uwe Schmidt
|
|
Packit |
5b08af |
License : MIT
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
Maintainer : Uwe Schmidt <uwe@fh-wedel.de>
|
|
Packit |
5b08af |
Stability : stable
|
|
Packit |
5b08af |
-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
module Text.Regex.XMLSchema.Generic.StringLike
|
|
Packit |
5b08af |
where
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
import Data.Maybe
|
|
Packit |
5b08af |
import Data.String (IsString(..))
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
import qualified Data.Text as T
|
|
Packit |
5b08af |
import qualified Data.Text.Lazy as TL
|
|
Packit |
5b08af |
import qualified Data.ByteString.Char8 as B
|
|
Packit |
5b08af |
import qualified Data.ByteString.Lazy.Char8 as BL
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- | /WARNING/: This StringLike class is /not/ intended for use outside this regex library.
|
|
Packit |
5b08af |
-- It provides an abstraction for String's as used inside this library.
|
|
Packit |
5b08af |
-- It allows the library to work with String (list of Char),
|
|
Packit |
5b08af |
-- ByteString.Char8, ByteString.Lazy.Char8,
|
|
Packit |
5b08af |
-- Data.Text and Data.Text.Lazy.
|
|
Packit |
5b08af |
--
|
|
Packit |
5b08af |
-- The class is similar to the StringLike class in the tagsoup package
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
class (Eq a, IsString a, Show a) => StringLike a where
|
|
Packit |
5b08af |
emptyS :: a
|
|
Packit |
5b08af |
uncons :: a -> Maybe (Char, a)
|
|
Packit |
5b08af |
nullS :: a -> Bool
|
|
Packit |
5b08af |
headS :: a -> Char
|
|
Packit |
5b08af |
takeS :: Int -> a -> a
|
|
Packit |
5b08af |
dropS :: Int -> a -> a
|
|
Packit |
5b08af |
appendS :: a -> a -> a
|
|
Packit |
5b08af |
concatS :: [a] -> a
|
|
Packit |
5b08af |
toString :: a -> String
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
nullS = isNothing . uncons
|
|
Packit |
5b08af |
headS (uncons -> Just (c, _))
|
|
Packit |
5b08af |
= c
|
|
Packit |
5b08af |
headS _ = error "headS: empty StringLike"
|
|
Packit |
5b08af |
concatS = foldl appendS emptyS
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE headS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
instance StringLike String where
|
|
Packit |
5b08af |
emptyS = []
|
|
Packit |
5b08af |
uncons (x : xs) = Just (x, xs)
|
|
Packit |
5b08af |
uncons "" = Nothing
|
|
Packit |
5b08af |
nullS = null
|
|
Packit |
5b08af |
headS = head
|
|
Packit |
5b08af |
takeS = take
|
|
Packit |
5b08af |
dropS = drop
|
|
Packit |
5b08af |
appendS = (++)
|
|
Packit |
5b08af |
concatS = concat
|
|
Packit |
5b08af |
toString = id
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE emptyS #-}
|
|
Packit |
5b08af |
{-# INLINE uncons #-}
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE takeS #-}
|
|
Packit |
5b08af |
{-# INLINE dropS #-}
|
|
Packit |
5b08af |
{-# INLINE appendS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
{-# INLINE toString #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
instance StringLike T.Text where
|
|
Packit |
5b08af |
emptyS = T.empty
|
|
Packit |
5b08af |
uncons = T.uncons
|
|
Packit |
5b08af |
nullS = T.null
|
|
Packit |
5b08af |
headS = T.head
|
|
Packit |
5b08af |
takeS = T.take
|
|
Packit |
5b08af |
dropS = T.drop
|
|
Packit |
5b08af |
appendS = T.append
|
|
Packit |
5b08af |
concatS = T.concat
|
|
Packit |
5b08af |
toString = T.unpack
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE emptyS #-}
|
|
Packit |
5b08af |
{-# INLINE uncons #-}
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE takeS #-}
|
|
Packit |
5b08af |
{-# INLINE dropS #-}
|
|
Packit |
5b08af |
{-# INLINE appendS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
{-# INLINE toString #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
instance StringLike TL.Text where
|
|
Packit |
5b08af |
emptyS = TL.empty
|
|
Packit |
5b08af |
uncons = TL.uncons
|
|
Packit |
5b08af |
nullS = TL.null
|
|
Packit |
5b08af |
headS = TL.head
|
|
Packit |
5b08af |
takeS = TL.take . toEnum
|
|
Packit |
5b08af |
dropS = TL.drop . toEnum
|
|
Packit |
5b08af |
appendS = TL.append
|
|
Packit |
5b08af |
concatS = TL.concat
|
|
Packit |
5b08af |
toString = TL.unpack
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE emptyS #-}
|
|
Packit |
5b08af |
{-# INLINE uncons #-}
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE takeS #-}
|
|
Packit |
5b08af |
{-# INLINE dropS #-}
|
|
Packit |
5b08af |
{-# INLINE appendS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
{-# INLINE toString #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
instance StringLike B.ByteString where
|
|
Packit |
5b08af |
emptyS = B.empty
|
|
Packit |
5b08af |
uncons = B.uncons
|
|
Packit |
5b08af |
nullS = B.null
|
|
Packit |
5b08af |
headS = B.head
|
|
Packit |
5b08af |
takeS = B.take
|
|
Packit |
5b08af |
dropS = B.drop
|
|
Packit |
5b08af |
appendS = B.append
|
|
Packit |
5b08af |
concatS = B.concat
|
|
Packit |
5b08af |
toString = B.unpack
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE emptyS #-}
|
|
Packit |
5b08af |
{-# INLINE uncons #-}
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE takeS #-}
|
|
Packit |
5b08af |
{-# INLINE dropS #-}
|
|
Packit |
5b08af |
{-# INLINE appendS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
{-# INLINE toString #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
instance StringLike BL.ByteString where
|
|
Packit |
5b08af |
emptyS = BL.empty
|
|
Packit |
5b08af |
uncons = BL.uncons
|
|
Packit |
5b08af |
nullS = BL.null
|
|
Packit |
5b08af |
headS = BL.head
|
|
Packit |
5b08af |
takeS = BL.take . toEnum
|
|
Packit |
5b08af |
dropS = BL.drop . toEnum
|
|
Packit |
5b08af |
appendS = BL.append
|
|
Packit |
5b08af |
concatS = BL.concat
|
|
Packit |
5b08af |
toString = BL.unpack
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
{-# INLINE emptyS #-}
|
|
Packit |
5b08af |
{-# INLINE uncons #-}
|
|
Packit |
5b08af |
{-# INLINE nullS #-}
|
|
Packit |
5b08af |
{-# INLINE takeS #-}
|
|
Packit |
5b08af |
{-# INLINE dropS #-}
|
|
Packit |
5b08af |
{-# INLINE appendS #-}
|
|
Packit |
5b08af |
{-# INLINE concatS #-}
|
|
Packit |
5b08af |
{-# INLINE toString #-}
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
-- ------------------------------------------------------------
|
|
Packit |
5b08af |
|
|
Packit |
5b08af |
|