Go unicode/utf8: encode and decode UTF-8 runes
Answer: Package utf8 implements functions and constants for text encoded in UTF 8. Helpers translate between runes and UTF 8 byte sequences. Valid reports whether a slice consists of valid UTF 8.
Functions in the package reference
The package implements functions and constants to support text encoded in UTF 8.
Helpers include functions to translate between runes and UTF 8 byte sequences.
RuneCount returns the number of runes in p. RuneLen returns the number of bytes required to encode the rune.
Valid reports whether p consists entirely of valid UTF 8 encoded runes. DecodeRune unpacks the first UTF 8 encoding in p.
The source comment
The source comment describes functions and constants to support text encoded in UTF 8.
Defining constants locally avoids this package depending on package unicode.
The conditions for RuneError and MaxRune are verified in the tests.
AppendRune appends the UTF 8 encoding of a rune to a slice.
See also
Claims
- id: C1 claim: The package implements functions and constants for UTF-8 text. source: S1 evidence: "functions and constants to support text encoded in UTF-8"
- id: C2 claim: It includes functions to translate between runes and UTF-8 byte sequences. source: S1 evidence: "translate between runes and UTF-8 byte sequences"
- id: C3 claim: The source comment covers functions and constants for UTF-8 text. source: S2 evidence: "Package utf8 implements functions and constants to support text encoded in"
- id: C4 claim: The next line includes functions to translate between runes and UTF-8 bytes. source: S2 evidence: "functions to translate between runes and UTF-8 byte sequences"
Sources
- [S1] unicode/utf8 package reference. Go. https://pkg.go.dev/unicode/utf8 . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] unicode/utf8 source. Go. https://go.dev/src/unicode/utf8/utf8.go . License: BSD-3-Clause. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, unicode/utf8 package reference; Go, unicode/utf8 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, unicode/utf8 package reference; Go, unicode/utf8 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go unicode/utf8: encode and decode UTF-8 runes." iinventedlight Library, iil:note:zesmmvjt, version of 2026-11-23. https://iinventedlight.com/library/notes/go-unicode-utf8/. License: CC-BY-4.0.
@misc{iil_note_zesmmvjt,
author = {{iinventedlight}},
title = {{Go unicode/utf8: encode and decode UTF-8 runes}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-unicode-utf8/},
note = {Permanent ID iil:note:zesmmvjt. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-unicode-utf8.schema.json (schema; CC-BY-4.0)
- go-unicode-utf8.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-unicode-utf8.md.