_content/blog/range-functions: trim tailing newline in bytes.Split example

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 <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Ian Lance Taylor 2024-09-07 20:22:49 -07:00 коммит произвёл Gopher Robot
Родитель 4150b91268
Коммит f37ae6b73e
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -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)
}
```