-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
67 lines (57 loc) · 1.09 KB
/
utils.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
package main
import (
"fmt"
"path"
//"github.com/rwtodd/sed-go"
"github.com/rwtodd/Go.Sed/sed"
"os"
"strings"
)
type StringRewriter interface {
RunString(string, int) string
}
type PathRewriter struct {
engine *sed.Engine
}
func (self *PathRewriter) RunString(input string, n int) string {
if nil != self.engine {
s, e := self.engine.RunString(input)
if nil != e {
return input
} else {
return strings.TrimSpace(s)
}
} else {
return path.Base(input)
}
}
func NewPathRewriter(cmd string) (pr *PathRewriter) {
pr = new(PathRewriter)
if cmd == "" {
return pr
}
engine, err := sed.New(strings.NewReader(cmd))
if nil == err {
pr.engine = engine
}
return
}
type SegmentRewriter struct {
format string
}
func (self *SegmentRewriter) RunString(input string, n int) string {
return fmt.Sprintf(self.format, n)
//return input
}
func NewSegmentRewriter(cmd string) (sr *SegmentRewriter) {
sr = new(SegmentRewriter)
sr.format = cmd
return
}
func exists(path string, size int64) bool {
s, err := os.Stat(path)
if nil != err || s.Size() < size {
return false
}
return true
}