_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:
Родитель
4150b91268
Коммит
f37ae6b73e
|
@ -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)
|
||||
}
|
||||
```
|
||||
|
|
Загрузка…
Ссылка в новой задаче