Skip to content

Commit

Permalink
Split out function to parse ###" prefix of raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 24, 2023
1 parent 231a097 commit 01e74f7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,9 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
Err(Reject)
}

fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
let mut chars = input.char_indices();
fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> {
let mut n = 0;
for (i, ch) in &mut chars {
for (i, ch) in input.char_indices() {
match ch {
'"' => {
n = i;
Expand All @@ -495,10 +494,16 @@ fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
// https://github.com/rust-lang/rust/pull/95251
return Err(Reject);
}
Ok((input.advance(n + 1), &input.rest[..n]))
}

fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
let (input, delimiter) = delimiter_of_raw_string(input)?;
let mut chars = input.char_indices();
while let Some((i, ch)) = chars.next() {
match ch {
'"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => {
let rest = input.advance(i + 1 + n);
'"' if input.rest[i + 1..].starts_with(delimiter) => {
let rest = input.advance(i + 1 + delimiter.len());
return Ok(literal_suffix(rest));
}
'\r' => match chars.next() {
Expand Down

0 comments on commit 01e74f7

Please sign in to comment.