Module string/rune
Unicode code point type (rune) for representing individual characters.
A rune is a newtype over u32 holding one scalar value — Go's rune,
Rust's char. from_u32 is the only constructor that validates, and it
rejects the surrogate range D800..=DFFF as well as anything above 10FFFF,
so a rune in hand is always encodable as UTF-8. Runes are values: Eq,
Ord and Send are all defined by comparing the code point.
This module gives a PRIMITIVE type its inherent methods from outside the
prelude (the prelude imports nothing and has no c_include, so it cannot
host them); std/math.yo follows the same pattern.
Stability
unstable — seven of the eleven methods are ASCII-ONLY under names Rust
reserves for the Unicode behaviour: is_whitespace, is_digit,
is_alphabetic, is_uppercase, is_lowercase, to_lowercase and
to_uppercase all test or shift the ASCII range and pass every other code
point through unchanged. Each says so in its own doc, but the NAMES are the
problem — Rust spells these is_ascii_* / to_ascii_* and keeps the
unprefixed names for the table-driven versions. The audit's plan
(plans/STD_API_STABILIZATION.md §4, "Text") is to rename them to
is_ascii_* / to_ascii_* and add real Unicode versions backed by
std/string/unicode.yo's tables. That rename is breaking, so the module
cannot be frozen before it lands. rune itself, from_u32, to_u32,
is_ascii and the named constants are settled.
Types
Unicode code point (U+0000 to U+10FFFF, excluding surrogates).
Similar to Go's rune or Rust's char.
Fields
| Name | Type | Description |
|---|---|---|
char | u32 | The raw Unicode code point value. |
Trait Implementations
impl(generic(T : Type), where(T <: ToString), T : (ToString))
impl(generic(T : Type), where(T <: ToString), T : (ToString), Format)
format : fn(self : Self, spec : str) -> StringRender self under spec. An unrecognised spec degrades to the plain
to_string() rendering rather than failing.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
spec | str |
Returns: String
impl(rune, ...)
from_u32 : (rune) fn(value : u32) -> Option(rune)Create a rune from a u32 value, returning None if the value is not a valid Unicode code point.
Parameters
| Name | Type | Notes |
|---|---|---|
value | u32 |
Returns: Option(rune)
to_u32 : (rune) fn(self : rune) -> u32Return the raw u32 code point value.
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: u32
is_ascii : (rune) fn(self : rune) -> boolCheck if this is an ASCII character (U+0000 to U+007F).
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
is_whitespace : (rune) fn(self : rune) -> boolCheck if this is a whitespace character (space, tab, newline, or carriage return).
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
is_digit : (rune) fn(self : rune) -> boolCheck if this is an ASCII digit ('0' to '9').
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
is_alphabetic : (rune) fn(self : rune) -> boolCheck if this is an ASCII letter ('A'-'Z' or 'a'-'z').
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
is_uppercase : (rune) fn(self : rune) -> boolCheck if this is an ASCII uppercase letter ('A'-'Z').
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
is_lowercase : (rune) fn(self : rune) -> boolCheck if this is an ASCII lowercase letter ('a'-'z').
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: bool
to_lowercase : (rune) fn(self : rune) -> runeConvert to lowercase. Only affects ASCII uppercase letters.
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: rune
to_uppercase : (rune) fn(self : rune) -> runeConvert to uppercase. Only affects ASCII lowercase letters.
Parameters
| Name | Type | Notes |
|---|---|---|
self | rune |
Returns: rune
NUL : SelfNull character (U+0000).
Returns: unknown
REPLACEMENT : SelfReplacement character (U+FFFD) — what a lossy decoder substitutes for an
invalid byte sequence. See std/encoding/utf8's decode_lossy.
Returns: unknown
TAB : SelfHorizontal tab (U+0009).
Returns: unknown
NEWLINE : SelfLine feed / newline (U+000A).
Returns: unknown
SPACE : SelfSpace (U+0020).
Returns: unknown
ZERO : SelfDigit zero '0' (U+0030).
Returns: unknown
NINE : SelfDigit nine '9' (U+0039).
Returns: unknown
UPPERCASE_A : SelfUppercase 'A' (U+0041).
Returns: unknown
UPPERCASE_Z : SelfUppercase 'Z' (U+005A).
Returns: unknown
LOWERCASE_A : SelfLowercase 'a' (U+0061).
Returns: unknown
LOWERCASE_Z : SelfLowercase 'z' (U+007A).
Returns: unknown
impl(rune, Eq(rune))
impl(rune, Ord(rune))
impl(rune, Send())
impl(rune, Default(...))
default : (rune) fn() -> runeThe default value of the type.
Returns: rune
Methods
== : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
!= : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
< : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
<= : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
> : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
>= : (rune) fn(lhs : rune, rhs : rune) -> boolParameters
| Name | Type | Notes |
|---|---|---|
lhs | rune | |
rhs | rune |
Returns: bool
cmp : (rune) fn(lhs : rune, rhs : rune) -> Orderingis_prefix_of : (rune) fn(self : rune, haystack : String, position : usize) -> boolis_suffix_of : (rune) fn(self : rune, haystack : String, end_position : usize) -> boolindex_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> Option(usize)is_contained_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> boollast_index_in : (rune) fn(self : rune, haystack : String, from_index : usize) -> Option(usize)length_in : (rune) fn(self : rune, haystack : String, at : usize) -> usizesplit_of : (rune) fn(self : rune, haystack : String) -> ArrayList(String)to_string : (rune) fn(self : rune) -> Stringdebug_string : (rune) fn(self : rune) -> String