0.2.5 initial commit

Makefile incomplete
This commit is contained in:
Aiden McClelland
2020-11-23 13:44:28 -07:00
commit 95d3845906
503 changed files with 53448 additions and 0 deletions

24
agent/src/Util/Text.hs Normal file
View 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)