// Remove leading, trailing whitespace and common indent from multiline strings.
Remove leading, trailing whitespace and common indent from multiline strings.
Remove leading trailing whitespace and common indent from multiline strings .
fn convert_to_dada_string(s: &str) -> String {
    // If the string has only one line, leave it and return immediately.
    if s.lines().count() == 1 {
        return support_escape(s);
    }
    // Split string into lines and filter out empty lines.
    let mut non_empty_line_iter = s.lines().filter(|&line| !line.trim().is_empty());
    if let Some(first_line) = non_empty_line_iter.next() {
        let prefix = first_line
            .chars()
            .into_iter()
            .take_while(|c| c.is_whitespace())
            .collect::<String>();
        let common_indent = non_empty_line_iter
            .map(|s| count_bytes_in_common(prefix.as_bytes(), s.as_bytes()))
            .min()
            .unwrap_or(0);
        // Remove the common indent from every line in the original string,
        // apart from empty lines, which remain as empty.
        let mut buf = String::new();
        for (i, line) in s.lines().enumerate() {
            if i > 0 {
                buf.push('\n');
            }
            if line.trim().is_empty() {
                buf.push_str(line);
            } else {
                buf.push_str(&line[common_indent..]);
            }
        }
        // Strip leading/trailing whitespace.
        return support_escape(buf.trim());
    }
    String::new()
}
fn convert_to_dada_string ( s : & str ) -> String { // If the string has only one line, leave it and return immediately. if s . lines ( ) . count ( ) == 1 { return support_escape ( s ) ; } // Split string into lines and filter out empty lines. let mut non_empty_line_iter = s . lines ( ) . filter ( | & line | ! line . trim ( ) . is_empty ( ) ) ; if let Some ( first_line ) = non_empty_line_iter . next ( ) { let prefix = first_line . chars ( ) . into_iter ( ) . take_while ( | c | c . is_whitespace ( ) ) . collect :: < String > ( ) ; let common_indent = non_empty_line_iter . map ( | s | count_bytes_in_common ( prefix . as_bytes ( ) , s . as_bytes ( ) ) ) . min ( ) . unwrap_or ( 0 ) ; // Remove the common indent from every line in the original string, // apart from empty lines, which remain as empty. let mut buf = String :: new ( ) ; for ( i , line ) in s . lines ( ) . enumerate ( ) { if i > 0 { buf . push ( '\n' ) ; } if line . trim ( ) . is_empty ( ) { buf . push_str ( line ) ; } else { buf . push_str ( & line [ common_indent .. ] ) ; } } // Strip leading/trailing whitespace. return support_escape ( buf . trim ( ) ) ; } String :: new ( ) }
Remove leading, trailing whitespace and common indent from multiline strings.
Remove leading trailing whitespace and common indent from multiline strings .
s
&str