added bindings for morse code, bug fix
This commit is contained in:
parent
3bd5530544
commit
b60acf2008
|
@ -23,6 +23,7 @@ import Encoding.UnixToUnix (encuu, decuu)
|
|||
import Encoding.Yenc (ency, decy)
|
||||
import Encoding.LetterToNumber (encltn, decltn)
|
||||
import Encoding.Rotate (rotate)
|
||||
import Encoding.Morse (encmorse, decmorse)
|
||||
import Encoding.Solve (solveEnc)
|
||||
|
||||
|
||||
|
@ -46,6 +47,7 @@ data Based = Decode {
|
|||
yenc :: Bool,
|
||||
a1z26 :: Bool,
|
||||
rot :: Maybe Int,
|
||||
morse :: Bool,
|
||||
solve :: Bool
|
||||
}
|
||||
| Encode {
|
||||
|
@ -67,6 +69,7 @@ data Based = Decode {
|
|||
xx :: Bool,
|
||||
yenc :: Bool,
|
||||
a1z26 :: Bool,
|
||||
morse :: Bool,
|
||||
rot :: Maybe Int
|
||||
}
|
||||
deriving(Show, Data, Typeable)
|
||||
|
@ -111,6 +114,8 @@ optionHandler Decode{a1z26=True} = decltn
|
|||
optionHandler Encode{a1z26=True} = encltn
|
||||
optionHandler Decode{rot=Just n} = rotate n
|
||||
optionHandler Encode{rot=Just n} = rotate n
|
||||
optionHandler Decode{morse=True} = decmorse
|
||||
optionHandler Encode{morse=True} = encmorse
|
||||
optionHandler Decode{solve=True} = solveEnc
|
||||
|
||||
decodeMode :: Based
|
||||
|
@ -134,6 +139,7 @@ decodeMode = Decode {
|
|||
yenc = def &= help "decode yEncode",
|
||||
a1z26 = def &= help "decode letter to number",
|
||||
rot = def &= help "rotate characters by n positions",
|
||||
morse = def &= help "decode morse",
|
||||
solve = def &= help "solve encoding"
|
||||
} &= help "Decode chosen base" &=auto
|
||||
|
||||
|
@ -157,7 +163,8 @@ encodeMode = Encode {
|
|||
xx = def &= help "encode xx, without padding",
|
||||
yenc = def &= help "encode yEncode",
|
||||
a1z26 = def &= help "encode letter to number",
|
||||
rot = def &= help "rotate characters by n positions"
|
||||
rot = def &= help "rotate characters by n positions",
|
||||
morse = def &= help "encode morse"
|
||||
} &= help "Encode chosen base"
|
||||
|
||||
main :: IO()
|
||||
|
|
|
@ -5,13 +5,14 @@ module Encoding.Morse
|
|||
|
||||
import Text.Morse as M
|
||||
import Data.ByteString (ByteString)
|
||||
import Data.Char (isSpace)
|
||||
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 "")
|
||||
encodeValidMorseChars = concatMap (\c -> M.encodeMorse [c])
|
||||
|
||||
decmorse :: ByteString -> ByteString
|
||||
decmorse input = case M.decodeMorse (BC.unpack input) of
|
||||
|
|
Loading…
Reference in New Issue