Skip to content

Commit 96b451a

Browse files
committed
Add some extra instances for RegexFlags
1 parent 4e5059d commit 96b451a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Data/String/Regex/Flags.purs

+27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module Data.String.Regex.Flags where
22

33
import Prelude
4+
5+
import Control.MonadPlus (guard)
6+
47
import Data.Monoid (class Monoid)
8+
import Data.String (joinWith)
59

610
type RegexFlagsRec =
711
{ global :: Boolean
@@ -85,3 +89,26 @@ instance semigroupRegexFlags :: Semigroup RegexFlags where
8589

8690
instance monoidRegexFlags :: Monoid RegexFlags where
8791
mempty = noFlags
92+
93+
instance eqRegexFlags :: Eq RegexFlags where
94+
eq (RegexFlags x) (RegexFlags y)
95+
= x.global == y.global
96+
&& x.ignoreCase == y.ignoreCase
97+
&& x.multiline == y.multiline
98+
&& x.sticky == y.sticky
99+
&& x.unicode == y.unicode
100+
101+
instance showRegexFlags :: Show RegexFlags where
102+
show (RegexFlags flags) =
103+
let
104+
usedFlags =
105+
[]
106+
<> (guard flags.global $> "global")
107+
<> (guard flags.ignoreCase $> "ignoreCase")
108+
<> (guard flags.multiline $> "multiline")
109+
<> (guard flags.sticky $> "sticky")
110+
<> (guard flags.unicode $> "unicode")
111+
in
112+
if usedFlags == []
113+
then "noFlags"
114+
else "(" <> joinWith " <> " usedFlags <> ")"

0 commit comments

Comments
 (0)