~music-clockwork/resonate/mixes

« back to all changes in this revision

Viewing changes to daemons/String.hs

  • Committer: Brian Kassouf
  • Date: 2009-05-04 19:24:30 UTC
  • mfrom: (615.2.28 resonate)
  • Revision ID: brian@brian-laptop-20090504192430-d99ollvz4nrfkz27
pulled in the new revisions from trunk branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module String (trim, substitute)
 
2
    where
 
3
 
 
4
import Data.Char (isSpace)
 
5
import Data.List (isPrefixOf)
 
6
 
 
7
trim :: String -> String
 
8
trim s = reverse $ ltrim $ reverse $ ltrim s
 
9
    where ltrim s2 = dropWhile isSpace s2
 
10
 
 
11
substitute :: String -> String -> String -> String
 
12
substitute _    _  [       ] = []
 
13
substitute from to xs@(a:as) =
 
14
    if isPrefixOf from xs
 
15
        then to ++ substitute from to (drop (length from) xs)
 
16
        else a : substitute from to as