-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
58 lines (51 loc) · 1.01 KB
/
tools.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
package slug
import (
"strings"
"github.com/goloop/t13n/lang"
)
// The slugRules sets custom transliteration rules
// for the github.com/goloop/t13n module.
func slugRules(ts lang.TransState) (string, int, bool) {
// Ignore ranges.
// Important: edit maps ascending order only!
ignored := [][]int{
{0, 47},
{58, 64},
{91, 96},
{123, 141},
{143, 152},
{155, 155},
}
switch ts.Value {
case " ", "~", "_", "\t", "\n":
ts.Value = "-"
case "@":
ts.Value = "at"
case "&":
ts.Value = "and"
case "#":
ts.Value = "sharp"
case "%":
ts.Value = "pct"
default:
id := int(ts.Curr)
for _, d := range ignored {
// If the item isn't in the following ranges.
if id < d[0] {
break
}
// If the item is in the current range.
if id >= d[0] && id <= d[1] {
ts.Value = ""
break
}
}
}
if len(ts.Value) > 1 && strings.HasSuffix(ts.Value, " ") {
runes := []rune(ts.Value)
if ts.Next != 0 {
ts.Value = string(runes[:len(runes)-1]) + "-"
}
}
return ts.Value, 0, true
}