packages feed

MorseCode 0.0.4 → 0.0.5

raw patch · 2 files changed

+18/−23 lines, 2 filesdep +splitPVP ok

version bump matches the API change (PVP)

Dependencies added: split

API changes (from Hackage documentation)

Files

MorseCode.cabal view
@@ -1,5 +1,5 @@ name:			MorseCode-version:		0.0.4+version:		0.0.5 Cabal-Version:	>= 1.6 license:		GPL-3 license-file:	LICENSE@@ -17,4 +17,4 @@ Library   Exposed-Modules:      Text.Morse-  Build-depends: containers >= 0.2.0.1, base >= 4 && < 5+  Build-depends: containers >= 0.2.0.1, base >= 4 && < 5, split
Text/Morse.hs view
@@ -25,6 +25,7 @@  import Data.Char import Data.Map (Map)+import Data.List.Split  import qualified Data.Map as M @@ -96,27 +97,21 @@ -- | Get string from Morse Code. -- Invalid Morse Code will skip. decodeMorse :: String -> String-decodeMorse str = decodeMorse' str ""--decodeMorse' :: String -> String -> String-decodeMorse' [] _ = []-decodeMorse' (x:xs) str -    | x == '.'-        = decodeMorse' xs (str ++ [x])-    | x == '-'-        = decodeMorse' xs (str ++ [x])-    | x == ' '-        = let char = -                  case findMinMatch morseCode (\ _ v -> v == str) of-                    Just (c, _) -> c-                    -- Insert blank when got invalid Morse code.-                    Nothing -> x -          in char : decodeMorse' xs ""-    | x == '/' -        = ' ' : decodeMorse' xs ""-    -- Ignore invalid Morse character.-    | otherwise-        = decodeMorse' xs ""+decodeMorse str =+    concatMap +    (\x -> +         if x == "/" +            -- Replace "/" with blank. +            then " " +            else +                concatMap +                (\lv -> +                     case findMinMatch morseCode (\ _ v -> v == lv) of+                       Just (c, _) -> [c]+                       -- Ignore invalid Morse Code.+                       Nothing -> [])+                (split (dropDelims $ dropFinalBlank $ oneOf " ") x))+    (split (oneOf "/") str)  -- | Character can encode to Morse Code? canEncodeToMorse :: Char -> Bool