File: util.go

package info (click to toggle)
golang-github-monochromegane-go-gitignore 0.0~git20200626.205db1a-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 108 kB
  • sloc: makefile: 2
file content (45 lines) | stat: -rw-r--r-- 632 bytes parent folder | download
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
package gitignore

import (
	"os"
	"strings"
)

func cutN(path string, n int) (string, bool) {
	isLast := true

	var i, count int
	for i < len(path)-1 {
		if os.IsPathSeparator(path[i]) {
			count++
			if count >= n {
				isLast = false
				break
			}
		}
		i++
	}
	return path[:i+1], isLast
}

func cutLastN(path string, n int) (string, bool) {
	isLast := true
	i := len(path) - 1

	var count int
	for i >= 0 {
		if os.IsPathSeparator(path[i]) {
			count++
			if count >= n {
				isLast = false
				break
			}
		}
		i--
	}
	return path[i+1:], isLast
}

func hasMeta(path string) bool {
	return strings.IndexAny(path, "*?[") >= 0
}