forked from warthog618/sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
charsets.go
74 lines (68 loc) · 1.35 KB
/
charsets.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
71
72
73
74
// SPDX-License-Identifier: MIT
//
// Copyright © 2018 Kent Gibson <[email protected]>.
package main
import (
"fmt"
"github.com/warthog618/sms/encoding/gsm7/charset"
)
var charsetName = []string{
"Basic (default)",
"Turkish",
"Spanish",
"Portuguese",
"Bengali",
"Gujaranti",
"Hindi",
"Kannada",
"Malayalam",
"Oriya",
"Punjabi",
"Tamil",
"Telugu",
"Urdu",
}
func main() {
for nli := charset.Default; nli <= charset.Urdu; nli++ {
fmt.Printf("%s Locking (NLI=%d)\n", charsetName[nli], nli)
Display(charset.NewDecoder(nli))
fmt.Println()
fmt.Printf("%s Shift (NLI=%d)\n", charsetName[nli], nli)
Display(charset.NewExtDecoder(nli))
fmt.Println()
}
}
// Display prints the character set for a given character set decoder.
func Display(m charset.Decoder) {
specials := map[rune]string{
'\n': "LF",
'\r': "CR",
'\f': "FF",
' ': "SP",
0x1b: "ESC",
0x20ac: " €",
}
fmt.Printf(" ")
for c := 0; c < 8; c++ {
fmt.Printf("0x%d_ ", c)
}
fmt.Println("")
for r := 0; r < 0x10; r++ {
fmt.Printf("0x_%x: ", r)
for c := 0; c < 8; c++ {
k := byte(c*0x10 + r)
if v, ok := m[k]; ok {
if s, ok := specials[v]; ok {
fmt.Printf("%3s ", s)
} else if v >= 0x400 {
fmt.Printf("%04x ", v)
} else {
fmt.Printf(" %c ", v)
}
} else {
fmt.Printf(" ")
}
}
fmt.Println()
}
}