X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Data%2FURI%2FInternal%2FScheme.hs;h=ebef877e376c4334a21d361ebe6bb5d92b103542;hb=ceb6901;hp=2e3ba24efa7ac59a9e2c999910e7275f5713aaf1;hpb=087dd4f3ffb5aba8107c38f2eae0c82545ec21ca;p=Lucu.git diff --git a/Data/URI/Internal/Scheme.hs b/Data/URI/Internal/Scheme.hs index 2e3ba24..ebef877 100644 --- a/Data/URI/Internal/Scheme.hs +++ b/Data/URI/Internal/Scheme.hs @@ -12,7 +12,7 @@ module Data.URI.Internal.Scheme ( 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 @@ -28,7 +28,8 @@ import Prelude.Unicode -- |'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: -- newtype Scheme = Scheme CIAscii deriving ( Eq @@ -39,7 +40,7 @@ newtype Scheme = Scheme CIAscii , 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 @@ -56,19 +57,28 @@ instance Default (Parser Scheme) where {-# INLINE nonFirst #-} nonFirst c = isAlpha_ascii c ∨ + isDigit c ∨ c ≡ '+' ∨ c ≡ '-' ∨ c ≡ '.' {-# INLINE fromBS #-} fromBS = Scheme ∘ A.toCIAscii ∘ A.unsafeFromByteString +-- |Extract a 'CIAscii' with all letters lowercased. instance ConvertSuccess Scheme CIAscii where {-# INLINE convertSuccess #-} - convertSuccess (Scheme s) = s + convertSuccess (Scheme s) = foldCase s +-- |Create an 'AsciiBuilder' with all letters lowercased. +instance ConvertSuccess Scheme AsciiBuilder where + {-# INLINE convertSuccess #-} + convertSuccess = A.toAsciiBuilder ∘ A.fromCIAscii ∘ cs + +-- |Try to parse a 'Scheme' from 'CIAscii'. 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 |]) ]