]> Sergey Matveev's repositories - path-extractor.git/blob - validators.go
Update readme with installation method
[path-extractor.git] / validators.go
1 package pathextractor
2
3 import (
4         "regexp"
5         "strings"
6 )
7
8 func isGitRange(input string) bool {
9         r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}")
10         return r.Match([]byte(input))
11 }
12
13 func isGitPath(input string) bool {
14         r := regexp.MustCompile("^[ab]/")
15         return r.Match([]byte(input))
16 }
17
18 func isDate(input string) bool {
19         r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+")
20         return r.Match([]byte(input))
21 }
22
23 func isGitInstruction(input string) bool {
24         r := regexp.MustCompile("\\.{3,}")
25         return r.Match([]byte(input))
26 }
27
28 func replaceGitPath(input string) string {
29         r := regexp.MustCompile("^[ab]/(.*)")
30         temp := [][]byte{}
31         temp = r.FindSubmatch([]byte(input))
32         return string(temp[1])
33 }
34
35 func isVersion(input string) bool {
36         r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?")
37         return r.Match([]byte(input))
38 }
39
40 func containsInvalidString(input string) bool {
41         invalidStrings := []string{"(", ")", "@", "origin/", "{", "}", "<", ">", "$", "*"}
42         for _, s := range invalidStrings {
43                 if strings.Contains(input, s) {
44                         return true
45                 }
46         }
47         return false
48 }