mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 20:43:41 +00:00
0.2.5 initial commit
Makefile incomplete
This commit is contained in:
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