-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (47 loc) · 849 Bytes
/
main.go
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
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
)
var encoderMap = []string{
"a", "1",
"e", "2",
"i", "3",
"o", "4",
"u", "5",
}
var decoderMap = []string{
"1", "a",
"2", "e",
"3", "i",
"4", "o",
"5", "u",
}
func main() {
var result string
decode := flag.Bool("d", false, "Decode.")
flag.Parse()
fmt.Println("Please enter the text to process:")
s := bufio.NewScanner(os.Stdin)
s.Split(bufio.ScanLines)
if s.Scan() {
if *decode {
result = processText(decoderMap, s.Text())
} else {
result = processText(encoderMap, s.Text())
}
fmt.Println(result)
}
if err := s.Err(); err != nil {
log.Printf("reading input: %s", err)
}
}
func processText(mapping []string, text string) string {
r := strings.NewReplacer(mapping...)
lowerCase := strings.ToLower(text)
return r.Replace(lowerCase)
}