-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathString.hs
37 lines (27 loc) · 1.16 KB
/
String.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Util.String where
import Util.Conditional
import Util.List
import Util.Advanced
import Control.Monad (join)
-- | Remove optional delimiters from around a string
undelim :: Char -> Char -> String -> String
undelim o e = full?.hstrip o.estrip e
-- | undelim, but delimiters must be matched
unmatch :: Char -> Char -> String -> String
unmatch o e = \x -> mcond x ((.(==e)).(&&).(==o)) (const const) (const $ const $ const x) x
-- |'unquote' strips an optional leading single-quote
-- and an optional trailing single-quote from a string
unquote :: String -> String
unquote = undelim '\'' '\''
-- |'unbrace' strips an optional leading open-square-bracket
-- and an optional trailing close-square-bracket from a string
unbrace :: String -> String
unbrace = undelim '[' ']'
-- |Head-Strip: Optionally strip a character from the head of a string
hstrip :: Char -> String -> String
hstrip = flip (flip (hcond [].(==)) (const id)) (:)
-- |End-Strip: Optionally strip a character from the end of a string
estrip :: Char -> String -> String
estrip = join.(.(const.const)).flip(lcond [].(==))const
surround :: String -> String -> String -> String
surround pref suff s = pref ++ s ++ suff