From: Edgar HIPP Date: Sun, 30 Aug 2015 15:06:59 +0000 (+0200) Subject: Correct surrounded by parens X-Git-Url: http://www.git.stargrave.org/?p=path-extractor.git;a=commitdiff_plain;h=feba31d0851fee86d73575955c5f1806094bc59a Correct surrounded by parens --- diff --git a/extractor.go b/extractor.go index 6a87ab4..ac819dc 100644 --- a/extractor.go +++ b/extractor.go @@ -10,6 +10,21 @@ func pathExtractor(input string) [][][]byte { return temp } +func stripParens(input string) string { + r := regexp.MustCompile("^\\((.*)\\)$") + temp := [][]byte{} + temp = r.FindSubmatch([]byte(input)) + if len(temp) <= 1 { + return input + } + return string(temp[1]) +} + +func postProcess(input string) string { + input = stripParens(input) + return input +} + func GetAllMatches(input string) []string { matches := [][][]byte{} result := []string{} @@ -23,7 +38,7 @@ func GetAllMatches(input string) []string { if isGitPath(s) { s = replaceGitPath(s) } - result = append(result, s) + result = append(result, postProcess(s)) } return result } diff --git a/pe_test.go b/pe_test.go index 844a0e5..6038afe 100644 --- a/pe_test.go +++ b/pe_test.go @@ -82,6 +82,9 @@ func TestGitIgnore(t *testing.T) { if len(output) != 1 { t.Errorf("Doesnt match surrounded by parens", output) } + if output[0] != "user.js" { + t.Errorf("matches surrounded by parens badly", output) + } output = GetAllMatches("var/") if len(output) != 1 {