mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-27 02:41:53 +00:00
0.2.5 initial commit
Makefile incomplete
This commit is contained in:
23
agent/src/Util/Conduit.hs
Normal file
23
agent/src/Util/Conduit.hs
Normal file
@@ -0,0 +1,23 @@
|
||||
module Util.Conduit where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Conduit
|
||||
import Data.Text as T
|
||||
import Data.Attoparsec.Text
|
||||
|
||||
parseC :: MonadIO m => Parser b -> ConduitT Text b m ()
|
||||
parseC parser = fix $ \cont -> parseWith g parser "" >>= \case
|
||||
Done rest result -> do
|
||||
yield result
|
||||
unless (T.null rest) $ leftover rest >> cont
|
||||
Fail _ _ msg -> panic $ toS msg
|
||||
Partial _ -> panic "INCOMPLETE PARSE"
|
||||
where
|
||||
g :: MonadIO m => ConduitT Text o m Text
|
||||
g = await >>= \case
|
||||
Nothing -> pure mempty
|
||||
Just x -> print x >> pure x
|
||||
|
||||
lineParser :: Parser Text
|
||||
lineParser = takeTill isEndOfLine <* endOfLine
|
||||
12
agent/src/Util/File.hs
Normal file
12
agent/src/Util/File.hs
Normal file
@@ -0,0 +1,12 @@
|
||||
module Util.File where
|
||||
|
||||
import Startlude
|
||||
|
||||
import System.Directory
|
||||
import System.IO.Error
|
||||
|
||||
removeFileIfExists :: MonadIO m => FilePath -> m ()
|
||||
removeFileIfExists fileName = liftIO $ removeFile fileName `catch` handleExists
|
||||
where
|
||||
handleExists e | isDoesNotExistError e = return ()
|
||||
| otherwise = throwIO e
|
||||
16
agent/src/Util/Function.hs
Normal file
16
agent/src/Util/Function.hs
Normal file
@@ -0,0 +1,16 @@
|
||||
module Util.Function where
|
||||
|
||||
import Startlude
|
||||
|
||||
infixr 9 .*
|
||||
(.*) :: (b -> c) -> (a0 -> a1 -> b) -> a0 -> a1 -> c
|
||||
(.*) = (.) . (.)
|
||||
{-# INLINE (.*) #-}
|
||||
|
||||
infixr 9 .**
|
||||
(.**) :: (b -> c) -> (a0 -> a1 -> a2 -> b) -> a0 -> a1 -> a2 -> c
|
||||
(.**) = (.) . (.*)
|
||||
{-# INLINE (.**) #-}
|
||||
|
||||
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
|
||||
uncurry3 f (a, b, c) = f a b c
|
||||
24
agent/src/Util/Text.hs
Normal file
24
agent/src/Util/Text.hs
Normal file
@@ -0,0 +1,24 @@
|
||||
module Util.Text where
|
||||
|
||||
import Data.Text ( strip )
|
||||
import Startlude
|
||||
import Text.Regex ( matchRegexAll
|
||||
, mkRegex
|
||||
, subRegex
|
||||
)
|
||||
|
||||
|
||||
-- | Behaves like Ruby gsub implementation
|
||||
gsub :: Text -> Text -> Text -> Text
|
||||
gsub regex replaceWith str = toS $ subRegex (mkRegex $ toS regex) (toS str) (toS replaceWith)
|
||||
|
||||
containsMatch :: Text -> Text -> Bool
|
||||
containsMatch regex str = not . null $ getMatches regex str
|
||||
|
||||
getMatches :: Text -> Text -> [Text]
|
||||
getMatches regex str
|
||||
| str == "" = []
|
||||
| otherwise = case matchRegexAll (mkRegex $ toS regex) (toS str) of
|
||||
Nothing -> []
|
||||
Just (_, "" , after, _) -> getMatches regex (toS . strip . toS $ after)
|
||||
Just (_, match, after, _) -> toS match : getMatches regex (toS after)
|
||||
Reference in New Issue
Block a user