[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:45:28 UTC 2010


The following commit has been merged in the master branch:
commit 8d38314ccae131691b99b8777e81ebf4b5f6024e
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sat Oct 23 04:00:30 2004 +0100

    Added split/splitRE stuff
    
    Keywords:
    
    Rewrote split to be simpler.  Added takeWhileList, breakList, etc.
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-103)

diff --git a/ChangeLog b/ChangeLog
index b99d3d2..33e0bcf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,21 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-22 22:00:30 GMT	John Goerzen <jgoerzen at complete.org>	patch-103
+
+    Summary:
+      Added split/splitRE stuff
+    Revision:
+      missingh--head--1.0--patch-103
+
+    Rewrote split to be simpler.  Added takeWhileList, breakList, etc.
+
+    modified files:
+     ChangeLog libsrc/MissingH/List.hs
+     libsrc/MissingH/Network/FTP/Parser.hs libsrc/MissingH/Str.hs
+     notes.txt
+
+
 2004-10-22 20:53:53 GMT	John Goerzen <jgoerzen at complete.org>	patch-102
 
     Summary:
diff --git a/libsrc/MissingH/List.hs b/libsrc/MissingH/List.hs
index 781f821..d54f79e 100644
--- a/libsrc/MissingH/List.hs
+++ b/libsrc/MissingH/List.hs
@@ -40,7 +40,8 @@ module MissingH.List(-- * Tests
                      for association lists. -}
                      addToAL, delFromAL, flipAL,
                      -- * Conversions
-                     split, join, genericJoin,
+                     split, join, genericJoin, takeWhileList,
+                     dropWhileList, spanList, breakList,
                      -- * Miscellaneous
                      countElem, elemRIndex, alwaysElemRIndex
                      -- -- * Sub-List Selection
@@ -74,6 +75,38 @@ Example:
 endswith :: Eq a => [a] -> [a] -> Bool
 endswith = isSuffixOf
 
+{- | Similar to Data.List.takeWhile, takes elements while the func is true.
+The function is given the remainder of the list to examine. -}
+takeWhileList :: ([a] -> Bool) -> [a] -> [a]
+takeWhileList _ [] = []
+takeWhileList func list@(x:xs) =
+    if func list 
+       then x : takeWhileList func xs
+       else []
+
+{- | Similar to Data.List.dropWhile, drops elements while the func is true.
+The function is given the remainder of the list to examine. -}
+dropWhileList :: ([a] -> Bool) -> [a] -> [a]
+dropWhileList _ [] = []
+dropWhileList func list@(x:xs) =
+    if func list
+       then dropWhileList func xs
+       else list
+
+{- | Similar to Data.List.span, but performs the test on the entire remaining
+list instead of just one element. 
+
+ at spanList p xs@ is the same as @(takeWhileList p xs, dropWhileList p xs)@ 
+-}
+spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
+spanList p xs = (takeWhileList p xs, dropWhileList p xs)
+
+{- | Similar to Data.List.break, but performs the test on the entire remaining
+list instead of just one element.
+-}
+breakList :: ([a] -> Bool) -> [a] -> ([a], [a])
+breakList func = spanList (not . func)
+
 {- | Given a delimiter and a list (or string), split into components.
 
 Example:
@@ -83,18 +116,17 @@ Example:
 > split "ba" ",foo,bar,,baz," -> [",foo,","r,,","z,"]
 -}
 split :: Eq a => [a] -> [a] -> [[a]]
+split _ [] = []
 split delim str =
-    let splitworker :: Eq a => [a] -> [a] -> [a] -> [[a]]
-        splitworker delim [] [] = []
-        splitworker delim [] accum = [accum]
-        splitworker delim str accum =
-            if delim == str then 
-               accum : [] : []
-            else if startswith delim str then
-               accum : splitworker delim (drop (length delim) str) []
-            else splitworker delim (tail str) (accum ++ [head str])
-        in
-        splitworker delim str []
+    let (firstline, remainder) = breakList (startswith delim) str
+        in 
+        firstline : case remainder of
+                                   [] -> []
+                                   x -> if x == delim
+                                        then [] : []
+                                        else split delim 
+                                                 (drop (length delim) x)
+
 
 {- | Given a delimiter and a list of items (or strings), join the items
 by using the delimiter.
diff --git a/libsrc/MissingH/Network/FTP/Parser.hs b/libsrc/MissingH/Network/FTP/Parser.hs
index e3db642..7b26e29 100644
--- a/libsrc/MissingH/Network/FTP/Parser.hs
+++ b/libsrc/MissingH/Network/FTP/Parser.hs
@@ -157,7 +157,7 @@ parseGoodReply input =
 Example:
 
 > toPortString (SockAddrInet (PortNum 0x1234) (0xaabbccdd)) ->
-                              "170,187,204,221,18,52"
+>                              "170,187,204,221,18,52"
 -}
 toPortString :: SockAddr -> String
 toPortString (SockAddrInet (PortNum port) hostaddr) =
diff --git a/libsrc/MissingH/Str.hs b/libsrc/MissingH/Str.hs
index 2dfde68..6f879ad 100644
--- a/libsrc/MissingH/Str.hs
+++ b/libsrc/MissingH/Str.hs
@@ -81,6 +81,18 @@ rstrip = reverse . lstrip . reverse
 {-
 -- | Splits a string based on a regular expression.  The regular express
 -- should identify one delimiter.
+-}
+
+splitRe :: Regex -> String -> [String]
+splitRe _ [] = []
+splitRe delim str =
+    case matchRegexAll delim str of
+       Nothing -> [str]
+       Just (firstline, _, remainder, _) ->
+           if remainder == ""
+              then firstline : [] : []
+              else firstline : splitRe delim remainder
+{-
 
 splitRe :: Regex -> String -> [String]
 splitRe delim [] = []
diff --git a/notes.txt b/notes.txt
index 7b3c675..36eb581 100644
--- a/notes.txt
+++ b/notes.txt
@@ -1,3 +1,5 @@
+ see if splitre works
+ 
  basename p = reverse $ takeWhile (/= '/') $ reverse p
 
  dirname p  = case reverse $ dropWhile (/= '/') $ reverse p of

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list