Skip to content

Commit

Permalink
_content/blog/range-functions: trim tailing newline in bytes.Split ex…
Browse files Browse the repository at this point in the history
…ample

Otherwise we get a trailing blank line, which is not what we want.

Pointed out by dmitshur in CL 611655.

Change-Id: I6c2c0cbc6e19c06d392ce6e6fd108163020bd124
Reviewed-on: https://go-review.googlesource.com/c/website/+/610565
Commit-Queue: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Sep 9, 2024
1 parent 4150b91 commit f37ae6b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion _content/blog/range-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,9 @@ the lines in a byte slice.
This is easy to write and fairly efficient.

```
for _, line := range bytes.Split(data, []byte{'\n'}) {
nl := []byte{'\n'}
// Trim a trailing newline to avoid a final empty blank line.
for _, line := range bytes.Split(bytes.TrimSuffix(data, nl), nl) {
handleLine(line)
}
```
Expand Down

0 comments on commit f37ae6b

Please sign in to comment.