[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 15:07:40 UTC 2010


The following commit has been merged in the master branch:
commit e0b2243eec89b73ec925bea0d62a675d37568c23
Author: John Goerzen <jgoerzen at complete.org>
Date:   Wed Apr 5 02:31:05 2006 +0100

    New function splitWs

diff --git a/MissingH/Str.hs b/MissingH/Str.hs
index ae49a37..a30419c 100644
--- a/MissingH/Str.hs
+++ b/MissingH/Str.hs
@@ -1,5 +1,5 @@
 {- arch-tag: String utilities main file
-Copyright (C) 2004-2005 John Goerzen <jgoerzen at complete.org>
+Copyright (C) 2004-2006 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and\/or modify
 it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 {- |
    Module     : MissingH.Str
-   Copyright  : Copyright (C) 2004-2005 John Goerzen
+   Copyright  : Copyright (C) 2004-2006 John Goerzen
    License    : GNU GPL, version 2 or above
 
    Maintainer : John Goerzen <jgoerzen at complete.org>
@@ -32,7 +32,7 @@ Written by John Goerzen, jgoerzen\@complete.org
 
 module MissingH.Str
                        (-- * Whitespace Removal
-                        strip, lstrip, rstrip,
+                        strip, lstrip, rstrip
                         -- * Tests
                         -- | Note: These functions are aliases for functions
                         -- in "MissingH.List".
@@ -40,7 +40,7 @@ module MissingH.Str
                         -- * Conversions
                         -- | Note: Some of these functions are aliases for functions
                         -- in "MissingH.List".
-                        join, split, splitRe, replace, subRe
+                        join, split, splitWs, splitRe, replace, subRe
                        ) where
 import MissingH.List(startswith, endswith, join, split, replace)
 import Text.Regex
@@ -105,3 +105,8 @@ as Text.Regex.splitRegex and is thus deprecated in MissingH.
 
 splitRe :: Regex -> String -> [String]
 splitRe = splitRegex
+
+{- | Splits a string around whitespace.  Empty elements in the result
+list are automatically removed. -}
+splitWs :: String -> [String]
+splitWs = filter (\x -> x /= []) . splitRegex (mkRegex "[ \t\n\r\v\f]+")
diff --git a/testsrc/Strtest.hs b/testsrc/Strtest.hs
index 3687e59..d5b1559 100644
--- a/testsrc/Strtest.hs
+++ b/testsrc/Strtest.hs
@@ -51,6 +51,16 @@ test_strip =
                     ("\nbas", "bas"),
                     ("abc def", "abc def")]
 
+test_splitWs =
+    let f inp exp = TestCase $ exp @=? splitWs inp
+        in [
+            f [] "    ",
+            f [] "",
+            f ["asdf"] " asdf\n",
+            f ["one", "two", "three"] "  one\ntwo \tthree \n"
+           ]
+
+
 test_splitRe =
     let f re inp exp = TestCase $ exp @=? splitRe (mkRegex re) inp
         in [
@@ -76,6 +86,7 @@ test_subRe =
 tests = TestList [TestLabel "lstrip" (TestList test_lstrip),
                   TestLabel "rstrip" $ TestList test_rstrip,
                   TestLabel "strip" $ TestList test_strip,
+                  TestLabel "splitWs" $ TestList test_splitWs,
                   TestLabel "subRe" $ TestList test_subRe,
                   TestLabel "splitRe" $ TestList test_splitRe
                   ]

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list