From a3868028ac8470d1ab7782614707bb90925e7fe3 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 18 Sep 2020 21:01:34 +0300 Subject: unicode/utf8: document the handling of runes out of range in EncodeRune Document the way EncodeRune currently handles runes which are out of range. Also add an example showing that behaviour. Change-Id: I0f8e7645ae053474ec319085a2bb6d7f73bc137c Reviewed-on: https://go-review.googlesource.com/c/go/+/255998 Reviewed-by: Rob Pike Reviewed-by: Giovanni Bajo Trust: Giovanni Bajo Run-TryBot: Giovanni Bajo TryBot-Result: Go Bot --- src/unicode/utf8/utf8.go | 1 + 1 file changed, 1 insertion(+) (limited to 'src/unicode/utf8/utf8.go') diff --git a/src/unicode/utf8/utf8.go b/src/unicode/utf8/utf8.go index ef0d740960..557e8a7770 100644 --- a/src/unicode/utf8/utf8.go +++ b/src/unicode/utf8/utf8.go @@ -337,6 +337,7 @@ func RuneLen(r rune) int { } // 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. -- cgit v1.3