git-codereview: use strings.Cut

Basic cut functionality is available in the standard library as of
Go 1.18, so today's supported Go versions (1.21 & 1.20) can use it.

Also simplify some slice and map code while here.

Change-Id: Ie887fc2dad542cd9a830974cf9c8373baa81ad8b
Reviewed-on: https://go-review.googlesource.com/c/review/+/531955
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/git-codereview/gofmt.go b/git-codereview/gofmt.go
index ca5f798..1df3e43 100644
--- a/git-codereview/gofmt.go
+++ b/git-codereview/gofmt.go
@@ -253,9 +253,7 @@
 		}
 	}
 	if flags&gofmtCommand != 0 {
-		for _, file := range localFiles {
-			args = append(args, file)
-		}
+		args = append(args, localFiles...)
 	}
 
 	if *verbose > 1 {
diff --git a/git-codereview/reword.go b/git-codereview/reword.go
index 5948502..8f12405 100644
--- a/git-codereview/reword.go
+++ b/git-codereview/reword.go
@@ -142,11 +142,11 @@
 			text = "# " + text // restore split separator
 
 			// Pull out # hash header line and body.
-			hdr, body, _ := cut(text, "\n")
+			hdr, body, _ := strings.Cut(text, "\n")
 
 			// Cut blank lines at start and end of body but keep newline-terminated.
 			for body != "" {
-				line, rest, _ := cut(body, "\n")
+				line, rest, _ := strings.Cut(body, "\n")
 				if line != "" {
 					break
 				}
@@ -221,14 +221,6 @@
 	run("git", "reset", "--soft", newHash)
 }
 
-func cut(s, sep string) (before, after string, ok bool) {
-	i := strings.Index(s, sep)
-	if i < 0 {
-		return s, "", false
-	}
-	return s[:i], s[i+len(sep):], true
-}
-
 var rewordProlog = `Rewording multiple commit messages.
 The # lines separate the different commits and must be left unchanged.
 `
diff --git a/git-codereview/submit_test.go b/git-codereview/submit_test.go
index 29f9c02..3e18fd8 100644
--- a/git-codereview/submit_test.go
+++ b/git-codereview/submit_test.go
@@ -250,12 +250,12 @@
 	cl1 := GerritChange{
 		Status:          "NEW",
 		CurrentRevision: hash1,
-		Labels:          map[string]*GerritLabel{"Code-Review": &GerritLabel{Approved: new(GerritAccount)}},
+		Labels:          map[string]*GerritLabel{"Code-Review": {Approved: new(GerritAccount)}},
 	}
 	cl2 := GerritChange{
 		Status:          "NEW",
 		CurrentRevision: hash2,
-		Labels:          map[string]*GerritLabel{"Code-Review": &GerritLabel{Approved: new(GerritAccount)}},
+		Labels:          map[string]*GerritLabel{"Code-Review": {Approved: new(GerritAccount)}},
 	}
 
 	srv.setReply("/a/changes/proj~main~I0000001", gerritReply{f: func() gerritReply {