-
Notifications
You must be signed in to change notification settings - Fork 22
/
decode.go
55 lines (48 loc) · 1.22 KB
/
decode.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 (
"log"
"strings"
)
type conversion struct {
from string
to string
}
func decodeTitle(title string) string {
for _, convert := range []conversion{
{`\#`, "#"},
{`--`, `–`},
{"``", "“"},
{"''", "”"},
{"'", "’"}, // U+2019
{`$\cdot$`, `·`}, // U+00B7.
} {
title = strings.Replace(title, convert.from, convert.to, -1)
}
// Get rid of all curly brackets. We're displaying titles without changing
// their casing.
title = strings.ReplaceAll(title, "{", "")
title = strings.ReplaceAll(title, "}", "")
return title
}
func decodeAuthors(authors string) string {
for _, convert := range []conversion{
{"'", "’"},
} {
authors = strings.Replace(authors, convert.from, convert.to, -1)
}
// For simplicity, we expect authors to be formatted as "John Doe" instead
// of "Doe, John".
if strings.Contains(authors, ",") {
log.Fatalf("author %q contains a comma", authors)
}
authorSlice := strings.Split(authors, " and ")
return strings.Join(authorSlice, ", ")
}
func decodeProceedings(proceedings string) string {
for _, convert := range []conversion{
{`\&`, "&"},
} {
proceedings = strings.Replace(proceedings, convert.from, convert.to, -1)
}
return proceedings
}