module Dormouse.Uri.RFC3986
  ( isGenDelim
  , isSubDelim
  , isReserved
  , isAsciiAlpha
  , isAsciiAlphaNumeric
  , isUnreserved
  , isSchemeChar
  , isUserInfoChar
  , isRegNameChar
  , isPathChar
  , isPathCharNoColon
  , isQueryChar
  , isFragmentChar
  ) where

import Data.Char as C

-- | Checks whether a char belongs to the gen-delims in RFC3986 
isGenDelim :: Char -> Bool
isGenDelim :: Char -> Bool
isGenDelim Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'?' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'#' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'[' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
']' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'@'

-- | Checks whether a char belongs to the sub-delims in RFC3986 
isSubDelim :: Char -> Bool
isSubDelim :: Char -> Bool
isSubDelim Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'!' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'$' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'&' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\'' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'(' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
')' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'*' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'+' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
';' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'='

-- | Checks whether a char belongs to the sub-delims in RFC3986 
isReserved :: Char -> Bool
isReserved :: Char -> Bool
isReserved Char
c = Char -> Bool
isGenDelim Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSubDelim Char
c

-- | Checks whether a char is ascii & alpha
isAsciiAlpha :: Char -> Bool
isAsciiAlpha :: Char -> Bool
isAsciiAlpha Char
c = Char -> Bool
C.isAlpha Char
c Bool -> Bool -> Bool
&& Char -> Bool
C.isAscii Char
c

-- | Checks whether a char is ascii & alphanumeric
isAsciiAlphaNumeric :: Char -> Bool
isAsciiAlphaNumeric :: Char -> Bool
isAsciiAlphaNumeric Char
c = Char -> Bool
C.isAlphaNum Char
c Bool -> Bool -> Bool
&& Char -> Bool
C.isAscii Char
c

-- | Checks whether a char belongs to the unreserved group in RFC3986 
isUnreserved :: Char -> Bool
isUnreserved :: Char -> Bool
isUnreserved Char
c = Char -> Bool
isAsciiAlphaNumeric Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'~'

-- | Checks whether a char is a valid scheme char in RFC3986
isSchemeChar :: Char -> Bool
isSchemeChar :: Char -> Bool
isSchemeChar Char
c = Char -> Bool
isAsciiAlphaNumeric Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'+' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-'

-- | Checks whether a char is a valid user info char in RFC3986
isUserInfoChar :: Char -> Bool
isUserInfoChar :: Char -> Bool
isUserInfoChar Char
c = Char -> Bool
isUnreserved Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSubDelim Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':'

-- | Checks whether a char is a valid reg-name char in RFC3986
isRegNameChar :: Char -> Bool
isRegNameChar :: Char -> Bool
isRegNameChar Char
c = Char -> Bool
isUnreserved Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSubDelim Char
c

-- | Checks whether a char is a valid path char in RFC3986
isPathChar :: Char -> Bool
isPathChar :: Char -> Bool
isPathChar Char
c = Char -> Bool
isUnreserved Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSubDelim Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'@'

-- | Checks whether a char is a valid path char (excluding colons) in RFC3986
isPathCharNoColon :: Char -> Bool
isPathCharNoColon :: Char -> Bool
isPathCharNoColon Char
c = Char -> Bool
isUnreserved Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSubDelim Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'@'

-- | Checks whether a char is a valid query char in RFC3986
isQueryChar :: Char -> Bool
isQueryChar :: Char -> Bool
isQueryChar Char
c = Char -> Bool
isPathChar Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'?' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/'

-- | Checks whether a char is a valid fragment char in RFC3986
isFragmentChar :: Char -> Bool
isFragmentChar :: Char -> Bool
isFragmentChar Char
c = Char -> Bool
isPathChar Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'?' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/'