Commits

Bryan O'Sullivan committed c734f61

Implement and test lazy isSuffixOf

  • Participants
  • Parent commits bc0b974

Comments (0)

Files changed (2)

Data/Text/Lazy.hs

 
     -- * Predicates
     , isPrefixOf
-    -- , isSuffixOf
+    , isSuffixOf
     -- , isInfixOf
 
     -- * Searching
     S.isPrefixOf (stream s) (stream t) = isPrefixOf s t
   #-}
 
+-- | /O(n)/ The 'isSuffixOf' function takes two 'Text's and returns
+-- 'True' iff the first is a suffix of the second.
+isSuffixOf :: Text -> Text -> Bool
+isSuffixOf x y = reverse x `isPrefixOf` reverse y
+{-# INLINE isSuffixOf #-}
+-- TODO: a better implementation
+
 revChunks :: [T.Text] -> Text
 revChunks = L.foldl' (flip chunk) Empty
 

tests/Properties.hs

 prop_T_isPrefixOf s    = L.isPrefixOf s`eqP` T.isPrefixOf (packT s)
 prop_TL_isPrefixOf s   = L.isPrefixOf s`eqP` TL.isPrefixOf (packT s)
 prop_T_isSuffixOf s    = L.isSuffixOf s`eqP` T.isSuffixOf (packT s)
+prop_TL_isSuffixOf s   = L.isSuffixOf s`eqP` TL.isSuffixOf (packT s)
 prop_T_isInfixOf s     = L.isInfixOf s `eqP` T.isInfixOf (packT s)
 
 prop_T_elem c          = L.elem c      `eqP` T.elem c
   ("prop_T_isPrefixOf", mytest prop_T_isPrefixOf),
   ("prop_TL_isPrefixOf", mytest prop_TL_isPrefixOf),
   ("prop_T_isSuffixOf", mytest prop_T_isSuffixOf),
+  ("prop_TL_isSuffixOf", mytest prop_TL_isSuffixOf),
   ("prop_T_isInfixOf", mytest prop_T_isInfixOf),
 
   ("prop_T_elem", mytest prop_T_elem),