footing 0.6.5

Feature-gated foundations for Rust backend services
Documentation
/// Normalizes display text without splitting UTF-8 characters at the byte limit.
pub(crate) fn normalize_message(value: impl Into<String>, max_bytes: usize) -> Option<String> {
    let value = value.into();
    let mut normalized = String::with_capacity(value.len().min(max_bytes));
    let mut pending_space = false;
    for character in value.chars() {
        if character.is_control() || character.is_whitespace() {
            pending_space = !normalized.is_empty();
            continue;
        }
        if normalized.len() + usize::from(pending_space) + character.len_utf8() > max_bytes {
            break;
        }
        if pending_space {
            normalized.push(' ');
        }
        normalized.push(character);
        pending_space = false;
    }
    (!normalized.is_empty()).then_some(normalized)
}