on master help sign in
Get rid of splitChar.
419badeBryan O'Sullivan
Data/Text.hs+8−18
@@ -125,7 +125,6 @@ module Data.Text
125 , split
125 , split
126 , splitTimes
126 , splitTimes
127 , splitTimesEnd
127 , splitTimesEnd
128− , splitChar
129 , splitWith
128 , splitWith
130 , chunksOf
129 , chunksOf
131
130
@@ -882,21 +881,6 @@ tails :: Text -> [Text]
882tails t | null t = [empty]
881tails t | null t = [empty]
883 | otherwise = t : tails (unsafeTail t)
882 | otherwise = t : tails (unsafeTail t)
884
883
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−
900-- $split
884-- $split
901--
885--
902-- Splitting functions in this library do not perform character-wise
886-- Splitting functions in this library do not perform character-wise
@@ -918,16 +902,22 @@ split :: Text -- ^ Text to split on
918 -> [Text]
902 -> [Text]
919split pat src0
903split pat src0
920 | l == 0 = [src0]
904 | l == 0 = [src0]
905+ | l == 1 = splitWith (== (head pat)) src0
921 | otherwise = go src0
906 | otherwise = go src0
922 where
907 where
923− l = length pat
908+ l = length pat
924 go src = search 0 src
909 go src = search 0 src
925 where
910 where
926 search !n !s
911 search !n !s
927 | null s = [src] -- not found
912 | null s = [src] -- not found
928 | pat `isPrefixOf` s = take n src : go (drop l s)
913 | pat `isPrefixOf` s = take n src : go (drop l s)
929 | otherwise = search (n+1) (unsafeTail s)
914 | 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+ #-}
931
921
932-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
922-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
933-- treating the first 'Text' argument as the delimiter to break on,
923-- 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
145
145
146import Data.ByteString (ByteString)
146import Data.ByteString (ByteString)
147import Data.Text hiding (split)
147import Data.Text hiding (split)
148+import qualified Data.Text as T
148import Data.Text.Unsafe (unsafeTail)
149import Data.Text.Unsafe (unsafeTail)
149import Prelude (Char, (+), otherwise)
150import Prelude (Char, (+), otherwise)
150
151
151split :: Char -> Text -> [Text]
152split :: Char -> Text -> [Text]
152−split = splitChar
153+split c = T.split (singleton c)
153{-# INLINE split #-}
154{-# INLINE split #-}
154
155
155-- | /O(n)/ Break a string on a substring, returning a pair of the
156-- | /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)
301prop_T_split_i t = id `eq` (T.intercalate t . T.split t)
301prop_T_split_i t = id `eq` (T.intercalate t . T.split t)
302prop_T_splitTimes_i k t= id `eq` (T.intercalate t . T.splitTimes k t)
302prop_T_splitTimes_i k t= id `eq` (T.intercalate t . T.splitTimes k t)
303prop_T_splitTimesEnd_i k t = id `eq` (T.intercalate t . T.splitTimesEnd k t)
303prop_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)
305prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
304prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
306
305
307prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
306prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
@@ -567,7 +566,6 @@ tests = [
567 ("prop_T_split_i", mytest prop_T_split_i),
566 ("prop_T_split_i", mytest prop_T_split_i),
568 ("prop_T_splitTimes_i", mytest prop_T_splitTimes_i),
567 ("prop_T_splitTimes_i", mytest prop_T_splitTimes_i),
569 ("prop_T_splitTimesEnd_i", mytest prop_T_splitTimesEnd_i),
568 ("prop_T_splitTimesEnd_i", mytest prop_T_splitTimesEnd_i),
570− ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
571 ("prop_TL_split_i", mytest prop_TL_split_i),
569 ("prop_TL_split_i", mytest prop_TL_split_i),
572 ("prop_T_splitWith", mytest prop_T_splitWith),
570 ("prop_T_splitWith", mytest prop_T_splitWith),
573 ("prop_T_splitWith_split", mytest prop_T_splitWith_split),
571 ("prop_T_splitWith_split", mytest prop_T_splitWith_split),