-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToNato.hs
56 lines (47 loc) · 1.19 KB
/
ToNato.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{-# LANGUAGE Safe #-}
module ToNato (translateChar, toNato) where
import Prelude (Char, String, map, tail, concatMap)
import Data.Char (isUpper, toLower, toUpper)
import Data.List.Split (splitOn)
import Data.List (intercalate)
import qualified Data.Map as Map
-- |Dictionary with all the NATO alphabet
natoMap :: Map.Map Char String
natoMap = Map.fromList [
('a', "alpha"),
('b', "bravo"),
('c', "charlie"),
('d', "delta"),
('e', "echo"),
('f', "foxtrot"),
('g', "golf"),
('h', "hotel"),
('i', "india"),
('j', "juliett"),
('k', "kilo"),
('l', "lima"),
('m', "mike"),
('n', "november"),
('o', "oscar"),
('p', "papa"),
('q', "quebec"),
('r', "romeo"),
('s', "sierra"),
('t', "tango"),
('u', "uniform"),
('v', "victor"),
('w', "whiskey"),
('x', "xray"),
('y', "yankee"),
('z', "zulu")
]
translateChar :: Char -> String
translateChar c =
(if isUpper c then (map toUpper n) else n)
where
n = Map.findWithDefault [c] (toLower c) natoMap
translateWord :: String -> String
translateWord s = concatMap translateChar (intercalate "-" (tail (splitOn "" s)))
toNato :: String -> String
toNato [] = []
toNato s = intercalate " " (map translateWord (splitOn " " s))