Trim
Removes leading Unicode whitespace from a borrowed UTF-8 view.
Module std.text
import std.text;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
fn
pub const fn TrimStart(Text: str) -> strRemoves leading Unicode whitespace from a borrowed UTF-8 view. Text: Valid UTF-8 backing storage, borrowed by the returned view. Return: Boundary-aligned suffix; allocates nothing and retains no owner. Warning: The result expires when the original backing storage is invalidated.
Example
module example.text_trimming;
from std.text import Trim, TrimStart, TrimEnd;
fn Main() -> i32 {
let Text: str = "\u{2003} λ \u{00A0}";
if Trim(Text) != "λ" { return 1; }
if TrimStart(Text) != "λ \u{00A0}" { return 2; }
if TrimEnd(Text) != "\u{2003} λ" { return 3; }
if Trim(" \t\u{3000}") != "" || Trim("") != "" { return 4; }
if Trim("\u{200B}λ\u{FEFF}") != "\u{200B}λ\u{FEFF}" { return 5; }
return 0;
}fn
pub const fn TrimEnd(Text: str) -> strRemoves trailing Unicode whitespace from a borrowed UTF-8 view. Text: Valid UTF-8 backing storage, borrowed by the result. Return: Boundary-aligned prefix after backward tail traversal, with no allocation. Warning: The result expires with its original backing storage.
fn
pub const fn Trim(Text: str) -> strRemoves leading and trailing Unicode whitespace without changing interior bytes. Text: Valid UTF-8 backing storage, borrowed by the result. Return: Borrowed boundary-aligned view after leading/trailing whitespace scans, no allocation. Warning: The result expires with its original backing storage.