URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [utf.go] - Rev 700
Compare with Previous | Blame | View Log
// $G $F.go && $L $F.$A && ./$A.out// 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 mainimport "unicode/utf8"func main() {var chars [6]runechars[0] = 'a'chars[1] = 'b'chars[2] = 'c'chars[3] = '\u65e5'chars[4] = '\u672c'chars[5] = '\u8a9e's := ""for i := 0; i < 6; i++ {s += string(chars[i])}var l = len(s)for w, i, j := 0, 0, 0; i < l; i += w {var r runer, w = utf8.DecodeRuneInString(s[i:len(s)])if w == 0 {panic("zero width in string")}if r != chars[j] {panic("wrong value from string")}j++}// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9econst L = 12if L != l {panic("wrong length constructing array")}a := make([]byte, L)a[0] = 'a'a[1] = 'b'a[2] = 'c'a[3] = 0xe6a[4] = 0x97a[5] = 0xa5a[6] = 0xe6a[7] = 0x9ca[8] = 0xaca[9] = 0xe8a[10] = 0xaaa[11] = 0x9efor w, i, j := 0, 0, 0; i < L; i += w {var r runer, w = utf8.DecodeRune(a[i:L])if w == 0 {panic("zero width in bytes")}if r != chars[j] {panic("wrong value from bytes")}j++}}
