]> Sergey Matveev's repositories - path-extractor.git/blobdiff - validators.go
Tests workability
[path-extractor.git] / validators.go
index 60811fc430d3c6ee3409837c83c9df36bd9687c7..df6daf5c5a1f74750050fbd947ba495baef616b2 100644 (file)
@@ -1,46 +1,97 @@
-package main
+package pathextractor
 
-import "strings"
-import "regexp"
+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 stringInSlice(str string, list []string) bool {
+       for _, v := range list {
+               if v == str {
+                       return true
+               }
+       }
+       return false
 }
 
-func isGitPath (input string) bool {
-    r := regexp.MustCompile("^[ab]/")
-    return r.Match([]byte(input))
+func isGitRange(input string) bool {
+       r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}")
+       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 isGitPath(input string) bool {
+       r := regexp.MustCompile("^[ab]/")
+       return r.Match([]byte(input))
 }
 
-func isGitInstruction (input string) bool {
-    r := regexp.MustCompile("\\.{3,}")
-    return r.Match([]byte(input))
+func isEmail(input string) bool {
+       r := regexp.MustCompile("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+([a-zA-Z]{2,4})")
+       result := r.FindSubmatch([]byte(input))
+       if result == nil {
+               return false
+       }
+       fileExtensions := []string{"png", "bmp", "jpeg"}
+       return !stringInSlice(string(result[1]), fileExtensions)
 }
 
-func replaceGitPath (input string) string {
-    r := regexp.MustCompile("^[ab]/(.*)")
-    temp := [][]byte{}
-    temp = r.FindSubmatch([]byte(input))
-    return string(temp[1])
+func isDate(input string) bool {
+       r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+")
+       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 isGitInstruction(input string) bool {
+       r := regexp.MustCompile("\\.{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 replaceGitPath(input string) string {
+       r := regexp.MustCompile("^[ab]/(.*)")
+       temp := [][]byte{}
+       temp = r.FindSubmatch([]byte(input))
+       return string(temp[1])
+}
+
+func isIp(input string) bool {
+       r := regexp.MustCompile("^[0-9]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}$")
+       return r.Match([]byte(input))
+}
+
+func isVersion(input string) bool {
+       r := regexp.MustCompile("^v?[0-9x]{1,3}\\.[0-9x]{1,3}(\\.[0-9x]{1,3})?$")
+       return r.Match([]byte(input))
+}
+
+func isSpace(input string) bool {
+       r := regexp.MustCompile("^[0-9]*\\.[0-9]+[MGK]$")
+       return r.Match([]byte(input))
+}
+
+func startsWithInvalidString(input string) bool {
+       invalidBeginnings := []string{"Error/", "Object.", "Array."}
+       for _, s := range invalidBeginnings {
+               if strings.Index(input, s) == 0 {
+                       return true
+               }
+       }
+       return false
+}
+
+func endsWithInvalidString(input string) bool {
+       invalidEndings := []string{"."}
+       for _, s := range invalidEndings {
+               if strings.LastIndex(input, s) == len(input)-len(s) {
+                       return true
+               }
+       }
+       return false
+}
+
+func containsInvalidString(input string) bool {
+       invalidStrings := []string{"//", "()", "and/or", "remotes/", "origin/", "{", "}", "<", ">", "$", "*", "this."}
+       for _, s := range invalidStrings {
+               if strings.Contains(input, s) {
+                       return true
+               }
+       }
+       return false
 }