fn interpret_string_lit(&mut self, lit: String) -> PResult<Vec<u8>> {
        let mut result = Vec::new();

        let mut char_indices = lit.char_indices().peekable();

        while let Some((offset, c)) = char_indices.next() {
            if c == '\\' {
                // A string literal with a value ending with \ shouldn't get past the lexer.
                let &(_, pc) = char_indices.peek()
                    .expect("unexpected end of string: this is a bug!");

                // First check to see if we have a simple escape.
                if let Some(escape_byte) = self.get_simple_escape(pc) {
                    char_indices.next();
                    result.push(escape_byte);
                } else if pc == '"' {
                    char_indices.next();
                    // \" is only valid in strings
                    result.push(b'"');
                } else if pc == 'x' {
                    char_indices.next();
                    let byte = try!(self.interpret_hex_escape(&mut char_indices));
                    result.push(byte);
                } else if pc == 'u' || pc == 'U' {
                    char_indices.next();
                    let value_char = try!(self.interpret_unicode_escape(pc == 'U',
                                                                        &mut char_indices));

                    let mut tmp = String::with_capacity(4);
                    tmp.push(value_char);
                    result.extend_from_slice(tmp.as_bytes());
                } else if pc.is_digit(8) {
                    let byte = try!(self.interpret_octal_escape(&mut char_indices));
                    result.push(byte);
                } else {
                    let msg = format!("unknown escape sequence: {}", pc);
                    return Err(self.err(ErrorKind::other(msg)));
                }
            } else if c == '\n' {
                let msg = format!("newline in string");
                return Err(self.err(ErrorKind::other(msg)));
            } else {
                let orig_str = &lit[offset..offset + c.len_utf8()];
                result.extend_from_slice(orig_str.as_bytes());
            }
        }

        Ok(result)
    }
/// Interpret a string literal, converting escape patterns to bytes.
/// Note that it returns a Vec<u8> rather than a String. This is because Go string literals
/// are allowed to contain invalid ASCII/UTF-8 through the use of octal and hex escapes.
Interpret a string literal, converting escape patterns to bytes.
Note that it returns a Vec rather than a String. This is because Go string literals
are allowed to contain invalid ASCII/UTF-8 through the use of octal and hex escapes.
Interpret a string literal converting escape patterns to bytes . Note that it returns a Vec rather than a String . This is because Go string literals are allowed to contain invalid ASCII / UTF - 8 through the use of octal and hex escapes .
fn interpret_string_lit(&mut self, lit: String) -> PResult<Vec<u8>> {
        let mut result = Vec::new();
        let mut char_indices = lit.char_indices().peekable();
        while let Some((offset, c)) = char_indices.next() {
            if c == '\\' {
                // A string literal with a value ending with \ shouldn't get past the lexer.
                let &(_, pc) = char_indices.peek()
                    .expect("unexpected end of string: this is a bug!");
                // First check to see if we have a simple escape.
                if let Some(escape_byte) = self.get_simple_escape(pc) {
                    char_indices.next();
                    result.push(escape_byte);
                } else if pc == '"' {
                    char_indices.next();
                    // \" is only valid in strings
                    result.push(b'"');
                } else if pc == 'x' {
                    char_indices.next();
                    let byte = try!(self.interpret_hex_escape(&mut char_indices));
                    result.push(byte);
                } else if pc == 'u' || pc == 'U' {
                    char_indices.next();
                    let value_char = try!(self.interpret_unicode_escape(pc == 'U',
                                                                        &mut char_indices));
                    let mut tmp = String::with_capacity(4);
                    tmp.push(value_char);
                    result.extend_from_slice(tmp.as_bytes());
                } else if pc.is_digit(8) {
                    let byte = try!(self.interpret_octal_escape(&mut char_indices));
                    result.push(byte);
                } else {
                    let msg = format!("unknown escape sequence: {}", pc);
                    return Err(self.err(ErrorKind::other(msg)));
                }
            } else if c == '\n' {
                let msg = format!("newline in string");
                return Err(self.err(ErrorKind::other(msg)));
            } else {
                let orig_str = &lit[offset..offset + c.len_utf8()];
                result.extend_from_slice(orig_str.as_bytes());
            }
        }
        Ok(result)
    }
fn interpret_string_lit ( & mut self , lit : String ) -> PResult < Vec < u8 > > { let mut result = Vec :: new ( ) ; let mut char_indices = lit . char_indices ( ) . peekable ( ) ; while let Some ( ( offset , c ) ) = char_indices . next ( ) { if c == '\\' { // A string literal with a value ending with \ shouldn't get past the lexer. let & ( _ , pc ) = char_indices . peek ( ) . expect ( " " ) ; // First check to see if we have a simple escape. if let Some ( escape_byte ) = self . get_simple_escape ( pc ) { char_indices . next ( ) ; result . push ( escape_byte ) ; } else if pc == '"' { char_indices . next ( ) ; // \" is only valid in strings result . push ( b'"' ) ; } else if pc == 'x' { char_indices . next ( ) ; let byte = try ! ( self interpret_hex_escape ( mut char_indices ) ) ; result . push ( byte ) ; } else if pc == 'u' || pc == 'U' { char_indices . next ( ) ; let value_char = try ! ( self interpret_unicode_escape ( pc 'U' mut char_indices ) ) ; let mut tmp = String :: with_capacity ( 4 ) ; tmp . push ( value_char ) ; result . extend_from_slice ( tmp . as_bytes ( ) ) ; } else if pc . is_digit ( 8 ) { let byte = try ! ( self interpret_octal_escape ( mut char_indices ) ) ; result . push ( byte ) ; } else { let msg = format ! ( " " pc ) ; return Err ( self . err ( ErrorKind :: other ( msg ) ) ) ; } } else if c == '\n' { let msg = format ! ( " " ) ; return Err ( self . err ( ErrorKind :: other ( msg ) ) ) ; } else { let orig_str = & lit [ offset .. offset + c . len_utf8 ( ) ] ; result . extend_from_slice ( orig_str . as_bytes ( ) ) ; } } Ok ( result ) }
Interpret a string literal, converting escape patterns to bytes.
Interpret a string literal converting escape patterns to bytes .
&mut self
lit
String