module Darcs.Patch.RegChars ( regChars,
) where
import Darcs.Prelude
(&&&) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
&&& :: forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
(&&&) a -> Bool
a a -> Bool
b a
c = a -> Bool
a a
c Bool -> Bool -> Bool
&& a -> Bool
b a
c
(|||) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
||| :: forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
(|||) a -> Bool
a a -> Bool
b a
c = a -> Bool
a a
c Bool -> Bool -> Bool
|| a -> Bool
b a
c
{-# INLINE regChars #-}
regChars :: String -> Char -> Bool
regChars :: String -> Char -> Bool
regChars (Char
'^':String
cs) = Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Char -> Bool
normalRegChars (String -> String
unescapeChars String
cs)
regChars (Char
'\\':Char
'^':String
cs) = String -> Char -> Bool
normalRegChars (String -> Char -> Bool) -> String -> Char -> Bool
forall a b. (a -> b) -> a -> b
$ String -> String
unescapeChars (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Char
'^'Char -> String -> String
forall a. a -> [a] -> [a]
:String
cs
regChars String
cs = String -> Char -> Bool
normalRegChars (String -> Char -> Bool) -> String -> Char -> Bool
forall a b. (a -> b) -> a -> b
$ String -> String
unescapeChars String
cs
{-# INLINE unescapeChars #-}
unescapeChars :: String -> String
unescapeChars :: String -> String
unescapeChars (Char
'\\':Char
'n':String
cs) = Char
'\n' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
unescapeChars String
cs
unescapeChars (Char
'\\':Char
't':String
cs) = Char
'\t' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
unescapeChars String
cs
unescapeChars (Char
'\\':Char
'^':String
cs) = Char
'^' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
unescapeChars String
cs
unescapeChars (Char
c:String
cs) = Char
c Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
unescapeChars String
cs
unescapeChars [] = []
{-# INLINE normalRegChars #-}
normalRegChars :: String -> Char -> Bool
normalRegChars :: String -> Char -> Bool
normalRegChars (Char
'\\':Char
'.':String
cs) = (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'.') (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| String -> Char -> Bool
normalRegChars String
cs
normalRegChars (Char
'\\':Char
'-':String
cs) = (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'-') (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| String -> Char -> Bool
normalRegChars String
cs
normalRegChars (Char
'\\':Char
'\\':String
cs) = (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'\\') (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| String -> Char -> Bool
normalRegChars String
cs
normalRegChars (Char
'\\':Char
c:String
_) = String -> Char -> Bool
forall a. HasCallStack => String -> a
error (String -> Char -> Bool) -> String -> Char -> Bool
forall a b. (a -> b) -> a -> b
$ String
"'\\"String -> String -> String
forall a. [a] -> [a] -> [a]
++[Char
c]String -> String -> String
forall a. [a] -> [a] -> [a]
++String
"' not supported."
normalRegChars (Char
c1:Char
'-':Char
c2:String
cs) = ((Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
c1) (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
&&& (Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c2)) (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| String -> Char -> Bool
normalRegChars String
cs
normalRegChars (Char
c:String
cs) = (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c) (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| String -> Char -> Bool
normalRegChars String
cs
normalRegChars [] = \Char
_ -> Bool
False