diff options
Diffstat (limited to 'src/strings/strings.go')
| -rw-r--r-- | src/strings/strings.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/strings/strings.go b/src/strings/strings.go index 367e0a8e24..70297f1e69 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -1289,3 +1289,14 @@ func CutPrefix(s, prefix string) (after string, found bool) { func CutSuffix(s, suffix string) (before string, found bool) { return stringslite.CutSuffix(s, suffix) } + +// CutLast slices s around the last instance of sep, +// returning the text before and after sep. +// The found result reports whether sep appears in s. +// If sep does not appear in s, CutLast returns s, "", false. +func CutLast(s, sep string) (before, after string, found bool) { + if i := LastIndex(s, sep); i >= 0 { + return s[:i], s[i+len(sep):], true + } + return s, "", false +} |
