Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
feat(string): update conversion to text
Browse files Browse the repository at this point in the history
  • Loading branch information
marmitar committed Jan 5, 2024
1 parent ab53212 commit d94684b
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 251 deletions.
18 changes: 8 additions & 10 deletions src/MCSP/Data/String.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module MCSP.Data.String (
Unbox,

-- ** Text IO
ShowString (..),
ReadString (..),
module MCSP.Data.String.Text,

-- * Accessors

Expand Down Expand Up @@ -175,14 +174,15 @@ import Data.Word (Word8)
import GHC.Base (undefined, ($!))
import GHC.IsList (IsList (..))
import GHC.Num (Num, (-))
import Text.Read (Read (..), readListPrecDefault)
import Text.ParserCombinators.ReadPrec (lift)
import Text.Read (Read (..))
import Text.Show (Show (..))

import Data.Vector.Generic qualified as Generic
import Data.Vector.Generic.Mutable qualified as Mutable
import Data.Vector.Unboxed (MVector, Unbox, Vector)

import MCSP.Data.String.Text (ReadString (..), ShowString (..), readCharsPrec)
import MCSP.Data.String.Text

-- --------------- --
-- Data definition --
Expand Down Expand Up @@ -446,17 +446,15 @@ instance ShowString a => Show (String a) where
{-# SPECIALIZE instance Show (String Char) #-}
{-# SPECIALIZE instance Show (String Int) #-}
{-# SPECIALIZE instance Show (String Word8) #-}
showsPrec _ s@Unboxed = showStr s
showsPrec _ = showStr
{-# INLINE showsPrec #-}

instance (ReadString a, Unbox a) => Read (String a) where
instance (Unbox a, ReadString a) => Read (String a) where
{-# SPECIALIZE instance Read (String Char) #-}
{-# SPECIALIZE instance Read (String Int) #-}
{-# SPECIALIZE instance Read (String Word8) #-}
readPrec = fromList <$> readCharsPrec
readPrec = lift (fromList <$> readStr)
{-# INLINE readPrec #-}
readListPrec = readListPrecDefault
{-# INLINE readListPrec #-}

-- -------------------- --
-- Evaluation (DeepSeq) --
Expand Down Expand Up @@ -1022,7 +1020,7 @@ modify f s@Unboxed = Generic.modify (f . mContents) s
-- | /O(n)/ Pair each character in a string with its index.
--
-- >>> indexed "greedy"
-- (0,'g')(1,'r')(2,'e')(3,'e')(4,'d')(5,'y')
-- (0,'g') (1,'r') (2,'e') (3,'e') (4,'d') (5,'y')
indexed :: String a -> String (Int, a)
indexed s@Unboxed = Generic.indexed s
{-# INLINE indexed #-}
Expand Down
Loading

0 comments on commit d94684b

Please sign in to comment.