on master help sign in
Remove splitTimesEnd.

--HG-- extra : convert_revision : de998348b88b4a67d361d24f715b51efbd34f1f0

commite12e119fec9bb732b51d57a8e7050d8837f4adf8 authorBryan O'Sullivan <bos@serpentine.com> dateTue 6 Oct 2009, 21:57 (17 years ago) parent63659ec
2 files changed+3−65
Data/Text.hs−53 tests/Properties.hs+3−12
Data/Text.hs−53
@@ -125,7 +125,6 @@ module Data.Text
125125 -- ** Breaking into many substrings
126126 -- $split
127127 , split
128− , splitTimesEnd
129128 , splitBy
130129 , chunksOf
131130
@@ -933,58 +932,6 @@ split pat@(Text _ _ l) src@(Text arr off len)
933932 split (singleton c) t = splitBy (==c) t
934933 #-}
935934
936−-- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times,
937−-- treating the first 'Text' argument as the delimiter to break on,
938−-- and consuming the delimiter. The last element of the list contains
939−-- the remaining text after the number of times to split has been
940−-- reached. A value of zero or less for @k@ causes no splitting to
941−-- occur. An empty delimiter is invalid, and will cause an error to be
942−-- raised.
943−--
944−-- Examples:
945−--
946−-- > splitTimes 0 "//" "a//b//c" == ["a//b//c"]
947−-- > splitTimes 2 ":" "a:b:c:d:e" == ["a","b","c:d:e"]
948−-- > splitTimes 100 "???" "a????b" == ["a","?b"]
949−--
950−-- and
951−--
952−-- > intercalate s . splitTimes k s == id
953−--
954−-- In (unlikely) bad cases, this function's time complexity
955−-- degenerates towards /O(n*m)/.
956−splitTimes :: Int -- ^ Maximum number of times to split
957− -> Text -- ^ Text to split on
958− -> Text -- ^ Input text
959− -> [Text]
960−splitTimes k pat@(Text _ _ l) src@(Text arr off len)
961− | l <= 0 = emptyError "splitTimes"
962− | otherwise = go 0 0 (indices pat src)
963− where
964− go !s !i _ | i >= k = [textP arr (s+off) (len-s)]
965− go !s _ [] = [textP arr (s+off) (len-s)]
966− go !s !i (x:xs) = textP arr (s+off) (x-s) : go (x+l) (i+1) xs
967−{-# INLINE splitTimes #-}
968−
969−-- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times, like
970−-- 'splitTimes', but start from the end of the input and work towards
971−-- the start.
972−--
973−-- Examples:
974−--
975−-- > splitTimes 2 "::" "a::b::c::d::e" == ["a","b","c::d::e"]
976−-- > splitTimesEnd 2 "::" "a::b::c::d::e" == ["a::b::c","d","e"]
977−--
978−-- In (unlikely) bad cases, this function's time complexity
979−-- degenerates towards /O(n*m)/.
980−splitTimesEnd :: Int -- ^ Maximum number of times to split
981− -> Text -- ^ Text to split on
982− -> Text -- ^ Input text
983− -> [Text]
984−splitTimesEnd k pat src =
985− L.reverse . L.map reverse $ splitTimes k (reverse pat) (reverse src)
986−{-# INLINE splitTimesEnd #-}
987−
988935-- | /O(n)/ Splits a 'Text' into components delimited by separators,
989936-- where the predicate returns True for a separator element. The
990937-- resulting components do not contain the separators. Two adjacent
tests/Properties.hs+3−12
@@ -402,17 +402,12 @@ tl_inits = L.inits `eqP` (map unpackS . TL.inits)
402402t_tails = L.tails `eqP` (map unpackS . T.tails)
403403tl_tails = L.tails `eqP` (map unpackS . TL.tails)
404404
405−findSplit s t = case T.find s t of
406− (x,xs) -> x : L.map (T.drop (T.length s) . fst) xs
407−
408−t_findSplit s = T.split s `eq` findSplit s
405+t_findSplit s = T.split s `eq` splitty
406+ where splitty t = case T.find s t of
407+ (x,xs) -> x : L.map (T.drop (T.length s) . fst) xs
409408t_split_split s = T.split s `eq` Slow.split s
410409t_split_i (NotEmpty t) = id `eq` (T.intercalate t . T.split t)
411410tl_split_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.split t)
412−t_splitTimesEnd_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimesEnd k t)
413−tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
414−t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
415−tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
416411
417412t_splitBy p = splitBy p `eqP` (map unpackS . T.splitBy p)
418413t_splitBy_count c = (L.length . T.splitBy (==c)) `eq` ((1+) . T.count (T.singleton c))
@@ -791,10 +786,6 @@ tests = [
791786 testProperty "t_findSplit" t_findSplit,
792787 testProperty "t_split_split" t_split_split,
793788 testProperty "t_split_i" t_split_i,
794− testProperty "t_splitTimesEnd_i" t_splitTimesEnd_i,
795− testProperty "tl_splitTimesEnd_i" tl_splitTimesEnd_i,
796− testProperty "t_splitTimesEnd_split" t_splitTimesEnd_split,
797− testProperty "tl_splitTimesEnd_split" tl_splitTimesEnd_split,
798789 testProperty "tl_split_i" tl_split_i,
799790 testProperty "t_splitBy" t_splitBy,
800791 testProperty "t_splitBy_count" t_splitBy_count,