better-url 0.12.0

A better URL crate.
Documentation
//! Setter stuff.

use crate::prelude::*;

/// Bytes to keep.
const KEEPS: ByteSet = ByteSet::new().add_many(b"\t\n\r").invert();

/// General canonizer for most part setters.
///
/// You should use dedicated canonizers where applicable.
pub fn canonize_part_setter<'a, T: Into<Cow<'a, str>>>(value: T) -> (bool, Cow<'a, str>) {
    let (changed, value) = canonize_part_setter_bytes(cow_str_to_bytes(value));

    (changed, unsafe {cow_bytes_to_str_unchecked(value)})
}

/// General canonizer for most part setters.
///
/// You should use dedicated canonizers where applicable.
pub fn canonize_part_setter_bytes<'a, T: Into<Cow<'a, [u8]>>>(value: T) -> (bool, Cow<'a, [u8]>) {
    let mut value = value.into();
    let mut changed = false;

    if memchr::memchr3(b'\t', b'\r', b'\n', &value).is_some() {
        value.to_mut().retain(|&b| KEEPS.contains(b));
        changed = true;
    }

    (changed, value)
}