// 3
}
+func ExampleEncodeRune_outOfRange() {
+ runes := []rune{
+ // Less than 0, out of range.
+ -1,
+ // Greater than 0x10FFFF, out of range.
+ 0x110000,
+ // The Unicode replacement character.
+ utf8.RuneError,
+ }
+ for i, c := range runes {
+ buf := make([]byte, 3)
+ size := utf8.EncodeRune(buf, c)
+ fmt.Printf("%d: %d %[2]s %d\n", i, buf, size)
+ }
+ // Output:
+ // 0: [239 191 189] � 3
+ // 1: [239 191 189] � 3
+ // 2: [239 191 189] � 3
+}
+
func ExampleFullRune() {
buf := []byte{228, 184, 150} // 世
fmt.Println(utf8.FullRune(buf))
}
// EncodeRune writes into p (which must be large enough) the UTF-8 encoding of the rune.
+// If the rune is out of range, it writes the encoding of RuneError.
// It returns the number of bytes written.
func EncodeRune(p []byte, r rune) int {
// Negative values are erroneous. Making it unsigned addresses the problem.