Skip to content

Commit 01e74f7

Browse files
committed
Split out function to parse ###" prefix of raw strings
1 parent 231a097 commit 01e74f7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/parse.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,9 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
478478
Err(Reject)
479479
}
480480

481-
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
482-
let mut chars = input.char_indices();
481+
fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> {
483482
let mut n = 0;
484-
for (i, ch) in &mut chars {
483+
for (i, ch) in input.char_indices() {
485484
match ch {
486485
'"' => {
487486
n = i;
@@ -495,10 +494,16 @@ fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
495494
// https://github.com/rust-lang/rust/pull/95251
496495
return Err(Reject);
497496
}
497+
Ok((input.advance(n + 1), &input.rest[..n]))
498+
}
499+
500+
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
501+
let (input, delimiter) = delimiter_of_raw_string(input)?;
502+
let mut chars = input.char_indices();
498503
while let Some((i, ch)) = chars.next() {
499504
match ch {
500-
'"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => {
501-
let rest = input.advance(i + 1 + n);
505+
'"' if input.rest[i + 1..].starts_with(delimiter) => {
506+
let rest = input.advance(i + 1 + delimiter.len());
502507
return Ok(literal_suffix(rest));
503508
}
504509
'\r' => match chars.next() {

0 commit comments

Comments
 (0)