on master help sign in
Get rid of splitChar.

--HG-- extra : convert_revision : f32b03e68f86a748b2b62f1659aeff9e9b3711e5

commit419bade871dd8ac0b05710c68c03e5de8d6e26f0 authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Aug 2009, 05:20 (17 years ago) parentc0479ba
3 files changed+10−21
Data/Text.hs+8−18 Data/Text/Compat.hs+2−1 tests/Properties.hs−2
Data/Text.hs+8−18
@@ -125,7 +125,6 @@ module Data.Text
125125 , split
126126 , splitTimes
127127 , splitTimesEnd
128− , splitChar
129128 , splitWith
130129 , chunksOf
131130
@@ -882,21 +881,6 @@ tails :: Text -> [Text]
882881tails t | null t = [empty]
883882 | otherwise = t : tails (unsafeTail t)
884883
885−-- | /O(n)/ Break a 'Text' into pieces separated by the 'Char'
886−-- argument, consuming the delimiter. I.e.
887−--
888−-- > splitChar '\n' "a\nb\nd\ne" == ["a","b","d","e"]
889−-- > splitChar 'a' "aXaXaXa" == ["","X","X","X",""]
890−-- > splitChar 'x' "x" == ["",""]
891−--
892−-- and
893−--
894−-- > intercalate (singleton c) . splitChar c == id
895−-- > splitChar == splitWith . (==)
896−splitChar :: Char -> Text -> [Text]
897−splitChar c = splitWith (==c)
898−{-# INLINE splitChar #-}
899−
900884-- $split
901885--
902886-- Splitting functions in this library do not perform character-wise
@@ -918,16 +902,22 @@ split :: Text -- ^ Text to split on
918902 -> [Text]
919903split pat src0
920904 | l == 0 = [src0]
905+ | l == 1 = splitWith (== (head pat)) src0
921906 | otherwise = go src0
922907 where
923− l = length pat
908+ l = length pat
924909 go src = search 0 src
925910 where
926911 search !n !s
927912 | null s = [src] -- not found
928913 | pat `isPrefixOf` s = take n src : go (drop l s)
929914 | otherwise = search (n+1) (unsafeTail s)
930−{-# INLINE split #-}
915+{-# INLINE [1] split #-}
916+
917+{-# RULES
918+"TEXT split/singleton -> splitWith/==" [~1] forall c t.
919+ split (singleton c) t = splitWith (==c) t
920+ #-}
931921
932922-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
933923-- treating the first 'Text' argument as the delimiter to break on,
Data/Text/Compat.hs+2−1
@@ -145,11 +145,12 @@ module Data.Text.Compat
145145
146146import Data.ByteString (ByteString)
147147import Data.Text hiding (split)
148+import qualified Data.Text as T
148149import Data.Text.Unsafe (unsafeTail)
149150import Prelude (Char, (+), otherwise)
150151
151152split :: Char -> Text -> [Text]
152−split = splitChar
153+split c = T.split (singleton c)
153154{-# INLINE split #-}
154155
155156-- | /O(n)/ Break a string on a substring, returning a pair of the
tests/Properties.hs−2
@@ -301,7 +301,6 @@ prop_TL_tails = L.tails `eqP` (map unpackS . TL.tails)
301301prop_T_split_i t = id `eq` (T.intercalate t . T.split t)
302302prop_T_splitTimes_i k t= id `eq` (T.intercalate t . T.splitTimes k t)
303303prop_T_splitTimesEnd_i k t = id `eq` (T.intercalate t . T.splitTimesEnd k t)
304−prop_T_splitChar_i c = id `eq` (T.intercalate (T.singleton c) . T.splitChar c)
305304prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
306305
307306prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
@@ -567,7 +566,6 @@ tests = [
567566 ("prop_T_split_i", mytest prop_T_split_i),
568567 ("prop_T_splitTimes_i", mytest prop_T_splitTimes_i),
569568 ("prop_T_splitTimesEnd_i", mytest prop_T_splitTimesEnd_i),
570− ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
571569 ("prop_TL_split_i", mytest prop_TL_split_i),
572570 ("prop_T_splitWith", mytest prop_T_splitWith),
573571 ("prop_T_splitWith_split", mytest prop_T_splitWith_split),