]> Sergey Matveev's repositories - path-extractor.git/blobdiff - extractor.go
Tests workability
[path-extractor.git] / extractor.go
index 326855cf59e52e409b2d65661aba738550730982..3183109418b35e00912f87c1420e5a98e7e0b569 100644 (file)
@@ -9,7 +9,7 @@ type MatchOptions struct {
 }
 
 func pathExtractor(input string) [][]int {
-       surroundRegex := "[@~\\-_a-zA-Z/.0-9]*"
+       surroundRegex := "[@~\\-_a-zA-ZА-Яа-яЁё/.0-9]*"
        r := regexp.MustCompile("(" + surroundRegex + "[\\./]" + surroundRegex + ")")
        return r.FindAllSubmatchIndex([]byte(input), -1)
 }
@@ -29,9 +29,11 @@ func postProcess(input string) string {
        return input
 }
 
-func GetAllMatches(input string, options MatchOptions) []string {
+func GetAllMatches(input string, format string) []string {
+       options := MatchOptions{format: format}
        result := []string{}
        candidatePath := string("")
+       restOfLine := string("")
        indexes := pathExtractor(input)
        for _, index := range indexes {
                candidatePath = input[index[0]:index[1]]
@@ -39,19 +41,29 @@ func GetAllMatches(input string, options MatchOptions) []string {
                        continue
                }
 
-               if isEmail(candidatePath) || isDate(candidatePath) || isVersion(candidatePath) || isGitRange(candidatePath) || isGitInstruction(candidatePath) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 {
+               if isIp(candidatePath) || isEmail(candidatePath) || isDate(candidatePath) || isVersion(candidatePath) || isGitRange(candidatePath) || isGitInstruction(candidatePath) || startsWithInvalidString(candidatePath) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 || isSpace(candidatePath) {
                        continue
                }
                if isGitPath(candidatePath) {
                        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])
+}