buildlang 1.15.0

BuildLang (buildc): an effects-oriented compiler with a verified C path, shader output, experimental backends, opt-in linear types, and re-checkable accountability + scientific-runtime receipts
Documentation
// BuildLang Standard Library - String Utilities Module
// Helper functions for common string operations.

// ---------------------------------------------------------------------------
// String construction
// ---------------------------------------------------------------------------

/// Build a string by repeating `s` a total of `n` times.
/// Returns an empty string when n <= 0.
fn repeat_str(s: str, n: i32) -> str {
    let mut result: str = "";
    let mut i: i32 = 0;
    while i < n {
        result = result + s;
        i = i + 1;
    }
    result
}

/// Create a string of `n` spaces.
fn spaces(n: i32) -> str {
    repeat_str(" ", n)
}

// ---------------------------------------------------------------------------
// String predicates
// ---------------------------------------------------------------------------

/// Returns true when the string has zero length.
fn is_empty(s: str) -> bool {
    s == ""
}

/// Returns true when the string has at least one character.
fn has_content(s: str) -> bool {
    s.len() > 0
}

// ---------------------------------------------------------------------------
// Padding helpers
// ---------------------------------------------------------------------------

/// Left-pad `s` with spaces until total width reaches `width`.
/// If `s` is already at least `width` characters, returns `s` unchanged.
fn pad_left(s: str, width: i32) -> str {
    let current: i32 = s.len();
    if current >= width {
        s
    } else {
        spaces(width - current) + s
    }
}

/// Right-pad `s` with spaces until total width reaches `width`.
/// If `s` is already at least `width` characters, returns `s` unchanged.
fn pad_right(s: str, width: i32) -> str {
    let current: i32 = s.len();
    if current >= width {
        s
    } else {
        s + spaces(width - current)
    }
}