~pedronis/+junk/scratch.go

« back to all changes in this revision

Viewing changes to xff.go

  • Committer: Samuele Pedroni (Canonical Services Ltd.)
  • Date: 2013-11-17 16:06:44 UTC
  • Revision ID: samuele.pedroni@canonical.com-20131117160644-kqjrvcv5pvcv3s8o
 how non-utf8 runs can live in strings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package main
 
2
 
 
3
import (
 
4
        "fmt"
 
5
        "unicode/utf8"
 
6
)
 
7
 
 
8
func main() {
 
9
        var a [10]byte
 
10
        a[0] = 0xff
 
11
        s := string(a[:1])
 
12
        fmt.Println(a)
 
13
        fmt.Println(s)
 
14
        r, i := utf8.DecodeRuneInString(s)
 
15
        fmt.Println(r == utf8.RuneError, i)
 
16
        fmt.Println([]byte(s))
 
17
}