git.iko.soy/typeable/attoparsec
on master help sign in
Fix an incorrect indexing bug in Text.string

Found by Michel Boucey.

commite3791b4e822121148a2b99dbaf8daad41b7c6254 authorBryan O'Sullivan <bos@serpentine.com> dateSat 28 Mar 2015, 11:24 (12 years ago) parentf516036
2 files changed+7−1
Data/Attoparsec/Text/Buffer.hs+6 Data/Attoparsec/Text/Internal.hs+1−1
Data/Attoparsec/Text/Buffer.hs+6
@@ -28,6 +28,7 @@ module Data.Attoparsec.Text.Buffer
2828 Buffer
2929 , buffer
3030 , unbuffer
31+ , unbufferAt
3132 , length
3233 , pappend
3334 , iter
@@ -74,6 +75,11 @@ buffer (Text arr off len) = Buf arr off len len 0
7475unbuffer :: Buffer -> Text
7576unbuffer (Buf arr off len _ _) = Text arr off len
7677
78+unbufferAt :: Int -> Buffer -> Text
79+unbufferAt s (Buf arr off len _ _) =
80+ assert (s >= 0 && s <= len) $
81+ Text arr (off+s) (len-s)
82+
7783instance Monoid Buffer where
7884 mempty = Buf A.empty 0 0 0 0
7985
Data/Attoparsec/Text/Internal.hs+1−1
@@ -169,7 +169,7 @@ string_ :: (forall r. Text -> Text -> Buffer -> Pos -> More
169169 -> Text -> Parser Text
170170string_ suspended f s0 = T.Parser $ \t pos more lose succ ->
171171 let s = f s0
172− ft = f (Buf.unbuffer t)
172+ ft = f (Buf.unbufferAt (fromPos pos) t)
173173 in case T.commonPrefixes s ft of
174174 Nothing
175175 | T.null s -> succ t pos more T.empty