summaryrefslogtreecommitdiff
path: root/Data/Attoparsec/Text
diff options
context:
space:
mode:
Diffstat (limited to 'Data/Attoparsec/Text')
-rw-r--r--Data/Attoparsec/Text/Internal.hs17
1 files changed, 9 insertions, 8 deletions
diff --git a/Data/Attoparsec/Text/Internal.hs b/Data/Attoparsec/Text/Internal.hs
index 185bc20..2391fbb 100644
--- a/Data/Attoparsec/Text/Internal.hs
+++ b/Data/Attoparsec/Text/Internal.hs
@@ -75,7 +75,7 @@ import Data.Attoparsec.Internal
import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
import qualified Data.Attoparsec.Text.Buffer as Buf
import Data.Attoparsec.Text.Buffer (Buffer, buffer)
-import Data.Char (chr, ord)
+import Data.Char (isAsciiUpper, isAsciiLower, toUpper, toLower)
import Data.List (intercalate)
import Data.String (IsString(..))
import Data.Text.Internal (Text(..))
@@ -225,15 +225,16 @@ stringCI s = go 0
-- | Satisfy a literal string, ignoring case for characters in the ASCII range.
asciiCI :: Text -> Parser Text
-asciiCI s = string_ (stringSuspended asciiToLower) asciiToLower s
- where
- asciiToLower = T.map f
- where
- offset = ord 'a' - ord 'A'
- f c | 'A' <= c && c <= 'Z' = chr (ord c + offset)
- | otherwise = c
+asciiCI s = fmap fst $ match $ T.foldr ((*>) . asciiCharCI) (pure ()) s
{-# INLINE asciiCI #-}
+asciiCharCI :: Char -> Parser Char
+asciiCharCI c
+ | isAsciiUpper c = char c <|> char (toLower c)
+ | isAsciiLower c = char c <|> char (toUpper c)
+ | otherwise = char c
+{-# INLINE asciiCharCI #-}
+
-- | Skip past input for as long as the predicate returns 'True'.
skipWhile :: (Char -> Bool) -> Parser ()
skipWhile p = go