gopkg.in/alecthomas/gometalinter.v3@v3.0.0/_linters/src/github.com/kisielk/gotool/internal/load/path.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build go1.9
     6  
     7  package load
     8  
     9  import (
    10  	"strings"
    11  )
    12  
    13  // hasPathPrefix reports whether the path s begins with the
    14  // elements in prefix.
    15  func hasPathPrefix(s, prefix string) bool {
    16  	switch {
    17  	default:
    18  		return false
    19  	case len(s) == len(prefix):
    20  		return s == prefix
    21  	case len(s) > len(prefix):
    22  		if prefix != "" && prefix[len(prefix)-1] == '/' {
    23  			return strings.HasPrefix(s, prefix)
    24  		}
    25  		return s[len(prefix)] == '/' && s[:len(prefix)] == prefix
    26  	}
    27  }