pub fn normalize(s: String, whitespace: WhiteSpace) -> String {
    let is_whitespace = |b: u8| matches!(b, 0x09 | 0x0A | 0x0D | 0x20);
    let collapse = match whitespace {
        WhiteSpace::Preserve => return s,
        WhiteSpace::Replace => false,
        WhiteSpace::Collapse => true,
    };
    let mut v = s.into_bytes();
    let mut outp = 0;
    let mut end = v.len();
    let mut copy = if collapse {
        while end > 0 && is_whitespace(v[end - 1]) {
            end -= 1;
        }
        let start = v
            .iter()
            .take(end)
            .take_while(|&&b| is_whitespace(b))
            .count();
        start..start
    } else {
        0..0
    };
    while copy.end < end {
        let p = copy.end;
        copy.end += 1;
        if is_whitespace(v[p]) {
            v[p] = b' ';
            if collapse {
                let mut next_start = copy.end;
                while next_start < end && is_whitespace(v[next_start]) {
                    next_start += 1;
                }
                if next_start > copy.end {
                    v.copy_within(copy.clone(), outp);
                    outp += copy.len();
                    copy = next_start..next_start;
                    continue;
                }
            }
        }
    }
    if copy.start > outp {
        v.copy_within(copy.clone(), outp);
        end = outp + copy.len();
    }
    v.truncate(end);

    // SAFETY:
    // * v came from s and thus was initially valid UTF-8.
    // * the only transformations are removing ASCII bytes and replacing ASCII
    //   bytes with other ASCII bytes, preserving validity.
    unsafe { String::from_utf8_unchecked(v) }
}
/// Performs white space normalization on a string, destructively.
///
/// ```rust
/// # use static_xml::de::{WhiteSpace, normalize};
/// assert_eq!(normalize("\n foo\t bar\n\n".to_owned(), WhiteSpace::Preserve), "\n foo\t bar\n\n");
/// assert_eq!(normalize("\n foo\t bar\n\n".to_owned(), WhiteSpace::Replace), "  foo  bar  ");
/// assert_eq!(normalize("\n foo\t bar\n\n".to_owned(), WhiteSpace::Collapse), "foo bar");
/// ```
Performs white space normalization on a string, destructively.
Performs white space normalization on a string destructively .
pub fn normalize(s: String, whitespace: WhiteSpace) -> String {
    let is_whitespace = |b: u8| matches!(b, 0x09 | 0x0A | 0x0D | 0x20);
    let collapse = match whitespace {
        WhiteSpace::Preserve => return s,
        WhiteSpace::Replace => false,
        WhiteSpace::Collapse => true,
    };
    let mut v = s.into_bytes();
    let mut outp = 0;
    let mut end = v.len();
    let mut copy = if collapse {
        while end > 0 && is_whitespace(v[end - 1]) {
            end -= 1;
        }
        let start = v
            .iter()
            .take(end)
            .take_while(|&&b| is_whitespace(b))
            .count();
        start..start
    } else {
        0..0
    };
    while copy.end < end {
        let p = copy.end;
        copy.end += 1;
        if is_whitespace(v[p]) {
            v[p] = b' ';
            if collapse {
                let mut next_start = copy.end;
                while next_start < end && is_whitespace(v[next_start]) {
                    next_start += 1;
                }
                if next_start > copy.end {
                    v.copy_within(copy.clone(), outp);
                    outp += copy.len();
                    copy = next_start..next_start;
                    continue;
                }
            }
        }
    }
    if copy.start > outp {
        v.copy_within(copy.clone(), outp);
        end = outp + copy.len();
    }
    v.truncate(end);
    // SAFETY:
    // * v came from s and thus was initially valid UTF-8.
    // * the only transformations are removing ASCII bytes and replacing ASCII
    //   bytes with other ASCII bytes, preserving validity.
    unsafe { String::from_utf8_unchecked(v) }
}
pub fn normalize ( s : String , whitespace : WhiteSpace ) -> String { let is_whitespace = | b : u8 | matches ! ( b 0x09 0x0A 0x0D 0x20 ) ; let collapse = match whitespace { WhiteSpace :: Preserve => return s , WhiteSpace :: Replace => false , WhiteSpace :: Collapse => true , } ; let mut v = s . into_bytes ( ) ; let mut outp = 0 ; let mut end = v . len ( ) ; let mut copy = if collapse { while end > 0 && is_whitespace ( v [ end - 1 ] ) { end -= 1 ; } let start = v . iter ( ) . take ( end ) . take_while ( | & & b | is_whitespace ( b ) ) . count ( ) ; start .. start } else { 0 .. 0 } ; while copy . end < end { let p = copy . end ; copy . end += 1 ; if is_whitespace ( v [ p ] ) { v [ p ] = b' ' ; if collapse { let mut next_start = copy . end ; while next_start < end && is_whitespace ( v [ next_start ] ) { next_start += 1 ; } if next_start > copy . end { v . copy_within ( copy . clone ( ) , outp ) ; outp += copy . len ( ) ; copy = next_start .. next_start ; continue ; } } } } if copy . start > outp { v . copy_within ( copy . clone ( ) , outp ) ; end = outp + copy . len ( ) ; } v . truncate ( end ) ; // SAFETY: // * v came from s and thus was initially valid UTF-8. // * the only transformations are removing ASCII bytes and replacing ASCII //   bytes with other ASCII bytes, preserving validity. unsafe { String :: from_utf8_unchecked ( v ) } }
Performs white space normalization on a string, destructively.
Performs white space normalization on a string destructively .
s
String
whitespace
WhiteSpace
use static_xml::de::{whitespace, normalize};
None