{-# LANGUAGE TypeApplications #-}
module Data.Bytes.Text.Ascii
( fromString
) where
import Data.Bytes.Types (Bytes)
import Data.Char (ord)
import Data.Word (Word8)
import qualified Data.Bytes.Pure as Bytes
import qualified GHC.Exts as Exts
fromString :: String -> Bytes
fromString :: String -> Bytes
fromString = ByteArray -> Bytes
Bytes.fromByteArray
(ByteArray -> Bytes) -> (String -> ByteArray) -> String -> Bytes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteArray
forall l. IsList l => [Item l] -> l
Exts.fromList
([Word8] -> ByteArray)
-> (String -> [Word8]) -> String -> ByteArray
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Word8) -> String -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (\Char
c -> let i :: Int
i = Char -> Int
ord Char
c in if Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
128 then Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word8 Int
i else Word8
0)