Skip to content

Commit c27ad57

Browse files
committed
Duplicate raw string parser for strings and byte strings
1 parent 2c2a98f commit c27ad57

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/parse.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,30 @@ fn cooked_string(input: Cursor) -> Result<Cursor, Reject> {
417417
Err(Reject)
418418
}
419419

420+
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
421+
let (input, delimiter) = delimiter_of_raw_string(input)?;
422+
let mut chars = input.char_indices();
423+
while let Some((i, ch)) = chars.next() {
424+
match ch {
425+
'"' if input.rest[i + 1..].starts_with(delimiter) => {
426+
let rest = input.advance(i + 1 + delimiter.len());
427+
return Ok(literal_suffix(rest));
428+
}
429+
'\r' => match chars.next() {
430+
Some((_, '\n')) => {}
431+
_ => break,
432+
},
433+
_ => {}
434+
}
435+
}
436+
Err(Reject)
437+
}
438+
420439
fn byte_string(input: Cursor) -> Result<Cursor, Reject> {
421440
if let Ok(input) = input.parse("b\"") {
422441
cooked_byte_string(input)
423442
} else if let Ok(input) = input.parse("br") {
424-
raw_string(input)
443+
raw_byte_string(input)
425444
} else {
426445
Err(Reject)
427446
}
@@ -497,7 +516,7 @@ fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> {
497516
Ok((input.advance(n + 1), &input.rest[..n]))
498517
}
499518

500-
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
519+
fn raw_byte_string(input: Cursor) -> Result<Cursor, Reject> {
501520
let (input, delimiter) = delimiter_of_raw_string(input)?;
502521
let mut chars = input.char_indices();
503522
while let Some((i, ch)) = chars.next() {

0 commit comments

Comments
 (0)