]> Sergey Matveev's repositories - path-extractor.git/blob - extractor.go
Correct surrounded by parens
[path-extractor.git] / extractor.go
1 package pathextractor
2
3 import "regexp"
4
5 func pathExtractor(input string) [][][]byte {
6         surroundRegex := "[^][ \\t:'\"]*"
7         r := regexp.MustCompile("(" + surroundRegex + "[\\./]" + surroundRegex + ")")
8         temp := [][][]byte{}
9         temp = r.FindAllSubmatch([]byte(input), -1)
10         return temp
11 }
12
13 func stripParens(input string) string {
14         r := regexp.MustCompile("^\\((.*)\\)$")
15         temp := [][]byte{}
16         temp = r.FindSubmatch([]byte(input))
17         if len(temp) <= 1 {
18                 return input
19         }
20         return string(temp[1])
21 }
22
23 func postProcess(input string) string {
24         input = stripParens(input)
25         return input
26 }
27
28 func GetAllMatches(input string) []string {
29         matches := [][][]byte{}
30         result := []string{}
31         s := string("")
32         matches = pathExtractor(input)
33         for _, match := range matches {
34                 s = string(match[1])
35                 if isEmail(s) || isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || endsWithInvalidString(s) || containsInvalidString(s) || len(s) <= 2 {
36                         continue
37                 }
38                 if isGitPath(s) {
39                         s = replaceGitPath(s)
40                 }
41                 result = append(result, postProcess(s))
42         }
43         return result
44 }