| 
									
										
										
										
											2012-02-16 23:51:04 -05:00
										 |  |  | // run | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07: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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 11:48:19 +11:00
										 |  |  | // Test UTF-8 in strings and character constants. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-08 15:43:02 -08:00
										 |  |  | import "unicode/utf8" | 
					
						
							| 
									
										
										
										
											2009-01-16 14:58:14 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07: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-25 22:20:02 -07:00
										 |  |  | 	var chars [6]rune | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	chars[0] = 'a' | 
					
						
							|  |  |  | 	chars[1] = 'b' | 
					
						
							|  |  |  | 	chars[2] = 'c' | 
					
						
							|  |  |  | 	chars[3] = '\u65e5' | 
					
						
							|  |  |  | 	chars[4] = '\u672c' | 
					
						
							|  |  |  | 	chars[5] = '\u8a9e' | 
					
						
							|  |  |  | 	s := "" | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07:00
										 |  |  | 	for i := 0; i < 6; i++ { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		s += string(chars[i]) | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10: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-25 22:20:02 -07:00
										 |  |  | 	for w, i, j := 0, 0, 0; i < l; i += w { | 
					
						
							|  |  |  | 		var r rune | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10: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-25 22:20:02 -07:00
										 |  |  | 		if w == 0 { | 
					
						
							|  |  |  | 			panic("zero width in string") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if r != chars[j] { | 
					
						
							|  |  |  | 			panic("wrong value from string") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		j++ | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	// encoded as bytes:  'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10: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-25 22:20:02 -07:00
										 |  |  | 	if L != l { | 
					
						
							|  |  |  | 		panic("wrong length constructing array") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10: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-25 22:20:02 -07:00
										 |  |  | 	for w, i, j := 0, 0, 0; i < L; i += w { | 
					
						
							|  |  |  | 		var r rune | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10: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-25 22:20:02 -07:00
										 |  |  | 		if w == 0 { | 
					
						
							|  |  |  | 			panic("zero width in bytes") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if r != chars[j] { | 
					
						
							|  |  |  | 			panic("wrong value from bytes") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		j++ | 
					
						
							| 
									
										
										
										
											2008-07-15 19:19:50 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |