-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.go
More file actions
92 lines (82 loc) · 1.75 KB
/
helper.go
File metadata and controls
92 lines (82 loc) · 1.75 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package snake
import (
"fmt"
"io"
"os"
"path/filepath"
"unicode"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/ianaindex"
)
var Len = utf8.RuneCountInString
// ucfirst 英文首字母大写 ...
func ucfirst(src string) string {
for i, v := range src {
return string(unicode.ToUpper(v)) + src[i+1:]
}
return src
}
// lcfirst 英文首字母小写 ...
func lcfirst(src string) string {
for i, v := range src {
return string(unicode.ToLower(v)) + src[i+1:]
}
return src
}
// WalkPath Files……
// 遍历目录查找文件
func walkPath(path string, dst ...string) []string {
var res []string
filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if err == nil && info.IsDir() {
for _, v := range dst {
if l, err := filepath.Glob(filepath.Join(p, filepath.Base(v))); len(l) != 0 && err == nil {
res = append(res, l...)
}
}
}
return err
})
return res
}
// ls 路径目录下内容
func ls(path string, dst ...string) []string {
var res []string
for _, v := range dst {
if l, err := filepath.Glob(filepath.Join(path, v)); err == nil {
res = append(res, l...)
}
}
return res
}
// _owcpfile 路径目录下内容
func _owcpfile(src FileSystem, dst FileSystem) bool {
// 覆盖拷贝
if f, ok := dst.MkFile(); ok {
defer f.Get().Close()
if s, ok := src.Open(); ok {
defer s.Get().Close()
_, err := io.Copy(f.Get(), s.Get())
return err == nil
}
}
return false
}
func getEncoding(charset string) encoding.Encoding {
if e, err := ianaindex.MIB.Encoding(charset); err == nil && e != nil {
return e
}
return nil
}
func prenum(data byte) int {
str := fmt.Sprintf("%b", data)
var i int = 0
for i < len(str) {
if str[i] != '1' {
break
}
i++
}
return i
}