Bryan O'Sullivan avatar Bryan O'Sullivan committed 21cf079

Remove splitTimesEnd.

Comments (0)

Files changed (2)

     -- ** Breaking into many substrings
     -- $split
     , split
-    , splitTimesEnd
     , splitBy
     , chunksOf
 
     split (singleton c) t = splitBy (==c) t
   #-}
 
--- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times,
--- treating the first 'Text' argument as the delimiter to break on,
--- and consuming the delimiter.  The last element of the list contains
--- the remaining text after the number of times to split has been
--- reached.  A value of zero or less for @k@ causes no splitting to
--- occur. An empty delimiter is invalid, and will cause an error to be
--- raised.
---
--- Examples:
---
--- > splitTimes 0   "//"  "a//b//c"   == ["a//b//c"]
--- > splitTimes 2   ":"   "a:b:c:d:e" == ["a","b","c:d:e"]
--- > splitTimes 100 "???" "a????b"    == ["a","?b"]
---
--- and
---
--- > intercalate s . splitTimes k s   == id
---
--- In (unlikely) bad cases, this function's time complexity
--- degenerates towards /O(n*m)/.
-splitTimes :: Int               -- ^ Maximum number of times to split
-           -> Text              -- ^ Text to split on
-           -> Text              -- ^ Input text
-           -> [Text]
-splitTimes k pat@(Text _ _ l) src@(Text arr off len)
-    | l <= 0    = emptyError "splitTimes"
-    | otherwise = go 0 0 (indices pat src)
-  where
-    go !s !i _  | i >= k = [textP arr (s+off) (len-s)]
-    go !s  _ []          = [textP arr (s+off) (len-s)]
-    go !s !i (x:xs)      =  textP arr (s+off) (x-s) : go (x+l) (i+1) xs
-{-# INLINE splitTimes #-}
-
--- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times, like
--- 'splitTimes', but start from the end of the input and work towards
--- the start.
---
--- Examples:
---
--- > splitTimes 2    "::" "a::b::c::d::e" == ["a","b","c::d::e"]
--- > splitTimesEnd 2 "::" "a::b::c::d::e" == ["a::b::c","d","e"]
---
--- In (unlikely) bad cases, this function's time complexity
--- degenerates towards /O(n*m)/.
-splitTimesEnd :: Int               -- ^ Maximum number of times to split
-              -> Text              -- ^ Text to split on
-              -> Text              -- ^ Input text
-              -> [Text]
-splitTimesEnd k pat src =
-    L.reverse . L.map reverse $ splitTimes k (reverse pat) (reverse src)
-{-# INLINE splitTimesEnd #-}
-
 -- | /O(n)/ Splits a 'Text' into components delimited by separators,
 -- where the predicate returns True for a separator element.  The
 -- resulting components do not contain the separators.  Two adjacent

tests/Properties.hs

 t_tails           = L.tails       `eqP` (map unpackS . T.tails)
 tl_tails          = L.tails       `eqP` (map unpackS . TL.tails)
 
-findSplit s t = case T.find s t of
-                  (x,xs) -> x : L.map (T.drop (T.length s) . fst) xs
-
-t_findSplit s           = T.split s `eq` findSplit s
+t_findSplit s           = T.split s `eq` splitty
+  where splitty t       = case T.find s t of
+                            (x,xs) -> x : L.map (T.drop (T.length s) . fst) xs
 t_split_split s         = T.split s `eq` Slow.split s
 t_split_i (NotEmpty t)  = id `eq` (T.intercalate t . T.split t)
 tl_split_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.split t)
-t_splitTimesEnd_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimesEnd k t)
-tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
-t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
-tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
 
 t_splitBy p       = splitBy p `eqP` (map unpackS . T.splitBy p)
 t_splitBy_count c = (L.length . T.splitBy (==c)) `eq` ((1+) . T.count (T.singleton c))
       testProperty "t_findSplit" t_findSplit,
       testProperty "t_split_split" t_split_split,
       testProperty "t_split_i" t_split_i,
-      testProperty "t_splitTimesEnd_i" t_splitTimesEnd_i,
-      testProperty "tl_splitTimesEnd_i" tl_splitTimesEnd_i,
-      testProperty "t_splitTimesEnd_split" t_splitTimesEnd_split,
-      testProperty "tl_splitTimesEnd_split" tl_splitTimesEnd_split,
       testProperty "tl_split_i" tl_split_i,
       testProperty "t_splitBy" t_splitBy,
       testProperty "t_splitBy_count" t_splitBy_count,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.