]> Sergey Matveev's repositories - path-extractor.git/blobdiff - extractor.go
Getting line number now works
[path-extractor.git] / extractor.go
index 326855cf59e52e409b2d65661aba738550730982..c19b7d5cae73c091b2f8e4599b17cd98461cd7aa 100644 (file)
@@ -32,6 +32,7 @@ func postProcess(input string) string {
 func GetAllMatches(input string, options MatchOptions) []string {
        result := []string{}
        candidatePath := string("")
+       restOfLine := string("")
        indexes := pathExtractor(input)
        for _, index := range indexes {
                candidatePath = input[index[0]:index[1]]
@@ -46,12 +47,22 @@ func GetAllMatches(input string, options MatchOptions) []string {
                        candidatePath = replaceGitPath(candidatePath)
                }
                candidatePath = postProcess(candidatePath)
-               lineNumber := 45
-               columnNumber := 1
                if options.format == "ackmate" {
-                       candidatePath = fmt.Sprint(candidatePath, ":", lineNumber, ":", columnNumber)
+                       restOfLine = input[index[1]:]
+                       cursorPos := getCursorPosition(restOfLine)
+                       candidatePath = fmt.Sprint(candidatePath, cursorPos)
                }
                result = append(result, candidatePath)
        }
        return result
 }
+
+func getCursorPosition(input string) string {
+       r := regexp.MustCompile("^(:[0-9]+(:[0-9]+)?)$")
+       temp := [][]byte{}
+       temp = r.FindSubmatch([]byte(input))
+       if len(temp) <= 1 {
+               return ""
+       }
+       return string(temp[1])
+}