text-fx 0.4.0

A collection of text processing utilities for Rust.
Documentation
/// In-place translation of a C-style NUL-terminated string, replacing all occurrences of one byte with another.
///
/// This function mutates the given pointer to a NUL-terminated string (`*mut i8`), replacing every occurrence
/// of the byte `from` with the byte `to`. The operation stops at the first NUL byte (`\0`).
///
/// # Safety
///
/// - The pointer `s` must be valid and point to a mutable, NUL-terminated string.
/// - The memory must be writable and large enough to contain the string and the NUL terminator.
/// - Behavior is undefined if `s` is not properly NUL-terminated or is invalid.
///
/// # Arguments
///
/// * `s` - Pointer to the mutable NUL-terminated string.
/// * `from` - The byte value to replace.
/// * `to` - The byte value to substitute.
///
/// # Examples
///
/// ```
/// use text_fx::transform::tr;
///
/// let mut buf = *b"hello\0";
/// tr(buf.as_mut_ptr() as *mut _, b'l' as i8, b'p' as i8);
/// assert_eq!(buf, *b"heppo\0");
/// ```
pub fn tr(mut s: *mut i8, from: i8, to: i8) {
    unsafe {
        while *s != b'\0' as i8 {
            if *s == from {
                *s = to;
            }
            s = s.add(1);
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_tr() {
        let mut s = *b"hello\0";
        tr(s.as_mut_ptr() as *mut _, b'l' as i8, b'p' as i8);
        assert_eq!(s, *b"heppo\0");
    }
}