2012-02-17 04:51:04 +00:00
|
|
|
// run
|
2008-07-16 02:19:50 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2011-11-08 23:43:02 +00:00
|
|
|
import "unicode/utf8"
|
2009-01-16 22:58:14 +00:00
|
|
|
|
2008-07-16 02:19:50 +00:00
|
|
|
func main() {
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
var chars [6]rune
|
2010-09-04 00:36:13 +00:00
|
|
|
chars[0] = 'a'
|
|
|
|
chars[1] = 'b'
|
|
|
|
chars[2] = 'c'
|
|
|
|
chars[3] = '\u65e5'
|
|
|
|
chars[4] = '\u672c'
|
|
|
|
chars[5] = '\u8a9e'
|
|
|
|
s := ""
|
2008-07-16 02:19:50 +00:00
|
|
|
for i := 0; i < 6; i++ {
|
2010-09-04 00:36:13 +00:00
|
|
|
s += string(chars[i])
|
2008-07-16 02:19:50 +00:00
|
|
|
}
|
2010-09-04 00:36:13 +00:00
|
|
|
var l = len(s)
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
for w, i, j := 0, 0, 0; i < l; i += w {
|
|
|
|
var r rune
|
2010-09-04 00:36:13 +00:00
|
|
|
r, w = utf8.DecodeRuneInString(s[i:len(s)])
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
if w == 0 {
|
|
|
|
panic("zero width in string")
|
|
|
|
}
|
|
|
|
if r != chars[j] {
|
|
|
|
panic("wrong value from string")
|
|
|
|
}
|
2010-09-04 00:36:13 +00:00
|
|
|
j++
|
2008-07-16 02:19:50 +00:00
|
|
|
}
|
|
|
|
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
|
2010-09-04 00:36:13 +00:00
|
|
|
const L = 12
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
if L != l {
|
|
|
|
panic("wrong length constructing array")
|
|
|
|
}
|
2010-09-04 00:36:13 +00:00
|
|
|
a := make([]byte, L)
|
|
|
|
a[0] = 'a'
|
|
|
|
a[1] = 'b'
|
|
|
|
a[2] = 'c'
|
|
|
|
a[3] = 0xe6
|
|
|
|
a[4] = 0x97
|
|
|
|
a[5] = 0xa5
|
|
|
|
a[6] = 0xe6
|
|
|
|
a[7] = 0x9c
|
|
|
|
a[8] = 0xac
|
|
|
|
a[9] = 0xe8
|
|
|
|
a[10] = 0xaa
|
|
|
|
a[11] = 0x9e
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
for w, i, j := 0, 0, 0; i < L; i += w {
|
|
|
|
var r rune
|
2010-09-04 00:36:13 +00:00
|
|
|
r, w = utf8.DecodeRune(a[i:L])
|
cgo, goyacc, go/build, html, http, path, path/filepath, testing/quick, test: use rune
Nothing terribly interesting here.
R=golang-dev, bradfitz, gri, r
CC=golang-dev
https://golang.org/cl/5300043
2011-10-26 05:20:02 +00:00
|
|
|
if w == 0 {
|
|
|
|
panic("zero width in bytes")
|
|
|
|
}
|
|
|
|
if r != chars[j] {
|
|
|
|
panic("wrong value from bytes")
|
|
|
|
}
|
2010-09-04 00:36:13 +00:00
|
|
|
j++
|
2008-07-16 02:19:50 +00:00
|
|
|
}
|
|
|
|
}
|