added morse encoding, WIP
This commit is contained in:
parent
f5d35aa555
commit
3bd5530544
|
@ -26,6 +26,7 @@ library
|
||||||
Encoding.Yenc
|
Encoding.Yenc
|
||||||
Encoding.Rotate
|
Encoding.Rotate
|
||||||
Encoding.LetterToNumber
|
Encoding.LetterToNumber
|
||||||
|
Encoding.Morse
|
||||||
Encoding.Solve
|
Encoding.Solve
|
||||||
other-modules:
|
other-modules:
|
||||||
-- Data.Bytes.Text.Ascii
|
-- Data.Bytes.Text.Ascii
|
||||||
|
@ -45,7 +46,8 @@ library
|
||||||
text,
|
text,
|
||||||
primitive,
|
primitive,
|
||||||
regex-tdfa,
|
regex-tdfa,
|
||||||
base64-bytestring
|
base64-bytestring,
|
||||||
|
MorseCode
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
executable based
|
executable based
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
module Encoding.Morse
|
||||||
|
( encmorse
|
||||||
|
, decmorse
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Text.Morse as M
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
import qualified Data.ByteString.Char8 as BC
|
||||||
|
|
||||||
|
encmorse :: ByteString -> ByteString
|
||||||
|
encmorse input = BC.pack $ encodeValidMorseChars (BC.unpack input)
|
||||||
|
where
|
||||||
|
encodeValidMorseChars :: String -> String
|
||||||
|
encodeValidMorseChars = concatMap (\c -> if canEncodeToMorse c then M.encodeMorse [c] else "")
|
||||||
|
|
||||||
|
decmorse :: ByteString -> ByteString
|
||||||
|
decmorse input = case M.decodeMorse (BC.unpack input) of
|
||||||
|
"" -> BC.pack "Invalid Morse Code"
|
||||||
|
decoded -> BC.pack decoded
|
||||||
|
|
Loading…
Reference in New Issue