From bd4ef01b210b38426145503c388e5a8ec21e3755 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 18 Apr 2026 23:04:12 +0800 Subject: [PATCH] Fix compatibility with text < 2.1 --- src/Data/Bytes/Parser/Ascii.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Data/Bytes/Parser/Ascii.hs b/src/Data/Bytes/Parser/Ascii.hs index a213740..79729ce 100644 --- a/src/Data/Bytes/Parser/Ascii.hs +++ b/src/Data/Bytes/Parser/Ascii.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE BinaryLiterals #-} {-# LANGUAGE DataKinds #-} @@ -71,6 +72,10 @@ import qualified Data.Bytes.Parser as Parser import qualified Data.Bytes.Parser.Latin as Latin import qualified Data.Bytes.Parser.Unsafe as Unsafe import qualified Data.Primitive as PM +#if !MIN_VERSION_text(2, 1, 0) +import qualified Data.Array.Byte as BA +import qualified Data.Text.Array as T +#endif import qualified Data.Text.Short.Unsafe as TS {- | Consume the next character, failing if it does not match the expected @@ -110,10 +115,18 @@ skipTrailedBy e !c = do take :: e -> Int -> Parser e s Text {-# INLINE take #-} take e !n = do +#if MIN_VERSION_text(2, 1, 0) bs@(Bytes arr off len) <- Parser.take e n if Bytes.all (\w -> w < 128) bs then pure (Text arr off len) else Parser.fail e +#else + bs@(Bytes (BA.ByteArray arr) off len) <- Parser.take e n + if Bytes.all (\w -> w < 128) bs + then pure (Text (T.ByteArray arr) off len) + else Parser.fail e +#endif + {- | Consume characters matching the predicate. The stops when it encounters a non-matching character or when it encounters a byte