packages feed

haskus-utils-compat 1.0 → 1.1

raw patch · 3 files changed

+98/−4 lines, 3 filesdep +formattingdep +textPVP ok

version bump matches the API change (PVP)

Dependencies added: formatting, text

API changes (from Hackage documentation)

+ Haskus.Utils.Embed.ByteString: embedBSFilePrefix :: FilePath -> FilePath -> Q Exp
+ Haskus.Utils.Text: (%) :: () => Format r a -> Format r' r -> Format r' a
+ Haskus.Utils.Text: (%.) :: () => Format r (Builder -> r') -> Format r' a -> Format r a
+ Haskus.Utils.Text: all :: (Char -> Bool) -> Text -> Bool
+ Haskus.Utils.Text: any :: (Char -> Bool) -> Text -> Bool
+ Haskus.Utils.Text: append :: Text -> Text -> Text
+ Haskus.Utils.Text: break :: (Char -> Bool) -> Text -> (Text, Text)
+ Haskus.Utils.Text: breakOn :: Text -> Text -> (Text, Text)
+ Haskus.Utils.Text: breakOnAll :: Text -> Text -> [(Text, Text)]
+ Haskus.Utils.Text: breakOnEnd :: Text -> Text -> (Text, Text)
+ Haskus.Utils.Text: bufferDecodeUtf8 :: Buffer -> Text
+ Haskus.Utils.Text: chunksOf :: Int -> Text -> [Text]
+ Haskus.Utils.Text: commonPrefixes :: Text -> Text -> Maybe (Text, Text, Text)
+ Haskus.Utils.Text: compareLength :: Text -> Int -> Ordering
+ Haskus.Utils.Text: concat :: [Text] -> Text
+ Haskus.Utils.Text: concatMap :: (Char -> Text) -> Text -> Text
+ Haskus.Utils.Text: cons :: Char -> Text -> Text
+ Haskus.Utils.Text: copy :: Text -> Text
+ Haskus.Utils.Text: count :: Text -> Text -> Int
+ Haskus.Utils.Text: data Format r a
+ Haskus.Utils.Text: data Text
+ Haskus.Utils.Text: drop :: Int -> Text -> Text
+ Haskus.Utils.Text: dropAround :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: dropEnd :: Int -> Text -> Text
+ Haskus.Utils.Text: dropWhile :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: dropWhileEnd :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: empty :: Text
+ Haskus.Utils.Text: filter :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: find :: (Char -> Bool) -> Text -> Maybe Char
+ Haskus.Utils.Text: findIndex :: (Char -> Bool) -> Text -> Maybe Int
+ Haskus.Utils.Text: foldl :: () => (a -> Char -> a) -> a -> Text -> a
+ Haskus.Utils.Text: foldl' :: () => (a -> Char -> a) -> a -> Text -> a
+ Haskus.Utils.Text: foldl1 :: (Char -> Char -> Char) -> Text -> Char
+ Haskus.Utils.Text: foldl1' :: (Char -> Char -> Char) -> Text -> Char
+ Haskus.Utils.Text: foldr :: () => (Char -> a -> a) -> a -> Text -> a
+ Haskus.Utils.Text: foldr1 :: (Char -> Char -> Char) -> Text -> Char
+ Haskus.Utils.Text: getTextUtf8 :: Word -> Get Text
+ Haskus.Utils.Text: getTextUtf8Nul :: Get Text
+ Haskus.Utils.Text: group :: Text -> [Text]
+ Haskus.Utils.Text: groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
+ Haskus.Utils.Text: head :: Text -> Char
+ Haskus.Utils.Text: index :: Text -> Int -> Char
+ Haskus.Utils.Text: infixr 5 `cons`
+ Haskus.Utils.Text: infixr 8 %.
+ Haskus.Utils.Text: infixr 9 %
+ Haskus.Utils.Text: init :: Text -> Text
+ Haskus.Utils.Text: inits :: Text -> [Text]
+ Haskus.Utils.Text: intercalate :: Text -> [Text] -> Text
+ Haskus.Utils.Text: intersperse :: Char -> Text -> Text
+ Haskus.Utils.Text: isInfixOf :: Text -> Text -> Bool
+ Haskus.Utils.Text: isPrefixOf :: Text -> Text -> Bool
+ Haskus.Utils.Text: isSuffixOf :: Text -> Text -> Bool
+ Haskus.Utils.Text: justifyLeft :: Int -> Char -> Text -> Text
+ Haskus.Utils.Text: justifyRight :: Int -> Char -> Text -> Text
+ Haskus.Utils.Text: last :: Text -> Char
+ Haskus.Utils.Text: length :: Text -> Int
+ Haskus.Utils.Text: lines :: Text -> [Text]
+ Haskus.Utils.Text: map :: (Char -> Char) -> Text -> Text
+ Haskus.Utils.Text: mapAccumL :: () => (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
+ Haskus.Utils.Text: mapAccumR :: () => (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
+ Haskus.Utils.Text: maximum :: Text -> Char
+ Haskus.Utils.Text: minimum :: Text -> Char
+ Haskus.Utils.Text: null :: Text -> Bool
+ Haskus.Utils.Text: pack :: String -> Text
+ Haskus.Utils.Text: partition :: (Char -> Bool) -> Text -> (Text, Text)
+ Haskus.Utils.Text: putStrLn :: Text -> IO ()
+ Haskus.Utils.Text: putTextUtf8 :: Text -> Put
+ Haskus.Utils.Text: replace :: Text -> Text -> Text -> Text
+ Haskus.Utils.Text: replicate :: Int -> Text -> Text
+ Haskus.Utils.Text: reverse :: Text -> Text
+ Haskus.Utils.Text: scanl :: (Char -> Char -> Char) -> Char -> Text -> Text
+ Haskus.Utils.Text: scanl1 :: (Char -> Char -> Char) -> Text -> Text
+ Haskus.Utils.Text: scanr :: (Char -> Char -> Char) -> Char -> Text -> Text
+ Haskus.Utils.Text: scanr1 :: (Char -> Char -> Char) -> Text -> Text
+ Haskus.Utils.Text: singleton :: Char -> Text
+ Haskus.Utils.Text: snoc :: Text -> Char -> Text
+ Haskus.Utils.Text: span :: (Char -> Bool) -> Text -> (Text, Text)
+ Haskus.Utils.Text: split :: (Char -> Bool) -> Text -> [Text]
+ Haskus.Utils.Text: splitAt :: Int -> Text -> (Text, Text)
+ Haskus.Utils.Text: splitOn :: Text -> Text -> [Text]
+ Haskus.Utils.Text: stringEncodeUtf8 :: String -> Buffer
+ Haskus.Utils.Text: strip :: Text -> Text
+ Haskus.Utils.Text: stripEnd :: Text -> Text
+ Haskus.Utils.Text: stripPrefix :: Text -> Text -> Maybe Text
+ Haskus.Utils.Text: stripStart :: Text -> Text
+ Haskus.Utils.Text: stripSuffix :: Text -> Text -> Maybe Text
+ Haskus.Utils.Text: tail :: Text -> Text
+ Haskus.Utils.Text: tails :: Text -> [Text]
+ Haskus.Utils.Text: take :: Int -> Text -> Text
+ Haskus.Utils.Text: takeEnd :: Int -> Text -> Text
+ Haskus.Utils.Text: takeWhile :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: takeWhileEnd :: (Char -> Bool) -> Text -> Text
+ Haskus.Utils.Text: textEncodeUtf8 :: Text -> Buffer
+ Haskus.Utils.Text: textFormat :: Format Text a -> a
+ Haskus.Utils.Text: textParseHexadecimal :: Integral a => Text -> Either String a
+ Haskus.Utils.Text: toCaseFold :: Text -> Text
+ Haskus.Utils.Text: toLower :: Text -> Text
+ Haskus.Utils.Text: toTitle :: Text -> Text
+ Haskus.Utils.Text: toUpper :: Text -> Text
+ Haskus.Utils.Text: transpose :: [Text] -> [Text]
+ Haskus.Utils.Text: tshow :: Show a => a -> Text
+ Haskus.Utils.Text: uncons :: Text -> Maybe (Char, Text)
+ Haskus.Utils.Text: unfoldr :: () => (a -> Maybe (Char, a)) -> a -> Text
+ Haskus.Utils.Text: unfoldrN :: () => Int -> (a -> Maybe (Char, a)) -> a -> Text
+ Haskus.Utils.Text: unlines :: [Text] -> Text
+ Haskus.Utils.Text: unpack :: Text -> String
+ Haskus.Utils.Text: unpackCString# :: Addr# -> Text
+ Haskus.Utils.Text: unsnoc :: Text -> Maybe (Text, Char)
+ Haskus.Utils.Text: unwords :: [Text] -> Text
+ Haskus.Utils.Text: words :: Text -> [Text]
+ Haskus.Utils.Text: zip :: Text -> Text -> [(Char, Char)]
+ Haskus.Utils.Text: zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text

Files

haskus-utils-compat.cabal view
@@ -1,12 +1,12 @@ name:                haskus-utils-compat-version:             1.0+version:             1.1 synopsis:            Compatibility modules with other external packages (ByteString, etc.) license:             BSD3 license-file:        LICENSE author:              Sylvain Henry maintainer:          sylvain@haskus.fr homepage:            http://docs.haskus.org/-copyright:           Sylvain Henry 2019+copyright:           Sylvain Henry 2020 category:            System build-type:          Simple cabal-version:       1.20@@ -16,11 +16,12 @@  source-repository head   type: git-  location: git://github.com/haskus/haskus-utils.git+  location: git://github.com/haskus/packages.git  library   exposed-modules:     Haskus.Utils.Embed.ByteString+    Haskus.Utils.Text    other-modules: @@ -32,8 +33,9 @@       ,  directory       ,  filepath       ,  bytestring+      ,  text+      ,  formatting -  build-tools:    ghc-options:          -Wall   default-language:     Haskell2010   hs-source-dirs:       src/lib
src/lib/Haskus/Utils/Embed/ByteString.hs view
@@ -1,12 +1,15 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE LambdaCase #-}  -- | Embed files as ByteStrings into an executable module Haskus.Utils.Embed.ByteString    ( bufferToByteString    , embedBS    , embedBSFile+   , embedBSFilePrefix    , embedBSOneFileOf    , embedBSDir    , module Haskus.Memory.Embed@@ -48,6 +51,16 @@    bs <- runIO $ BS.readFile fp    embedBS bs +embedBSFilePrefix :: FilePath -> FilePath -> Q Exp+embedBSFilePrefix prefix fp' = do+   -- small hack because "stack build" and "stack repl" in the multi-package+   -- project have different CWD+   fp <- liftIO (doesFileExist fp') >>= \case+            True  -> return fp'+            False -> return (prefix </> fp')+   embedBSFile fp++ -- | Embed a single existing file in your source code -- out of list a list of paths supplied. --@@ -82,7 +95,11 @@    bufToBs <- [| bufferToByteString |]    let embedPair (relpath,realpath) = do          exp' <- embedFile realpath False Nothing Nothing Nothing+#if __GLASGOW_HASKELL__ >= 810+         return $! TupE [Just (LitE $ StringL relpath), Just (bufToBs `AppE` exp')]+#else          return $! TupE [LitE $ StringL relpath, bufToBs `AppE` exp']+#endif    e <- ListE <$> ((runIO $ listDirectoryRec fp) >>= mapM embedPair)    return $ SigE e typ 
+ src/lib/Haskus/Utils/Text.hs view
@@ -0,0 +1,75 @@+-- | Wrap Data.Text+--+-- We plan to replace it with Haskus.Text in the future+module Haskus.Utils.Text+   ( module Data.Text+   -- * Conversions+   , bufferDecodeUtf8+   , textEncodeUtf8+   , stringEncodeUtf8+   -- * Formatting+   , textFormat+   , F.Format+   , (F.%)+   , (F.%.)+   , module Formatting.Formatters+   -- * Parsing+   , textParseHexadecimal+   -- * Get/Put+   , putTextUtf8+   , getTextUtf8+   , getTextUtf8Nul+   , tshow+   -- * IO+   , T.putStrLn+   )+where++import Data.Text hiding (center)+import qualified Data.Text.Encoding as T+import qualified Data.Text          as T+import qualified Data.Text.IO       as T+import Formatting                   as F+import Formatting.Formatters+import Data.Text.Read               as T++import Haskus.Binary.Buffer+import Haskus.Binary.Put+import Haskus.Binary.Get++-- | Decode Utf8+bufferDecodeUtf8 :: Buffer -> Text+bufferDecodeUtf8 (Buffer bs) = T.decodeUtf8 bs++-- | Encode Text into Utf8+textEncodeUtf8 :: Text -> Buffer+textEncodeUtf8 = Buffer . T.encodeUtf8++-- | Encode String into Utf8+stringEncodeUtf8 :: String -> Buffer+stringEncodeUtf8 = textEncodeUtf8 . T.pack++-- | Format a text (strict)+textFormat :: Format Text a -> a+textFormat = F.sformat++-- | Parse an hexadecimal number+-- FIXME: use a real parser (MegaParsec, etc.)+textParseHexadecimal :: Integral a => Text -> Either String a+textParseHexadecimal s = fst <$> T.hexadecimal s++-- | Put an UTF8 encoded text+putTextUtf8 :: Text -> Put+putTextUtf8 = putBuffer . textEncodeUtf8++-- | Pull n bytes from the input, as a Buffer+getTextUtf8 :: Word -> Get Text+getTextUtf8 sz = bufferDecodeUtf8 <$> getBuffer sz++-- | Pull \0 terminal text+getTextUtf8Nul :: Get Text+getTextUtf8Nul = bufferDecodeUtf8 <$> getBufferNul++-- | Show as Text+tshow :: Show a => a -> Text+tshow = pack . show