forked from AbleScript/ablescript
Implemented string unicode escapes
This commit is contained in:
parent
ed83065ee4
commit
c0852fe83e
|
@ -138,7 +138,24 @@ fn get_value<T: std::str::FromStr>(lexer: &mut Lexer<Token>) -> Option<T> {
|
|||
|
||||
fn get_string(lexer: &mut Lexer<Token>) -> Option<String> {
|
||||
lexer.bump(lexer.remainder().find("*/")?);
|
||||
let string = lexer.slice()[2..].to_owned();
|
||||
|
||||
let mut string = String::new();
|
||||
let mut slice = &lexer.slice()[2..];
|
||||
while let Some(escape_start) = slice.find('"') {
|
||||
string.push_str(&slice.get(..escape_start)?);
|
||||
slice = &slice.get(escape_start + 1..)?;
|
||||
|
||||
let escape_end = slice.find('"')?;
|
||||
string.push(
|
||||
u32::from_str_radix(&slice.get(..escape_end)?, 12)
|
||||
.ok()
|
||||
.and_then(char::from_u32)?,
|
||||
);
|
||||
|
||||
slice = &slice.get(escape_end + 1..)?;
|
||||
}
|
||||
|
||||
string.push_str(&slice);
|
||||
lexer.bump(2);
|
||||
|
||||
Some(string)
|
||||
|
|
Loading…
Reference in a new issue