Runes
A rune, rune
, is an unsigned 32-bit integer representing a Unicode code point.
-
$rune(arg: i64) -> rune
-
Converts
arg
to arune
. Panics if the argument is out of range.
Rune Literals
Rune literals use single quotes, e.g.
var c1 = 'a'; var c2 = '€'; var c3 = '🔥';
A rune literal should contain either a single UTF-8 encoded code point or a backslashed escape sequence representing a code point, e.g.
assert '\x61' == 'a'; assert '\u20AC' == '€';
Rune literals support the same backslashed escape sequences as strings.
Conversions
You can convert a rune to a string using the $str()
function — this returns a string containing the UTF-8 encoded representation of the code point, e.g.
assert $str('a') == "a"; assert $str('a') == "\x61"; assert $str('🔥') == "🔥"; assert $str('🔥') == "\xF0\x9F\x94\xA5";
You can convert a rune to an integer using the $i64()
function:
assert $i64('a') == 97;
You can convert an integer to a rune using the $rune()
function:
assert $rune(97) == 'a';
Concatenating
If you add two runes together using the +
operator, the result will be a UTF-8 encoded string, e.g.
assert 'x' + 'y' == "xy";
Similarly, you can prepend or append a rune to a string using the +
operator, e.g.
assert 'x' + "yz" == "xyz"; assert "xy" + 'z' == "xyz";
You can multiply a rune by an integer n
to produce a string containing n
UTF-8 encoded copies of the rune, e.g.
assert 'x' * 3 == "xxx"; assert '🔥' * 3 == "🔥🔥🔥";
Methods
-
:is_ascii() -> bool
-
Returns
true
if the rune is in the ASCII range. -
:is_ascii_alpha() -> bool
-
Returns
true
if the rune is in the range of ASCII alphabetical characters. -
:is_ascii_decimal() -> bool
-
Returns
true
if the rune is an ASCII decimal digit. -
:is_ascii_hex() -> bool
-
Returns
true
if the rune is an ASCII hexadecimal digit. -
:is_ascii_octal() -> bool
-
Returns
true
if the rune is an ASCII octal digit. -
:is_ascii_printable() -> bool
-
Returns
true
if the rune is in the range of ASCII printable characters. -
:is_ascii_ws() -> bool
-
Returns
true
if the rune is an ASCII whitespace character. -
:is_unicode_ws() -> bool
-
Returns
true
if the rune is a Unicode whitespace codepoint.