mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package strs contains string-related utility funcs.
|
|
package strs
|
|
|
|
import "strings"
|
|
|
|
// CutPrefix returns s without the provided leading prefix string
|
|
// and reports whether it found the prefix.
|
|
// If s doesn't start with prefix, CutPrefix returns s, false.
|
|
// If prefix is the empty string, CutPrefix returns s, true.
|
|
//
|
|
// TODO: remove this once Go 1.20 is out with it.
|
|
// See https://github.com/tailscale/tailscale/issues/5309
|
|
func CutPrefix(s, prefix string) (after string, found bool) {
|
|
if !strings.HasPrefix(s, prefix) {
|
|
return s, false
|
|
}
|
|
return s[len(prefix):], true
|
|
}
|
|
|
|
// CutSuffix returns s without the provided ending suffix string
|
|
// and reports whether it found the suffix.
|
|
// If s doesn't end with suffix, CutSuffix returns s, false.
|
|
// If suffix is the empty string, CutSuffix returns s, true.
|
|
//
|
|
// See https://github.com/tailscale/tailscale/issues/5309
|
|
// TODO: remove this once Go 1.20 is out with it.
|
|
func CutSuffix(s, suffix string) (before string, found bool) {
|
|
if !strings.HasSuffix(s, suffix) {
|
|
return s, false
|
|
}
|
|
return s[:len(s)-len(suffix)], true
|
|
}
|