-
Notifications
You must be signed in to change notification settings - Fork 1
/
escape.go
35 lines (32 loc) · 1.03 KB
/
escape.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
package ts3
import (
"strings"
)
func Escape(in string) (out string) {
out = in
out = strings.Replace(out, "\\", "\\\\", -1)
out = strings.Replace(out, " ", "\\s", -1)
out = strings.Replace(out, "|", "\\p", -1)
out = strings.Replace(out, "\a", "\\a", -1)
out = strings.Replace(out, "\b", "\\b", -1)
out = strings.Replace(out, "\f", "\\f", -1)
out = strings.Replace(out, "\n", "\\n", -1)
out = strings.Replace(out, "\r", "\\r", -1)
out = strings.Replace(out, "\t", "\\t", -1)
out = strings.Replace(out, "\v", "\\v", -1)
return
}
func Unescape(in string) (out string) {
out = in
out = strings.Replace(out, "\\v", "\v", -1)
out = strings.Replace(out, "\\t", "\t", -1)
out = strings.Replace(out, "\\r", "\r", -1)
out = strings.Replace(out, "\\n", "\n", -1)
out = strings.Replace(out, "\\f", "\f", -1)
out = strings.Replace(out, "\\b", "\b", -1)
out = strings.Replace(out, "\\a", "\a", -1)
out = strings.Replace(out, "\\p", "|", -1)
out = strings.Replace(out, "\\s", " ", -1)
out = strings.Replace(out, "\\\\", "\\", -1)
return
}