From b04f3b06ec347543b0eafe82dcfb0e05885d3feb Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Tue, 22 Dec 2015 02:40:47 -0500 Subject: all: replace strings.Index with strings.Contains where possible Change-Id: Ia613f1c37bfce800ece0533a5326fca91d99a66a Reviewed-on: https://go-review.googlesource.com/18120 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer --- src/path/filepath/match.go | 4 ++-- src/path/filepath/match_test.go | 2 +- src/path/match.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/path') diff --git a/src/path/filepath/match.go b/src/path/filepath/match.go index 89f16de355..d64bf84fc0 100644 --- a/src/path/filepath/match.go +++ b/src/path/filepath/match.go @@ -49,7 +49,7 @@ Pattern: star, chunk, pattern = scanChunk(pattern) if star && chunk == "" { // Trailing * matches rest of string unless it has a /. - return strings.Index(name, string(Separator)) < 0, nil + return !strings.Contains(name, string(Separator)), nil } // Look for match at current position. t, ok, err := matchChunk(chunk, name) @@ -305,5 +305,5 @@ func glob(dir, pattern string, matches []string) (m []string, e error) { // recognized by Match. func hasMeta(path string) bool { // TODO(niemeyer): Should other magic characters be added here? - return strings.IndexAny(path, "*?[") >= 0 + return strings.ContainsAny(path, "*?[") } diff --git a/src/path/filepath/match_test.go b/src/path/filepath/match_test.go index 0edbfc70c4..d8bab7f4da 100644 --- a/src/path/filepath/match_test.go +++ b/src/path/filepath/match_test.go @@ -88,7 +88,7 @@ func TestMatch(t *testing.T) { pattern := tt.pattern s := tt.s if runtime.GOOS == "windows" { - if strings.Index(pattern, "\\") >= 0 { + if strings.Contains(pattern, "\\") { // no escape allowed on windows. continue } diff --git a/src/path/match.go b/src/path/match.go index 75dd3b38e7..8d9aa513b1 100644 --- a/src/path/match.go +++ b/src/path/match.go @@ -43,7 +43,7 @@ Pattern: star, chunk, pattern = scanChunk(pattern) if star && chunk == "" { // Trailing * matches rest of string unless it has a /. - return strings.Index(name, "/") < 0, nil + return !strings.Contains(name, "/"), nil } // Look for match at current position. t, ok, err := matchChunk(chunk, name) -- cgit v1.3-5-g9baa