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


The following commit has been merged in the master branch:
commit 6d61f0d555df0e6d328294bea10776f70f7f5219
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Oct 5 08:17:13 2004 +0100

    Initial version
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-1)

diff --git a/MissingH/Strutil.hs b/MissingH/Strutil.hs
new file mode 100644
index 0000000..4878499
--- /dev/null
+++ b/MissingH/Strutil.hs
@@ -0,0 +1,45 @@
+{- arch-tag: String utilities main file
+Copyright (C) 2004 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
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+module Strutil(strip, lstrip, rstrip) where
+
+-- | This module provides various helpful utilities for dealing with strings.
+-- John Goerzen <jgoerzen at complete.org>
+
+-- * Whitespace removal
+
+-- | Removes any whitespace characters that are present at the start or end of a string. Does not alter the internal contents of a string. If no whitespace characters are present at the start or end of a string, returns the original string unmodified. Safe to use on any string. 
+--
+-- | Note that this may differ from some other similar functions from other authors in that: 
+--
+-- 1. If multiple whitespace characters are present all in a row, they are all removed; 
+--
+-- 2. If no whitespace characters are present, nothing is done.
+
+strip :: String -> String
+strip = lstrip . rstrip
+
+-- | Same as strip, but applies only to the left side of the string.
+lstrip s = case s of
+                  [] -> []
+                  (x:xs) -> if elem x wschars
+                            then lstrip xs
+                            else s
+
+-- | Same as strip, but applies only to the right side of the string.
+rstrip s = reverse . lstrip . reverse

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list