Skip to content

Commit 139e2f2

Browse files
committed
tidy: use strings.Cut over strings.IndexByte and manual slicing
1 parent 468a8c9 commit 139e2f2

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

cli_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ func TestParsing(t *testing.T) {
379379
cmd: NewCmd("cp").
380380
Opt(NewOpt("aa").
381381
WithParser(func(s string) (any, error) {
382-
comma := strings.IndexByte(s, ',')
383-
x, _ := strconv.Atoi(s[:comma])
384-
y, _ := strconv.Atoi(s[comma+1:])
382+
xStr, yStr, _ := strings.Cut(s, ",")
383+
x, _ := strconv.Atoi(xStr)
384+
y, _ := strconv.Atoi(yStr)
385385
return image.Point{X: x, Y: y}, nil
386386
})),
387387
variations: []testInputOutput{

examples_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,12 @@ func ExampleInputInfo_ShortOnly() {
495495
}
496496

497497
func ExampleInputInfo_WithParser() {
498+
// This is a horrible parsing function for coordinates.
499+
// It's just for example purposes.
498500
pointParser := func(s string) (any, error) {
499-
comma := strings.IndexByte(s, ',')
500-
x, _ := strconv.Atoi(s[:comma])
501-
y, _ := strconv.Atoi(s[comma+1:])
501+
xStr, yStr, _ := strings.Cut(s, ",")
502+
x, _ := strconv.Atoi(xStr)
503+
y, _ := strconv.Atoi(yStr)
502504
return image.Point{X: x, Y: y}, nil
503505
}
504506

0 commit comments

Comments
 (0)