fn unquote_string(in_string: String) -> String {
    // String should always begin with a quote
    if in_string.len() == 0 { return in_string; }

    let mut out_string  = String::new();
    let mut chars       = in_string.chars();

    // First character is skipped (will be a string quote)
    chars.next();
    let mut quoted = false;

    for chr in chars {
        match (chr, quoted) {
            ('\\', false)   => { quoted = false; }
            ('n', true)     => { out_string.push('\n'); }
            ('r', true)     => { out_string.push('\r'); }
            ('t', true)     => { out_string.push('\t'); }
            (any, _)        => { out_string.push(any); }
        }
    }

    // Remove the last character
    if out_string.chars().last() == in_string.chars().nth(0) {
        out_string.pop();
    }

    // out_string contains the result
    out_string
}
///
/// Removes the quotes around a string (or character), replaces characters like '\n' with their 'real' equivalent
///
Removes the quotes around a string (or character), replaces characters like '\n' with their 'real' equivalent
Removes the quotes around a string ( or character ) replaces characters like ' \ n ' with their ' real ' equivalent
fn unquote_string(in_string: String) -> String {
    // String should always begin with a quote
    if in_string.len() == 0 { return in_string; }
    let mut out_string  = String::new();
    let mut chars       = in_string.chars();
    // First character is skipped (will be a string quote)
    chars.next();
    let mut quoted = false;
    for chr in chars {
        match (chr, quoted) {
            ('\\', false)   => { quoted = false; }
            ('n', true)     => { out_string.push('\n'); }
            ('r', true)     => { out_string.push('\r'); }
            ('t', true)     => { out_string.push('\t'); }
            (any, _)        => { out_string.push(any); }
        }
    }
    // Remove the last character
    if out_string.chars().last() == in_string.chars().nth(0) {
        out_string.pop();
    }
    // out_string contains the result
    out_string
}
fn unquote_string ( in_string : String ) -> String { // String should always begin with a quote if in_string . len ( ) == 0 { return in_string ; } let mut out_string = String :: new ( ) ; let mut chars = in_string . chars ( ) ; // First character is skipped (will be a string quote) chars . next ( ) ; let mut quoted = false ; for chr in chars { match ( chr , quoted ) { ( '\\' , false ) => { quoted = false ; } ( 'n' , true ) => { out_string . push ( '\n' ) ; } ( 'r' , true ) => { out_string . push ( '\r' ) ; } ( 't' , true ) => { out_string . push ( '\t' ) ; } ( any , _ ) => { out_string . push ( any ) ; } } } // Remove the last character if out_string . chars ( ) . last ( ) == in_string . chars ( ) . nth ( 0 ) { out_string . pop ( ) ; } // out_string contains the result out_string }
Removes the quotes around a string (or character), replaces characters like '\n' with their 'real' equivalent
Removes the quotes around a string ( or character ) replaces characters like ' \ n ' with their ' real ' equivalent
in_string
String
in_string
String