Standard library / unicode/utf16
utf16.Decode()
Converts UTF-16 code units to runes, replacing unpaired surrogates with U+FFFD. Input is code units, not encoded bytes. Expected stdout: '[U+1F600 U+FFFD]\n'.
Formal Syntax & Structure
go syntaxgo
func Decode(s []uint16) []runeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []uint16 | Input UTF-16 code units to decode. |
Return Value
[]rune
Converts UTF-16 code units to runes, replacing unpaired surrogates with U+FFFD. Input is code units, not encoded bytes.
Working Example
Example Snippetgo
package main
import ( "fmt" "unicode/utf16")
func main() { fmt.Printf("%U\n", utf16.Decode([]uint16{0xd83d, 0xde00, 0xd800}))}