Runes
Runes represent Unicode code points in Harneet. A rune is a 32-bit integer value (alias of int32) that encodes a single Unicode scalar value.
Overview
- Runes are 32-bit Unicode code points (alias of int32)
- Literal syntax uses single quotes:
'A','😀','\n' - Supports escape sequences and Unicode escapes
- Arithmetic and comparisons behave like integers
- Use
strings.FromCodePoint(int)to turn a code point into a 1-character string
Rune Literals
Single-quoted rune literals:
Supported Escapes
\n,\t,\r,\\,\',\0\xNN2-digit hex (0..0xFF)\uNNNN4-digit hex\UNNNNNNNN8-digit hex
Arithmetic and Comparison
Runes are integers. You can use them in arithmetic and comparisons.
Printing
fmt.Printf treats runes as integers. Use %d to print the numeric code point.
To convert a code point to a string, use strings.FromCodePoint:
Conversions
- Rune ↔ Int: implicit in most operations (rune is an integer type)
- Rune → String: use
strings.FromCodePoint(int) - String → Rune: use
cast.ToRune(string)for a single-character string
Arrays and Maps of Runes
Notes
- Zero value for
runeis 0. - Valid range is 0..0x10FFFF (Unicode scalar values). Out-of-range values are rejected.