[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:42:25 UTC 2010


The following commit has been merged in the master branch:
commit e45c5ba2cc6ac861a021c1ae51f827059a2be2e0
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Oct 5 20:19:28 2004 +0100

    Doesn't handle ending delim right
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-9)

diff --git a/MissingH/Strutil.hs b/MissingH/Strutil.hs
index 0c9b927..b0f1230 100644
--- a/MissingH/Strutil.hs
+++ b/MissingH/Strutil.hs
@@ -26,7 +26,9 @@ module MissingH.Strutil(-- * Whitespace Removal
                         -- * Tests
                         -- | Note: These functions are aliases for functions
                         -- in "MissingH.Listutil".
-                        startswith, endswith
+                        startswith, endswith,
+                        -- * Conversions
+                        split
                        ) where
 import MissingH.Listutil(startswith, endswith)
 
@@ -63,3 +65,20 @@ lstrip s = case s of
 rstrip :: String -> String
 rstrip = reverse . lstrip . reverse
 
+{- | Given a delimiter and a list (or string), split into components.
+
+Example:
+
+> split "," "foo,bar,,baz" -> ["foo", "bar", "", "baz"]
+-}
+split :: String -> String -> [String]
+split delim str =
+    let splitworker :: String -> String -> String -> [String]
+        splitworker delim [] [] = []
+        splitworker delim [] accum = [accum]
+        splitworker delim str accum =
+            if startswith delim str then
+               accum : splitworker delim (drop (length delim) str) []
+            else splitworker delim (tail str) (accum ++ [head str])
+        in
+        splitworker delim str []

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list