@@ -115,7 +115,7 @@ module Data.Text
115115 , unwords
116116
117117 -- * Predicates
118− -- , isPrefixOf
118+ , isPrefixOf
119119 -- , isSuffixOf
120120 -- , isInfixOf
121121
@@ -143,7 +143,7 @@ module Data.Text
143143 , -- sort
144144 ) where
145145
146−import Prelude (Char, Bool, Functor(..), Int, Maybe(..), String,
146+import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
147147 Eq, (==), (++), error,
148148 Read(..), Show(..),
149149 (&&), (||), (+), (-), (<), (>), (<=), (>=), (.), ($),
@@ -836,5 +836,14 @@ unwords :: [Text] -> Text
836836unwords = intercalate (singleton ' ')
837837{-# INLINE unwords #-}
838838
839+isPrefixOf :: Text -> Text -> Bool
840+isPrefixOf a@(Text _ _ alen) b@(Text _ _ blen) = alen <= blen && loop 0 0
841+ where loop !i !j | i >= alen = True
842+ | c == e = loop (i+d) (j+f)
843+ | otherwise = False
844+ where (c,d) = iter a i
845+ (e,f) = iter b j
846+{-# INLINE [1] isPrefixOf #-}
847+
839848errorEmptyList :: String -> a
840849errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")