]> Sergey Matveev's repositories - path-extractor.git/blobdiff - extractor.go
First try for linenumbers
[path-extractor.git] / extractor.go
index 6a87ab454cc79fb3a2b5daee2ceb52206850e64c..2a3b2cd5723d89593b5782e6782fa768b495c596 100644 (file)
@@ -1,6 +1,11 @@
 package pathextractor
 
 import "regexp"
+import "fmt"
+
+type MatchOptions struct {
+       format string
+}
 
 func pathExtractor(input string) [][][]byte {
        surroundRegex := "[^][ \\t:'\"]*"
@@ -10,10 +15,26 @@ func pathExtractor(input string) [][][]byte {
        return temp
 }
 
-func GetAllMatches(input string) []string {
+func stripParens(input string) string {
+       r := regexp.MustCompile("^\\((.*)\\)$")
+       temp := [][]byte{}
+       temp = r.FindSubmatch([]byte(input))
+       if len(temp) <= 1 {
+               return input
+       }
+       return string(temp[1])
+}
+
+func postProcess(input string) string {
+       input = stripParens(input)
+       return input
+}
+
+func GetAllMatches(input string, options MatchOptions) []string {
        matches := [][][]byte{}
        result := []string{}
        s := string("")
+       // print(input)
        matches = pathExtractor(input)
        for _, match := range matches {
                s = string(match[1])
@@ -23,6 +44,10 @@ func GetAllMatches(input string) []string {
                if isGitPath(s) {
                        s = replaceGitPath(s)
                }
+               s = postProcess(s)
+               if options.format == "ackmate" {
+                       s = fmt.Sprint(s, ":45")
+               }
                result = append(result, s)
        }
        return result