Use strings to simplify the code.
This is a follow-up for the CL 586715.
Change-Id: I9e5470ec271e8af1ad4ddbb5f01f43a8a4879557
GitHub-Last-Rev:
b95d6179781053ea8ec9fc8ad2e18607fd35c5bb
GitHub-Pull-Request: golang/go#68713
Reviewed-on: https://go-review.googlesource.com/c/go/+/602697
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
}
func split(name string) (dir, elem string, isDir bool) {
- if len(name) > 0 && name[len(name)-1] == '/' {
- isDir = true
- name = name[:len(name)-1]
- }
- i := len(name) - 1
- for i >= 0 && name[i] != '/' {
- i--
- }
+ name, isDir = strings.CutSuffix(name, "/")
+ i := strings.LastIndexByte(name, '/')
if i < 0 {
return ".", name, isDir
}
}
func embedFileNameSplit(name string) (dir, elem string, isDir bool) {
- if name[len(name)-1] == '/' {
- isDir = true
- name = name[:len(name)-1]
- }
- i := len(name) - 1
- for i >= 0 && name[i] != '/' {
- i--
- }
+ name, isDir = strings.CutSuffix(name, "/")
+ i := strings.LastIndexByte(name, '/')
if i < 0 {
return ".", name, isDir
}