-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtti.go
More file actions
31 lines (29 loc) · 813 Bytes
/
Copy pathtti.go
File metadata and controls
31 lines (29 loc) · 813 Bytes
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
package teletext
import (
"bytes"
"strconv"
)
// Converts .tti file data to the internal page format
func ConvertTTI(title string, data []byte) Page {
out := Page{}
lines := bytes.Split(data, []byte{0xd, 0xa})
pagenumber := 100
for _, l := range lines {
line := unescape(l)
if bytes.HasPrefix(line, []byte("PN,")) {
lsplit := bytes.SplitN(line, []byte(","), 2)
pagenumber, _ = strconv.Atoi(string(lsplit[1]))
pagenumber /= 100
out = append(out, PageHeader{Header{Page: pagenumber}, title})
} else if bytes.HasPrefix(line, []byte("OL,")) {
lsplit := bytes.SplitN(line, []byte(","), 3)
row, _ := strconv.Atoi(string(lsplit[1]))
data := lsplit[2]
if len(data) > 40 {
data = data[:40]
}
out = append(out, OutputLine{Header{pagenumber, row}, data})
}
}
return out
}