-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtelepad2num.go
70 lines (63 loc) · 1.02 KB
/
telepad2num.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"fmt"
"os"
"unicode"
)
var (
dump = flag.Bool("d", false, "dump telepad")
)
func main() {
flag.Usage = usage
flag.Parse()
if *dump {
printTelepad()
return
}
if flag.NArg() < 1 {
usage()
}
for _, arg := range flag.Args() {
fmt.Println(tel2num(arg))
}
}
func usage() {
fmt.Fprintln(os.Stderr, "usage: [options] telepad ...")
flag.PrintDefaults()
os.Exit(2)
}
func printTelepad() {
fmt.Println("ABC -> 2")
fmt.Println("DEF -> 3")
fmt.Println("GHI -> 4")
fmt.Println("JKL -> 5")
fmt.Println("MNO -> 6")
fmt.Println("PQRS -> 7")
fmt.Println("TUV -> 8")
fmt.Println("WXYZ -> 9")
}
func tel2num(s string) string {
var p string
for _, c := range s {
switch unicode.ToUpper(c) {
case 'A', 'B', 'C':
p += "2"
case 'D', 'E', 'F':
p += "3"
case 'G', 'H', 'I':
p += "4"
case 'J', 'K', 'L':
p += "5"
case 'M', 'N', 'O':
p += "6"
case 'P', 'Q', 'R', 'S':
p += "7"
case 'T', 'U', 'V':
p += "8"
case 'W', 'X', 'Y', 'Z':
p += "9"
}
}
return p
}