/
helper.go
59 lines (50 loc) · 1.22 KB
/
helper.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
package main
import (
"flag"
"fmt"
"exp/regexp"
"strings"
)
// Used for Stripping out hyperlinks
var UrlReg *regexp.Regexp = regexp.MustCompile("</?a.*?>")
var tabs bool
func init() {
flag.BoolVar(&tabs, "t", false, "Use tabs instead of spaces.")
}
func RemoveUrl(s string) string {
return UrlReg.ReplaceAllString(s, "")
}
// Used for properly tabbing nested things
func tab(s string, i int) (result string) {
if tabs {
result = "\t" + strings.Replace(s, "\n", "\n\t", -1)
} else {
result = " " + strings.Replace(s, "\n", "\n ", -1)
}
return
}
// Used for adding *'s to included newlines
func javaDoc(j JavaDoc) (s string) {
s = j.String()
s = strings.Replace(s, "\n", "\n * ", -1)
s = regexp.MustCompile(" * $").ReplaceAllString(s, " *")
return
}
// This is used for testing only.
// No calls to it should exist in a final product.
func debugPrint(data ...string) {
fmt.Println("{")
for _, info := range data {
fmt.Println("\t", info)
}
fmt.Println("}")
}
func sanitize(s string) (r string) {
r = s
r = RemoveUrl(r)
r = strings.Replace(r, ">", ">", -1)
r = strings.Replace(r, "<", "<", -1)
r = regexp.MustCompile(", |,|^|[^<,]+ ?\\.").ReplaceAllString(r, "")
r = strings.Trim(r, " ")
return
}