-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathba.go
106 lines (80 loc) · 1.67 KB
/
pathba.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"path/filepath"
"path"
"strings"
)
func main() {
fmt.Println("Hello World")
a := NewPath("/home/asb.doc")
a.Print()
fmt.Println(a.Base())
fmt.Println(a.Dir())
fmt.Println(a.Ext())
fmt.Println(a.Name())
fmt.Println(a.HasExt())
fmt.Println(a.RemoveExt())
}
type Path struct {
path string
}
func NewPath(p string) Path {
return Path{path: p}
}
func (p *Path) Print() {
fmt.Println(p.path)
}
func (p *Path) Dir() string {
dirn := path.Dir(p.path)
return dirn
}
func (p *Path) Base() string {
bn := path.Base(p.path)
return bn
}
func (p *Path) Ext() string {
ext := filepath.Ext(p.path)
if ext != "" {
ext = strings.TrimPrefix(ext, ".")
}
return strings.ToLower(ext)
}
func (p *Path) Name() string {
var base = path.Base(p.path)
var ext = path.Ext(p.path)
var name = base[0:len(base)-len(ext)]
return name
}
func (p *Path) HasExt() bool {
if filepath.Ext(p.path) == "" {
return false
} else {
return true
}
}
func (p *Path) RemoveExt() string {
ext := path.Ext(p.path)
var pathWithoutExt string
if ext != "" {
pathWithoutExt = strings.TrimSuffix(p.path, ext)
}
return pathWithoutExt
}
// func (p *Path) MoveUp(numOfLevel int) Path {
// return Path{path: ""}
// }
// func (p *Path) ValidateExt(validExts []string) string {
// }
// func (p *Path) ValidateNotExt(invalidExts []string) string {
// }
// func (p *Path) IsFromUnixLike() bool {
// }
// func (p *Path) IsFromWindow() bool {
// }
// func (p *Path) IsBaseOnly() bool {
// }
// func (p *Path) IsAbs() bool {} {
// }
// func (p *Path) IsRel() bool {
// }