diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2009-12-16 23:35:00 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2009-12-16 23:35:00 +0000 |
| commit | 98b3b673ddd3b860b6e78ee3acc7b36c05fcd357 (patch) | |
| tree | b5e08564d46c0dd342fd470d85852d6002ba667d /HsBot.hs | |
| parent | 2a3644123341049c854ea201ffa11cab2f68ec4a (diff) | |
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@11 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'HsBot.hs')
| -rw-r--r-- | HsBot.hs | 55 |
1 files changed, 31 insertions, 24 deletions
@@ -129,34 +129,41 @@ sort (x:xs) = sort (filter (>= x) xs) ++ [x] ++ sort (filter (< x) xs) split :: String -> Char -> [String] split [] delim = [""] -split (c:cs) delim | c == delim = "" : rest +split (c:cs) delim + | c == delim = "" : rest | otherwise = (c : head rest) : tail rest where rest = split cs delim --- Returns the string before and after the match -occurance :: String -> String -> Maybe (String, String) -occurance search str = o' "" search str - where o' pred [] str = Just (init . init $ reverse pred, str) - o' pred occurance [] = Nothing - o' pred (m:occurance) (s:str) - | m == s = o' (s:pred) occurance str - | otherwise = o' (s:pred) search str - +-- Returns a list of all strings to increase or decrease the karma of matches :: String -> String -> [String] -matches search string = case m' $ occurance search string of - (list, []) -> list - (list, rest) -> list ++ (matches search rest) - where extrL str - | last str == ' ' = [] - | otherwise = [last $ split str ' '] - extrR str - | str !! 0 == ' ' = [] - | otherwise = [split str ' ' !! 0] - m' (Just (a, "")) = (extrR a, "") - m' (Just ("", b)) = (extrR b, b) - m' (Just (a, b)) = ((extrL a) ++ (extrR b), b) - m' Nothing = ([], []) - +matches search string = + case m' $ occ search string of + (list, "") -> list + (list, rest) -> list ++ (matches search rest) + where occ :: String -> String -> Maybe (String, String) + occ search str = o' "" search str + where o' pred [] str = + Just (init . init $ reverse pred, str) + o' pred occ [] = Nothing + o' pred (m:occ) (s:str) + | m == s = o' (s:pred) occ str + | otherwise = o' (s:pred) search str + split' str = map (filter (\x -> (x /= '-') && (x /= '+'))) $ split str ' ' + extrL str + | last str == ' ' = [] + | otherwise = [last $ split' str] + extrR str + | str !! 0 == ' ' = [] + | otherwise = [split' str !! 0] + m' (Just (a, "")) = (extrL a, "") + m' (Just ("", b)) = (extrR b, b) + m' (Just (a, b)) = ((extrL a) ++ (extrR b), b) + m' Nothing = ([], []) + +test1 = matches "++" "++foo" +test2 = matches "++" "foo++" +test3 = matches "++" "++foo++" +test4 = matches "++" "++foo ++bar++ --baz++" processInput :: Conf -> Conf processInput conf = loggMessage "foo" conf |
