Add utils.

This commit is contained in:
Amy Boyd
2016-06-22 23:06:09 +01:00
parent 16490522ea
commit e21711568e
2 changed files with 47 additions and 0 deletions

30
editorconfig/utils.go Normal file
View File

@@ -0,0 +1,30 @@
package editorconfig
import (
"fmt"
"os"
"path/filepath"
"regexp"
)
var filePathSeparatorRegex = regexp.QuoteMeta(string(filepath.Separator))
var endOfPathRegex, _ = regexp.Compile(`[` + filePathSeparatorRegex + `][^` + filePathSeparatorRegex + `]+$`)
func GetParentDir(path string) string {
return endOfPathRegex.ReplaceAllString(path, "")
}
func ContainsString(haystack []string, needle string) bool {
for _, s := range haystack {
if s == needle {
return true
}
}
return false
}
func ExitBecauseOfInternalError(err string) {
fmt.Println(err)
os.Exit(2)
}