git.iko.soy/typeable/attoparsec
on master help sign in
Get asciiCI working
commit6350d7d3a446548f72d2282d3c55a4f82e814adc authorBryan O'Sullivan <bos@serpentine.com> dateFri 27 Mar 2015, 21:41 (12 years ago) parentf125009
1 file changed+3−10
Data/Attoparsec/Text/Internal.hs+3−10
Data/Attoparsec/Text/Internal.hs+3−10
@@ -175,7 +175,8 @@ string_ suspended f s0 = T.Parser $ \t pos more lose succ ->
175175 | T.null ft -> suspended s s t pos more lose succ
176176 | otherwise -> lose t pos more [] "string"
177177 Just (pfx,ssfx,tsfx)
178− | T.null ssfx -> succ t (pos + Pos (T.lengthWord16 pfx)) more pfx
178+ | T.null ssfx -> let l = Pos (T.lengthWord16 pfx)
179+ in succ t (pos + l) more (substring pos l t)
179180 | not (T.null tsfx) -> lose t pos more [] "string"
180181 | otherwise -> suspended s ssfx t pos more lose succ
181182{-# INLINE string_ #-}
@@ -220,16 +221,8 @@ stringCI s = go 0
220221
221222-- | Satisfy a literal string, ignoring case for characters in the ASCII range.
222223asciiCI :: Text -> Parser Text
223−asciiCI input = do
224− (k,t) <- ensure n
225− if asciiToLower t == s
226− then advance k >> return t
227− else fail "asciiCI"
224+asciiCI s = string_ (stringSuspended asciiToLower) asciiToLower s
228225 where
229− n = T.length input
230− s = asciiToLower input
231−
232− -- convert letters in the ASCII range to lower-case
233226 asciiToLower = T.map f
234227 where
235228 offset = ord 'a' - ord 'A'