% Halipeto -- Haskell static web page generator
% Copyright 2004 Andrew Cooke (firstname.lastname@example.org)
% Copyright 2007-2010 Peter Simons (email@example.com)
% 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
% Files in FromHaxml are from HaXml - http://www.cs.york.ac.uk/HaXml -
% see the COPYRIGHT and LICENSE in that directory. The files included
% are a subset of the full HaXml distribution and have been modified to
% originate from the FromHaxml module (so that install on Win32 is
Various general routines.
module Halipeto.Utilities (
slash, toSlash, fromSlash, toSep, fromSep, dropSpace,
Concatenation of paths and files.
slash' :: Char
slash' = '/'
%%Haddock: Concatenate two directories
slash :: String -> String -> String
slash p f = if null f || head f == slash' || null p || last p == slash'
then p ++ f
else p ++ [slash'] ++ f
%%Haddock: Convert a list of directories to a file path
toSlash :: [String] -> FilePath
toSlash = foldl slash ""
%%Haddock: Convert a file path to a list of directories
fromSlash :: FilePath -> [String]
fromSlash = fromSep slash'
Separation and expansion of strings.
%%Haddock: Join a list with a given separator character
toSep :: Char -> [String] -> String
toSep _  = undefined
toSep _ [s] = s
toSep sep (s:ss) = s ++ [sep] ++ toSep sep ss
%%Haddock: Split a list on a given separator character
fromSep :: Char -> String -> [String]
fromSep sep s' = uncurry (:) $ foldr f ("", ) s'
f c (s, l) | c == sep && l ==  && s == "" = ("", l)
| c == sep = ("", s:l)
| otherwise = (c:s, l)
Remove space from the start of a string.
%%Haddock: Drop leading spaces
dropSpace :: String -> String
dropSpace "" = ""
dropSpace (c:s) | isSpace c = dropSpace s
| otherwise = (c:s)
Maps over uniform tuples.
%%Haddock: Map over a uniform tuple
mapT2 :: (a -> b) -> (a, a) -> (b, b)
mapT2 f (x1, x2) = (f x1, f x2)
%%Haddock: Map over a uniform triple
mapT3 :: (a -> b) -> (a, a, a) -> (b, b, b)
mapT3 f (x1, x2, x3) = (f x1, f x2, f x3)
Chain functions that return Maybe.
%%Haddock: Chain Maybe functions
thenMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c)
thenMaybe f1 f2 a = case f1 a of
Nothing -> Nothing
Just a' -> f2 a'