diff options
| author | apocelipes <seve3r@outlook.com> | 2024-05-03 08:36:03 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-03 16:48:16 +0000 |
| commit | 10c035acd669271dc37b9e5354b30ec939ff7c84 (patch) | |
| tree | c4565bf1105c647fd54e1d9a6e5236d2c28e4a8f /src/internal/stringslite/strings.go | |
| parent | 0bc093a1aae4fb5e101fae815fe6673e9180923e (diff) | |
| download | go-10c035acd669271dc37b9e5354b30ec939ff7c84.tar.xz | |
strings: move TrimPrefix and TrimSuffix to stringslite
To help packages use these functions like "os" which using
the copied function "stringsTrimSuffix".
Change-Id: I223028ed264c7b7e95534b4883223af0988cda68
GitHub-Last-Rev: 2fd8fbf5286e5a4abdb03704d69f02e32d3f1a6b
GitHub-Pull-Request: golang/go#67151
Reviewed-on: https://go-review.googlesource.com/c/go/+/583075
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: qiu laidongfeng2 <2645477756@qq.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/internal/stringslite/strings.go')
| -rw-r--r-- | src/internal/stringslite/strings.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/internal/stringslite/strings.go b/src/internal/stringslite/strings.go index ce8a913297..c0c6e2dce5 100644 --- a/src/internal/stringslite/strings.go +++ b/src/internal/stringslite/strings.go @@ -122,3 +122,17 @@ func CutSuffix(s, suffix string) (before string, found bool) { } return s[:len(s)-len(suffix)], true } + +func TrimPrefix(s, prefix string) string { + if HasPrefix(s, prefix) { + return s[len(prefix):] + } + return s +} + +func TrimSuffix(s, suffix string) string { + if HasSuffix(s, suffix) { + return s[:len(s)-len(suffix)] + } + return s +} |
