-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
50 lines (43 loc) · 1.19 KB
/
util.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
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/view source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package view
import (
"bytes"
"strings"
)
// StripPathPrefixAt method strips the given path to path cut position.
//
// For Example:
//
// path := "/Users/jeeva/go/src/github.com/go-aah/tutorials/form/views/common/header.html"
// result := StripPrefixAt(path, "views/")
func StripPathPrefixAt(str, pathCut string) string {
if idx := strings.Index(str, pathCut); idx > 0 {
return str[idx+len(pathCut):]
}
return str
}
// TrimPathPrefix method trims given file paths by prefix and
// returns comma separated string.
func TrimPathPrefix(prefix string, fpaths ...string) string {
var fs []string
for _, fp := range fpaths {
fs = append(fs, trimPathPrefix(prefix, fp))
}
return strings.Join(fs, ", ")
}
func trimPathPrefix(prefix, fpath string) string {
fpath = strings.TrimPrefix(fpath, prefix)
if fpath[0] == '/' || fpath[0] == '\\' {
fpath = fpath[1:]
}
return fpath
}
func acquireBuffer() *bytes.Buffer {
return bufPool.Get().(*bytes.Buffer)
}
func releaseBuffer(buf *bytes.Buffer) {
buf.Reset()
bufPool.Put(buf)
}