fn str_lit(lit: &str) -> String {
    let mut res = String::with_capacity(lit.len());

    // FIXME #8372: This could be a for-loop if it didn't borrow the iterator
    let error = |i| format!("lexer should have rejected {} at {}", lit, i);

    /// Eat everything up to a non-whitespace
    fn eat<'a>(it: &mut iter::Peekable<str::CharIndices<'a>>) {
        loop {
            match it.peek().map(|x| x.1) {
                Some(' ') | Some('\n') | Some('\r') | Some('\t') => {
                    it.next();
                },
                _ => { break; }
            }
        }
    }

    let mut chars = lit.char_indices().peekable();
    loop {
        match chars.next() {
            Some((i, c)) => {
                match c {
                    '\\' => {
                        let ch = chars.peek().unwrap_or_else(|| {
                            panic!("{}", error(i))
                        }).1;

                        if ch == '\n' {
                            eat(&mut chars);
                        } else if ch == '\r' {
                            chars.next();
                            let ch = chars.peek().unwrap_or_else(|| {
                                panic!("{}", error(i))
                            }).1;

                            if ch != '\n' {
                                panic!("lexer accepted bare CR");
                            }
                            eat(&mut chars);
                        } else {
                            // otherwise, a normal escape
                            let (c, n) = char_lit(&lit[i..]);
                            for _ in 0..n - 1 { // we don't need to move past the first \
                                chars.next();
                            }
                            res.push(c);
                        }
                    },
                    '\r' => {
                        let ch = chars.peek().unwrap_or_else(|| {
                            panic!("{}", error(i))
                        }).1;

                        if ch != '\n' {
                            panic!("lexer accepted bare CR");
                        }
                        chars.next();
                        res.push('\n');
                    }
                    c => res.push(c),
                }
            },
            None => break
        }
    }

    res.shrink_to_fit(); // probably not going to do anything, unless there was an escape.
    res
}
/// Parse a string representing a string literal into its final form. Does
/// unescaping.
Parse a string representing a string literal into its final form. Does
unescaping.
Parse a string representing a string literal into its final form . Does unescaping .
fn str_lit(lit: &str) -> String {
    let mut res = String::with_capacity(lit.len());
    // FIXME #8372: This could be a for-loop if it didn't borrow the iterator
    let error = |i| format!("lexer should have rejected {} at {}", lit, i);
    /// Eat everything up to a non-whitespace
    fn eat<'a>(it: &mut iter::Peekable<str::CharIndices<'a>>) {
        loop {
            match it.peek().map(|x| x.1) {
                Some(' ') | Some('\n') | Some('\r') | Some('\t') => {
                    it.next();
                },
                _ => { break; }
            }
        }
    }
    let mut chars = lit.char_indices().peekable();
    loop {
        match chars.next() {
            Some((i, c)) => {
                match c {
                    '\\' => {
                        let ch = chars.peek().unwrap_or_else(|| {
                            panic!("{}", error(i))
                        }).1;
                        if ch == '\n' {
                            eat(&mut chars);
                        } else if ch == '\r' {
                            chars.next();
                            let ch = chars.peek().unwrap_or_else(|| {
                                panic!("{}", error(i))
                            }).1;
                            if ch != '\n' {
                                panic!("lexer accepted bare CR");
                            }
                            eat(&mut chars);
                        } else {
                            // otherwise, a normal escape
                            let (c, n) = char_lit(&lit[i..]);
                            for _ in 0..n - 1 { // we don't need to move past the first \
                                chars.next();
                            }
                            res.push(c);
                        }
                    },
                    '\r' => {
                        let ch = chars.peek().unwrap_or_else(|| {
                            panic!("{}", error(i))
                        }).1;
                        if ch != '\n' {
                            panic!("lexer accepted bare CR");
                        }
                        chars.next();
                        res.push('\n');
                    }
                    c => res.push(c),
                }
            },
            None => break
        }
    }
    res.shrink_to_fit(); // probably not going to do anything, unless there was an escape.
    res
}
fn str_lit ( lit : & str ) -> String { let mut res = String :: with_capacity ( lit . len ( ) ) ; // FIXME #8372: This could be a for-loop if it didn't borrow the iterator let error = | i | format ! ( " " lit i ) ; /// Eat everything up to a non-whitespace fn eat < ' a > ( it : & mut iter :: Peekable < str :: CharIndices < ' a > > ) { loop { match it . peek ( ) . map ( | x | x . 1 ) { Some ( ' ' ) | Some ( '\n' ) | Some ( '\r' ) | Some ( '\t' ) => { it . next ( ) ; } , _ => { break ; } } } } let mut chars = lit . char_indices ( ) . peekable ( ) ; loop { match chars . next ( ) { Some ( ( i , c ) ) => { match c { '\\' => { let ch = chars . peek ( ) . unwrap_or_else ( | | { panic ! ( " " error ( i ) ) } ) . 1 ; if ch == '\n' { eat ( & mut chars ) ; } else if ch == '\r' { chars . next ( ) ; let ch = chars . peek ( ) . unwrap_or_else ( | | { panic ! ( " " error ( i ) ) } ) . 1 ; if ch != '\n' { panic ! ( " " ) ; } eat ( & mut chars ) ; } else { // otherwise, a normal escape let ( c , n ) = char_lit ( & lit [ i .. ] ) ; for _ in 0 .. n - 1 { // we don't need to move past the first \ chars . next ( ) ; } res . push ( c ) ; } } , '\r' => { let ch = chars . peek ( ) . unwrap_or_else ( | | { panic ! ( " " error ( i ) ) } ) . 1 ; if ch != '\n' { panic ! ( " " ) ; } chars . next ( ) ; res . push ( '\n' ) ; } c => res . push ( c ) , } } , None => break } } res . shrink_to_fit ( ) ; // probably not going to do anything, unless there was an escape. res }
Parse a string representing a string literal into its final form.
Parse a string representing a string literal into its final form .
lit
&str
lit
&str