/// return true if the string value already starts/ends with quotes and is
/// already properly escaped (all spaces escaped)
return true if the string value already starts/ends with quotes and is
already properly escaped (all spaces escaped)
return true if the string value already starts / ends with quotes and is already properly escaped ( all spaces escaped )
fn needs_quotes_and_escaping(value: &str) -> bool {
    // mismatches beginning  / end quotes
    if value.starts_with('"') != value.ends_with('"') {
        return true;
    }
    // ignore beginning/ending quotes, if any
    let pre_quoted = value.len() >= 2 && value.starts_with('"') && value.ends_with('"');
    let value = if pre_quoted {
        &value[1..value.len() - 1]
    } else {
        value
    };
    // unescaped quotes
    let c0 = value.chars();
    let c1 = value.chars().skip(1);
    if c0.zip(c1).any(|(c0, c1)| c0 != '\\' && c1 == '"') {
        return true;
    }
    // Quote any strings that contain a literal '=' which the logfmt parser
    // interprets as a key/value separator.
    if value.chars().any(|c| c == '=') && !pre_quoted {
        return true;
    }
    if value.bytes().any(|b| b <= b' ') && !pre_quoted {
        return true;
    }
    false
}
fn needs_quotes_and_escaping ( value : & str ) -> bool { // mismatches beginning  / end quotes if value . starts_with ( '"' ) != value . ends_with ( '"' ) { return true ; } // ignore beginning/ending quotes, if any let pre_quoted = value . len ( ) >= 2 && value . starts_with ( '"' ) && value . ends_with ( '"' ) ; let value = if pre_quoted { & value [ 1 .. value . len ( ) - 1 ] } else { value } ; // unescaped quotes let c0 = value . chars ( ) ; let c1 = value . chars ( ) . skip ( 1 ) ; if c0 . zip ( c1 ) . any ( | ( c0 , c1 ) | c0 != '\\' && c1 == '"' ) { return true ; } // Quote any strings that contain a literal '=' which the logfmt parser // interprets as a key/value separator. if value . chars ( ) . any ( | c | c == '=' ) && ! pre_quoted { return true ; } if value . bytes ( ) . any ( | b | b <= b' ' ) && ! pre_quoted { return true ; } false }
return true if the string value already starts/ends with quotes and is
already properly escaped (all spaces escaped)
return true if the string value already starts / ends with quotes and is already properly escaped ( all spaces escaped )
value
&str