-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.go
More file actions
executable file
·72 lines (59 loc) · 1.66 KB
/
lib.go
File metadata and controls
executable file
·72 lines (59 loc) · 1.66 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
package fopa
import (
"path/filepath"
"github.com/kendfss/fopa/internal"
)
var Filler = "_"
// remove illegal characters from a file path
func Sanitize(path string) string {
return Sanitizef(path, Filler)
}
// remove illegal characters from a file path
func Sanitizef(path, fill string) string {
return sanitizef(path, fill)
}
// Redux remove runs of the fill character
func Redux(path string) string {
return Reduxf(path, Filler)
}
// Redux removes runs of the fill character, with a format string
func Reduxf(path, fill string) string {
return reduxf(path, fill)
}
// Sanitize and Redux a filepath
func Clean(path string) string {
return Cleanf(path, Filler)
}
// Sanitize and Redux a filepath, with a format string
func Cleanf(path, fill string) string {
return cleanf(path, fill)
}
// // ForbiddenRules returns a slice of Symbol x Description pairs.
// func ForbiddenRules() []Rule {
// if forbiddenRules == nil {
// forbiddenRules = make([]Rule, len(internal.ForbiddenRules))
// for i, e := range internal.ForbiddenRules {
// forbiddenRules[i] = Rule{Symb: e.Symb, Desc: e.Desc}
// }
// }
// return forbiddenRules
// }
// ForbiddenChars returns a slice of the characters this library forbids
func ForbiddenChars() []string {
return internal.ForbiddenChars
}
// SplitClean splits the path before cleaning each segment
func SplitClean(path string) string {
parts := filepath.SplitList(path)
for i, part := range parts {
parts[i] = Clean(part)
}
return filepath.Join(parts...)
}
// Join cleans each segment before joining the lot
func Join(parts ...string) string {
for i, part := range parts {
parts[i] = Clean(part)
}
return filepath.Join(parts...)
}