mirror of
https://github.com/golang/go
synced 2024-11-21 22:14:41 -07:00
go spec: introduce rune type
R=r, iant, rsc, r CC=golang-dev https://golang.org/cl/5293048
This commit is contained in:
parent
2e79e8e549
commit
b910a27396
@ -1,5 +1,5 @@
|
|||||||
<!-- title The Go Programming Language Specification -->
|
<!-- title The Go Programming Language Specification -->
|
||||||
<!-- subtitle Version of October 17, 2011 -->
|
<!-- subtitle Version of October 25, 2011 -->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
TODO
|
TODO
|
||||||
@ -691,7 +691,8 @@ float64 the set of all IEEE-754 64-bit floating-point numbers
|
|||||||
complex64 the set of all complex numbers with float32 real and imaginary parts
|
complex64 the set of all complex numbers with float32 real and imaginary parts
|
||||||
complex128 the set of all complex numbers with float64 real and imaginary parts
|
complex128 the set of all complex numbers with float64 real and imaginary parts
|
||||||
|
|
||||||
byte familiar alias for uint8
|
byte alias for uint8
|
||||||
|
rune alias for int (will change to int32 in the future)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -711,7 +712,9 @@ uintptr an unsigned integer large enough to store the uninterpreted bits of a p
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
To avoid portability issues all numeric types are distinct except
|
To avoid portability issues all numeric types are distinct except
|
||||||
<code>byte</code>, which is an alias for <code>uint8</code>.
|
<code>byte</code>, which is an alias for <code>uint8</code>, and
|
||||||
|
<code>rune</code>, which is an alias for <code>int</code> (to become
|
||||||
|
<code>int32</code> in a later version of Go).
|
||||||
Conversions
|
Conversions
|
||||||
are required when different numeric types are mixed in an expression
|
are required when different numeric types are mixed in an expression
|
||||||
or assignment. For instance, <code>int32</code> and <code>int</code>
|
or assignment. For instance, <code>int32</code> and <code>int</code>
|
||||||
@ -1497,7 +1500,7 @@ The following identifiers are implicitly declared in the universe block:
|
|||||||
<pre class="grammar">
|
<pre class="grammar">
|
||||||
Basic types:
|
Basic types:
|
||||||
bool byte complex64 complex128 float32 float64
|
bool byte complex64 complex128 float32 float64
|
||||||
int8 int16 int32 int64 string uint8 uint16 uint32 uint64
|
int8 int16 int32 int64 rune string uint8 uint16 uint32 uint64
|
||||||
|
|
||||||
Architecture-specific convenience types:
|
Architecture-specific convenience types:
|
||||||
int uint uintptr
|
int uint uintptr
|
||||||
@ -1509,7 +1512,7 @@ Zero value:
|
|||||||
nil
|
nil
|
||||||
|
|
||||||
Functions:
|
Functions:
|
||||||
append cap close complex copy imag len
|
append cap close complex copy delete imag len
|
||||||
make new panic print println real recover
|
make new panic print println real recover
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -1791,11 +1794,15 @@ constant:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
var b = true // t has type bool
|
var b = true // t has type bool
|
||||||
var i = 0 // i has type int
|
var r = 'a' // r has type int
|
||||||
var f = 3.0 // f has type float64
|
var i = 0 // i has type int
|
||||||
var c = 1i // c has type complex128
|
var f = 3.0 // f has type float64
|
||||||
var s = "OMDB" // s has type string
|
var c0 = 0i // c0 has type complex128
|
||||||
|
var c1 = 1 + 0i // c1 has type complex128
|
||||||
|
var c2 = 1 + 1i // c2 has type complex128
|
||||||
|
var s1 = "OMDB" // s1 has type string
|
||||||
|
var s2 = `foo` // s2 has type string
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h3 id="Short_variable_declarations">Short variable declarations</h3>
|
<h3 id="Short_variable_declarations">Short variable declarations</h3>
|
||||||
@ -3276,11 +3283,11 @@ in any of these cases:
|
|||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<code>x</code> is an integer or has type <code>[]byte</code> or
|
<code>x</code> is an integer or has type <code>[]byte</code> or
|
||||||
<code>[]int</code> and <code>T</code> is a string type.
|
<code>[]rune</code> and <code>T</code> is a string type.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<code>x</code> is a string and <code>T</code> is <code>[]byte</code> or
|
<code>x</code> is a string and <code>T</code> is <code>[]byte</code> or
|
||||||
<code>[]int</code>.
|
<code>[]rune</code>.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -3354,9 +3361,8 @@ MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
Converting a value of type <code>[]byte</code> (or
|
Converting a value of type <code>[]byte</code> to a string type yields
|
||||||
the equivalent <code>[]uint8</code>) to a string type yields a
|
a string whose successive bytes are the elements of the slice. If
|
||||||
string whose successive bytes are the elements of the slice. If
|
|
||||||
the slice value is <code>nil</code>, the result is the empty string.
|
the slice value is <code>nil</code>, the result is the empty string.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -3365,12 +3371,13 @@ string([]byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
Converting a value of type <code>[]int</code> to a string type yields
|
Converting a value of type <code>[]rune</code> to a string type yields
|
||||||
a string that is the concatenation of the individual integers
|
a string that is the concatenation of the individual rune values
|
||||||
converted to strings. If the slice value is <code>nil</code>, the
|
converted to strings. If the slice value is <code>nil</code>, the
|
||||||
result is the empty string.
|
result is the empty string.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
string([]int{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
|
string([]rune{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
|
||||||
</pre>
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
@ -3385,11 +3392,11 @@ If the string is empty, the result is <code>[]byte(nil)</code>.
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
Converting a value of a string type to <code>[]int</code> yields a
|
Converting a value of a string type to <code>[]rune</code> yields a
|
||||||
slice containing the individual Unicode code points of the string.
|
slice containing the individual Unicode code points of the string.
|
||||||
If the string is empty, the result is <code>[]int(nil)</code>.
|
If the string is empty, the result is <code>[]rune(nil)</code>.
|
||||||
<pre>
|
<pre>
|
||||||
[]int(MyString("白鵬翔")) // []int{0x767d, 0x9d6c, 0x7fd4}
|
[]rune(MyString("白鵬翔")) // []rune{0x767d, 0x9d6c, 0x7fd4}
|
||||||
</pre>
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
@ -4059,7 +4066,7 @@ For each iteration, iteration values are produced as follows:
|
|||||||
Range expression 1st value 2nd value (if 2nd variable is present)
|
Range expression 1st value 2nd value (if 2nd variable is present)
|
||||||
|
|
||||||
array or slice a [n]E, *[n]E, or []E index i int a[i] E
|
array or slice a [n]E, *[n]E, or []E index i int a[i] E
|
||||||
string s string type index i int see below int
|
string s string type index i int see below rune
|
||||||
map m map[K]V key k K m[k] V
|
map m map[K]V key k K m[k] V
|
||||||
channel c chan E element e E
|
channel c chan E element e E
|
||||||
</pre>
|
</pre>
|
||||||
@ -4077,7 +4084,7 @@ or slice itself. For a <code>nil</code> slice, the number of iterations is 0.
|
|||||||
For a string value, the "range" clause iterates over the Unicode code points
|
For a string value, the "range" clause iterates over the Unicode code points
|
||||||
in the string starting at byte index 0. On successive iterations, the index value will be the
|
in the string starting at byte index 0. On successive iterations, the index value will be the
|
||||||
index of the first byte of successive UTF-8-encoded code points in the string,
|
index of the first byte of successive UTF-8-encoded code points in the string,
|
||||||
and the second value, of type <code>int</code>, will be the value of
|
and the second value, of type <code>rune</code>, will be the value of
|
||||||
the corresponding code point. If the iteration encounters an invalid
|
the corresponding code point. If the iteration encounters an invalid
|
||||||
UTF-8 sequence, the second value will be <code>0xFFFD</code>,
|
UTF-8 sequence, the second value will be <code>0xFFFD</code>,
|
||||||
the Unicode replacement character, and the next iteration will advance
|
the Unicode replacement character, and the next iteration will advance
|
||||||
|
Loading…
Reference in New Issue
Block a user