fn parse_lit_str_cooked(mut s: &str) -> Vec<u8> { letmut content = String::new(); 'outer: loop { let ch = match byte(s, 0) {
b'"' => break,
b'\\' => { let b = byte(s, 1);
s = &s[2..]; match b {
b'x' => { let (byte, rest) = backslash_x(s);
s = rest;
char::from_u32(u32::from(byte)).expect("byte was just validated")
}
b'u' => { let (chr, rest) = backslash_u(s);
s = rest;
chr
}
b'n' => '\n',
b'r' => '\r',
b't' => '\t',
b'\\' => '\\',
b'0' => '\0',
b'\'' => '\'',
b'"' => '"',
b'\r' | b'\n' => loop { let ch = s.chars().next().unwrap_or_default(); if ch.is_whitespace() {
s = &s[ch.len_utf8()..];
} else { continue'outer;
}
},
_ => bug!("invalid escape"),
}
}
b'\r' => { // bare CR not permitted
s = &s[2..]; '\n'
}
_ => { let ch = s.chars().next().unwrap_or_default();
s = &s[ch.len_utf8()..];
ch
}
};
content.push(ch);
}
content.into_bytes()
}
fn parse_lit_str_raw(s: &[u8]) -> Vec<u8> { letmut pounds = 0; while byte(s, pounds) == b'#' {
pounds += 1;
} let close = s
.iter()
.rposition(|&b| b == b'"')
.expect("had a string without trailing \"");
s[pounds + 1..close].to_owned()
}
fn parse_lit_byte_str_cooked(mut v: &[u8]) -> Vec<u8> { letmut out = Vec::new(); 'outer: loop { let byte = match byte(v, 0) {
b'"' => break,
b'\\' => { let b = byte(v, 1);
v = &v[2..]; match b {
b'x' => { let (byte, rest) = backslash_x(v);
v = rest;
byte
}
b'n' => b'\n',
b'r' => b'\r',
b't' => b'\t',
b'\\' => b'\\',
b'0' => b'\0',
b'\'' => b'\'',
b'"' => b'"',
b'\r' | b'\n' => loop { let byte = byte(v, 0); let ch = char::from_u32(u32::from(byte)).expect("invalid byte"); if ch.is_whitespace() {
v = &v[1..];
} else { continue'outer;
}
},
_ => bug!("invalid escape"),
}
}
b'\r' => { // bare CR not permitted
v = &v[2..];
b'\n'
}
b => {
v = &v[1..];
b
}
};
out.push(byte);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.