]> Cypherpunks repositories - gostls13.git/commit
strings: document Split{,N,After,AfterN} edge cases
authorAlberto Donizetti <alb.donizetti@gmail.com>
Tue, 6 Jun 2017 09:25:17 +0000 (11:25 +0200)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Tue, 6 Jun 2017 15:48:54 +0000 (15:48 +0000)
commit3a27f28e9b62fc4e7229dbf9b08fbb8f3d65157b
tree875946ae1412d2e3f155b0f709371fc522647a4a
parent2d86f4942868c1309051062237cf4d424d588e9c
strings: document Split{,N,After,AfterN} edge cases

Apparently people get confused by the fact that

  Split("", ",")

returns []{""} instead of []{}.

This is actually just a consequence of the fact that if the separator
sep (2nd argument) is not found the string s (1st argument), then the
Split* functions return a length 1 slice with the string s in it.

Document the general case: if sep is not in s, what you get is a len 1
slice with s in it; unless both s and sep are "", in that case you get
an empty slice of length 0.

Fixes #19726

Change-Id: I64c8220b91acd1e5aa1cc1829199e0cd8c47c404
Reviewed-on: https://go-review.googlesource.com/44950
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/strings/strings.go