( Scheme
)
where
-import Data.Ascii (CIAscii)
+import Data.Ascii (AsciiBuilder, CIAscii)
import qualified Data.Ascii as A
import Data.Attoparsec.Char8
import qualified Data.ByteString.Char8 as BS
-- |'Scheme' names consist of a non-empty sequence of characters
-- beginning with a letter and followed by any combination of letters,
--- digits, plus (\'+\'), period (\'.\'), or hyphen (\'-\'):
+-- digits, plus (\'+\'), period (\'.\'), or hyphen (\'-\'). Comparison
+-- of 'Scheme's are always case-insensitive. See:
-- <http://tools.ietf.org/html/rfc3986#section-3.1>
newtype Scheme = Scheme CIAscii
deriving ( Eq
, Typeable
)
--- |'isString' is a fast but unsafe way to create 'Scheme' such that
+-- |'fromString' is a fast but unsafe way to create 'Scheme' such that
-- no validation on the string is performed.
deriving instance IsString Scheme
{-# INLINE nonFirst #-}
nonFirst c
= isAlpha_ascii c ∨
+ isDigit c ∨
c ≡ '+' ∨
c ≡ '-' ∨
c ≡ '.'
instance ConvertSuccess Scheme CIAscii where
{-# INLINE convertSuccess #-}
- convertSuccess (Scheme s) = s
+ convertSuccess (Scheme s) = foldCase s
+
+instance ConvertSuccess Scheme AsciiBuilder where
+ {-# INLINE convertSuccess #-}
+ convertSuccess = A.toAsciiBuilder ∘ A.fromCIAscii ∘ cs
instance ConvertAttempt CIAscii Scheme where
{-# INLINE convertAttempt #-}
convertAttempt = parseAttempt' def ∘ A.fromCIAscii
-deriveAttempts [ ([t| Scheme |], [t| CIAscii |])
+deriveAttempts [ ([t| Scheme |], [t| AsciiBuilder |])
+ , ([t| Scheme |], [t| CIAscii |])
]