]> Sergey Matveev's repositories - path-extractor.git/commitdiff
gofmt all the code
authorSoulou <leo@unbekandt.eu>
Sun, 21 Jun 2015 16:06:00 +0000 (18:06 +0200)
committerSoulou <leo@unbekandt.eu>
Sun, 21 Jun 2015 16:06:00 +0000 (18:06 +0200)
extractor.go
pe.go
pe_test.go
validators.go

index 69d4b95b7a2f2801050f9d32a35efb746fd2c7bc..b7be986ea6b3ab8bca8582b0c8d6af4c7bb06d8e 100644 (file)
@@ -2,29 +2,28 @@ package main
 
 import "regexp"
 
-
 func pathExtractor(input string) [][][]byte {
-    surroundRegex := "[^][ \\t:'\"]"
-    r := regexp.MustCompile("("+surroundRegex+"*[\\./]"+surroundRegex+"*)")
-    temp := [][][]byte{}
-    temp = r.FindAllSubmatch([]byte(input),-1)
-    return temp
+       surroundRegex := "[^][ \\t:'\"]"
+       r := regexp.MustCompile("(" + surroundRegex + "*[\\./]" + surroundRegex + "*)")
+       temp := [][][]byte{}
+       temp = r.FindAllSubmatch([]byte(input), -1)
+       return temp
 }
 
 func getAllMatches(input string) []string {
-    matches := [][][]byte{}
-    result := []string{}
-    s := string("")
-    matches = pathExtractor(input)
-    for _,match := range matches {
-        s = string(match[1])
-        if isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || containsInvalidString(s) || len(s)<=2 {
-            continue
-        }
-        if isGitPath(s) {
-            s = replaceGitPath(s)
-        }
-        result = append(result,s)
-    }
-    return result
+       matches := [][][]byte{}
+       result := []string{}
+       s := string("")
+       matches = pathExtractor(input)
+       for _, match := range matches {
+               s = string(match[1])
+               if isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || containsInvalidString(s) || len(s) <= 2 {
+                       continue
+               }
+               if isGitPath(s) {
+                       s = replaceGitPath(s)
+               }
+               result = append(result, s)
+       }
+       return result
 }
diff --git a/pe.go b/pe.go
index a95a3857fc859e9e616b5e6bcced67425e223a4b..5147f27862ae95d3ddc4a790f6cee77a636bdd89 100644 (file)
--- a/pe.go
+++ b/pe.go
@@ -1,18 +1,19 @@
 package main
 
-import "os"
-import "bufio"
-import "fmt"
+import (
+       "bufio"
+       "fmt"
+       "os"
+)
 
 func main() {
-    stdin := os.Stdin
-    if scanner := bufio.NewScanner(stdin); scanner != nil {
-        for scanner.Scan() {
-            matches := getAllMatches(scanner.Text())
-            for _,match := range matches {
-                fmt.Println(match)
-            }
-        }
-    }
+       stdin := os.Stdin
+       if scanner := bufio.NewScanner(stdin); scanner != nil {
+               for scanner.Scan() {
+                       matches := getAllMatches(scanner.Text())
+                       for _, match := range matches {
+                               fmt.Println(match)
+                       }
+               }
+       }
 }
-
index 378e79ac31a6950aee1c52e1acc5e75505fcc242..2ef95b285870f1d42b9dda338da17f079fc0f9a3 100644 (file)
@@ -3,63 +3,63 @@ package main
 import "testing"
 
 func TestGitIgnore(t *testing.T) {
-    output:=getAllMatches("?? alt/generateStore.php")
-    if output[0] != "alt/generateStore.php" {
-        t.Errorf("Doesnt match files", output[0])
-    }
+       output := getAllMatches("?? alt/generateStore.php")
+       if output[0] != "alt/generateStore.php" {
+               t.Errorf("Doesnt match files", output[0])
+       }
 
-    output=getAllMatches("hello .gitignore")
-    if output[0] != ".gitignore" {
-        t.Errorf("Doesnt match hidden files", output[0])
-    }
+       output = getAllMatches("hello .gitignore")
+       if output[0] != ".gitignore" {
+               t.Errorf("Doesnt match hidden files", output[0])
+       }
 
-    output=getAllMatches(" mail@mail.com ")
-    if len(output) != 0 {
-        t.Errorf("Matches email adresses", output[0])
-    }
+       output = getAllMatches(" mail@mail.com ")
+       if len(output) != 0 {
+               t.Errorf("Matches email adresses", output[0])
+       }
 
-    output=getAllMatches("v1.2")
-    if len(output) != 0 {
-        t.Errorf("Matches version number", output[0])
-    }
+       output = getAllMatches("v1.2")
+       if len(output) != 0 {
+               t.Errorf("Matches version number", output[0])
+       }
 
-    output=getAllMatches("obj.slice()")
-    if len(output) != 0 {
-        t.Errorf("Matches function call", output[0])
-    }
+       output = getAllMatches("obj.slice()")
+       if len(output) != 0 {
+               t.Errorf("Matches function call", output[0])
+       }
 
-    output=getAllMatches("~/www")
-    if len(output) == 0 || output[0] != "~/www" {
-        t.Errorf("Doesnt match home", output[0])
-    }
+       output = getAllMatches("~/www")
+       if len(output) == 0 || output[0] != "~/www" {
+               t.Errorf("Doesnt match home", output[0])
+       }
 
-    output=getAllMatches("origin/master")
-    if len(output) != 0 {
-        t.Errorf("Matches remote name", output[0])
-    }
+       output = getAllMatches("origin/master")
+       if len(output) != 0 {
+               t.Errorf("Matches remote name", output[0])
+       }
 
-    output=getAllMatches("john doe (dead on 28/04/2014)")
-    if len(output) != 0 {
-        t.Errorf("Matches date", output[0])
-    }
+       output = getAllMatches("john doe (dead on 28/04/2014)")
+       if len(output) != 0 {
+               t.Errorf("Matches date", output[0])
+       }
 
-    output=getAllMatches("john doe ,dead on 28/04/2014")
-    if len(output) != 0 {
-        t.Errorf("Matches date", output[0])
-    }
+       output = getAllMatches("john doe ,dead on 28/04/2014")
+       if len(output) != 0 {
+               t.Errorf("Matches date", output[0])
+       }
 
-    output=getAllMatches(".gitignore , ~/www")
-    if len(output) != 2 {
-        t.Errorf("Doesnt match multi", output[0])
-    }
+       output = getAllMatches(".gitignore , ~/www")
+       if len(output) != 2 {
+               t.Errorf("Doesnt match multi", output[0])
+       }
 
-    output=getAllMatches("var/")
-    if len(output) != 1 {
-        t.Errorf("Doesnt match dir", output[0])
-    }
+       output = getAllMatches("var/")
+       if len(output) != 1 {
+               t.Errorf("Doesnt match dir", output[0])
+       }
 
-    output=getAllMatches("//")
-    if len(output) != 0 {
-        t.Errorf("Comment matches", output[0])
-    }
+       output = getAllMatches("//")
+       if len(output) != 0 {
+               t.Errorf("Comment matches", output[0])
+       }
 }
index 60811fc430d3c6ee3409837c83c9df36bd9687c7..74b774603977ad21fdf5ef8e1fef0270cfb0fe16 100644 (file)
@@ -1,46 +1,48 @@
 package main
 
-import "strings"
-import "regexp"
-
-func isGitRange (input string) bool {
-    r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}")
-    return r.Match([]byte(input))
+import (
+       "regexp"
+       "strings"
+)
+
+func isGitRange(input string) bool {
+       r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}")
+       return r.Match([]byte(input))
 }
 
-func isGitPath (input string) bool {
-    r := regexp.MustCompile("^[ab]/")
-    return r.Match([]byte(input))
+func isGitPath(input string) bool {
+       r := regexp.MustCompile("^[ab]/")
+       return r.Match([]byte(input))
 }
 
-func isDate (input string) bool {
-    r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+")
-    return r.Match([]byte(input))
+func isDate(input string) bool {
+       r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+")
+       return r.Match([]byte(input))
 }
 
-func isGitInstruction (input string) bool {
-    r := regexp.MustCompile("\\.{3,}")
-    return r.Match([]byte(input))
+func isGitInstruction(input string) bool {
+       r := regexp.MustCompile("\\.{3,}")
+       return r.Match([]byte(input))
 }
 
-func replaceGitPath (input string) string {
-    r := regexp.MustCompile("^[ab]/(.*)")
-    temp := [][]byte{}
-    temp = r.FindSubmatch([]byte(input))
-    return string(temp[1])
+func replaceGitPath(input string) string {
+       r := regexp.MustCompile("^[ab]/(.*)")
+       temp := [][]byte{}
+       temp = r.FindSubmatch([]byte(input))
+       return string(temp[1])
 }
 
-func isVersion (input string) bool {
-    r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?")
-    return r.Match([]byte(input))
+func isVersion(input string) bool {
+       r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?")
+       return r.Match([]byte(input))
 }
 
-func containsInvalidString (input string) bool {
-    invalidStrings := []string{"(",")","@","origin/","{","}","<",">","$","*"}
-    for _,s := range invalidStrings {
-        if strings.Contains(input,s) {
-            return true
-        }
-    }
-    return false
+func containsInvalidString(input string) bool {
+       invalidStrings := []string{"(", ")", "@", "origin/", "{", "}", "<", ">", "$", "*"}
+       for _, s := range invalidStrings {
+               if strings.Contains(input, s) {
+                       return true
+               }
+       }
+       return false
 }