git.iko.soy/typeable/attoparsec
on master help sign in
Check for empty string.
commitdc9ccb1dce39143ed9f7e15e69d32e8705b00776 authorBryan O'Sullivan <bos@serpentine.com> dateTue 6 Jan 2009, 10:44 (18 years ago) parent173d2e5
1 file changed+10−8
src/Data/ParserCombinators/Attoparsec/Internal.hs+10−8
src/Data/ParserCombinators/Attoparsec/Internal.hs+10−8
@@ -226,14 +226,16 @@ string s = Parser $ \(S sb lb n) ->
226226endOfLine :: Parser ()
227227endOfLine = Parser $ \(S sb lb n) ->
228228 let bs = sb +: lb
229− in case I.w2c (U.unsafeHead sb) of
230− '\n' -> Right ((), mkState (LB.tail bs) (n + 1))
231− '\r' -> let (h,t) = LB.splitAt 2 bs
232− rn = L8.pack "\r\n"
233− in if h == rn
234− then Right ((), mkState t (n + 2))
235− else Right ((), mkState (LB.tail bs) (n + 1))
236− _ -> Left (bs, ["EOL"])
229+ in if SB.null sb
230+ then Left (bs, ["EOL"])
231+ else case I.w2c (U.unsafeHead sb) of
232+ '\n' -> Right ((), mkState (LB.tail bs) (n + 1))
233+ '\r' -> let (h,t) = LB.splitAt 2 bs
234+ rn = L8.pack "\r\n"
235+ in if h == rn
236+ then Right ((), mkState t (n + 2))
237+ else Right ((), mkState (LB.tail bs) (n + 1))
238+ _ -> Left (bs, ["EOL"])
237239
238240-- | Satisfy a literal string, after applying a transformation to both
239241-- it and the matching text.