1 | <?php |
||
5 | class Morsecode |
||
6 | { |
||
7 | /** |
||
8 | * @var array |
||
9 | */ |
||
10 | private $translation = [ |
||
11 | '0' => '-----', |
||
12 | '1' => '.----', |
||
13 | '2' => '..---', |
||
14 | '3' => '...--', |
||
15 | '4' => '....-', |
||
16 | '5' => '.....', |
||
17 | '6' => '-....', |
||
18 | '7' => '--...', |
||
19 | '8' => '---..', |
||
20 | '9' => '----.', |
||
21 | 'a' => '.-', |
||
22 | 'b' => '-...', |
||
23 | 'c' => '-.-.', |
||
24 | 'd' => '-..', |
||
25 | 'e' => '.', |
||
26 | 'f' => '..-.', |
||
27 | 'g' => '--.', |
||
28 | 'h' => '....', |
||
29 | 'i' => '..', |
||
30 | 'j' => '.---', |
||
31 | 'k' => '-.-', |
||
32 | 'l' => '.-..', |
||
33 | 'm' => '--', |
||
34 | 'n' => '-.', |
||
35 | 'o' => '---', |
||
36 | 'p' => '.--.', |
||
37 | 'q' => '--.-', |
||
38 | 'r' => '.-.', |
||
39 | 's' => '...', |
||
40 | 't' => '-', |
||
41 | 'u' => '..-', |
||
42 | 'v' => '...-', |
||
43 | 'w' => '.--', |
||
44 | 'x' => '-..-', |
||
45 | 'y' => '-.--', |
||
46 | 'z' => '--..', |
||
47 | '.' => '.-.-.-', |
||
48 | ',' => '--..--', |
||
49 | '?' => '..--..', |
||
50 | '!' => '-.-.--', |
||
51 | '-' => '-....-', |
||
52 | '/' => '-..-.', |
||
53 | '@' => '.--.-.', |
||
54 | '(' => '-.--.', |
||
55 | ')' => '-.--.-', |
||
56 | ' ' => '/', |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * The value the class constructed with. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | private $value = ''; |
||
65 | |||
66 | /** |
||
67 | * Morsecode constructor. |
||
68 | * |
||
69 | * @param string $value |
||
70 | */ |
||
71 | public function __construct(string $value = '') |
||
75 | |||
76 | /** |
||
77 | * @param string $str |
||
78 | * @return string |
||
79 | */ |
||
80 | public function encode(string $str = '', string $result = ''): string |
||
94 | |||
95 | /** |
||
96 | * @param string $str |
||
97 | * @return string |
||
98 | */ |
||
99 | public function decode(string $str = '', string $result = ''): string |
||
114 | } |
||
115 |