diff options
author | Robert Griesemer <gri@golang.org> | 2010-10-25 16:41:06 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2010-10-25 16:41:06 -0700 |
commit | 425bbadd3cc77581f3a4d767895b0e35c1fb6ca5 (patch) | |
tree | 7dd0e97e72f2f0bdd2c87633db391e631daa5144 | |
parent | 079cbddbd83f996cfd5b79ea38c96c5061efa85b (diff) | |
download | go-425bbadd3cc77581f3a4d767895b0e35c1fb6ca5.tar.gz go-425bbadd3cc77581f3a4d767895b0e35c1fb6ca5.zip |
go_spec: allow copy() to copy bytes from a string into a []byte
(language change as discussed a while ago)
R=iant, ken2, r, rsc
CC=golang-dev
https://golang.org/cl/2716041
-rw-r--r-- | doc/go_spec.html | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index 41368309de..fc47ae825d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ <!-- title The Go Programming Language Specification --> -<!-- subtitle Version of Oct 21, 2010 --> +<!-- subtitle Version of Oct 25, 2010 --> <!-- TODO @@ -4534,13 +4534,17 @@ The built-in function <code>copy</code> copies slice elements from a source <code>src</code> to a destination <code>dst</code> and returns the number of elements copied. Source and destination may overlap. Both arguments must have <a href="#Type_identity">identical</a> element type <code>T</code> and must be -<a href="#Assignability">assignable</a> to a slice -of type <code>[]T</code>. The number of arguments copied is the minimum of +<a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>. +The number of arguments copied is the minimum of <code>len(src)</code> and <code>len(dst)</code>. +As a special case, <code>copy</code> also accepts a destination argument assignable +to type <code>[]byte</code> with a source argument of a string type. +This form copies the bytes from the string into the byte slice. </p> <pre class="grammar"> copy(dst, src []T) int +copy(dst []byte, src string) int </pre> <p> @@ -4550,8 +4554,10 @@ Examples: <pre> var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7} var s = make([]int, 6) -n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5} -n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5} +var b = make([]byte, 5) +n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5} +n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5} +n3 := copy(b, "Hello, World!") // n3 == 5, b == []byte("Hello") </pre> <h3 id="Complex_numbers">Assembling and disassembling complex numbers</h3> |