← All notes

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

Sources

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

Permanent ID: iil:note:zesmmvjt

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.},
}

Markdown

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.

All artifact files (JSON index)

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.