/// Remove trailing spaces from the specified snippet. We do not remove spaces
/// inside strings or comments.
Remove trailing spaces from the specified snippet. We do not remove spaces
inside strings or comments.
Remove trailing spaces from the specified snippet . We do not remove spaces inside strings or comments .
pub fn remove_trailing_white_spaces(text: &str) -> String {
    let mut buffer = String::with_capacity(text.len());
    let mut space_buffer = String::with_capacity(128);
    for (char_kind, c) in CharClasses::new(text.chars()) {
        match c {
            '\n' => {
                if char_kind == FullCodeCharKind::InString {
                    buffer.push_str(&space_buffer);
                }
                space_buffer.clear();
                buffer.push('\n');
            }
            _ if c.is_whitespace() => {
                space_buffer.push(c);
            }
            _ => {
                if !space_buffer.is_empty() {
                    buffer.push_str(&space_buffer);
                    space_buffer.clear();
                }
                buffer.push(c);
            }
        }
    }
    buffer
}
pub fn remove_trailing_white_spaces ( text : & str ) -> String { let mut buffer = String :: with_capacity ( text . len ( ) ) ; let mut space_buffer = String :: with_capacity ( 128 ) ; for ( char_kind , c ) in CharClasses :: new ( text . chars ( ) ) { match c { '\n' => { if char_kind == FullCodeCharKind :: InString { buffer . push_str ( & space_buffer ) ; } space_buffer . clear ( ) ; buffer . push ( '\n' ) ; } _ if c . is_whitespace ( ) => { space_buffer . push ( c ) ; } _ => { if ! space_buffer . is_empty ( ) { buffer . push_str ( & space_buffer ) ; space_buffer . clear ( ) ; } buffer . push ( c ) ; } } } buffer }
Remove trailing spaces from the specified snippet.
Remove trailing spaces from the specified snippet .
text
&str