Skip to content

Commit ac56ac4

Browse files
committed
Consistent way to check for \n after \r
1 parent 72f39fa commit ac56ac4

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/parse.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,10 @@ fn cooked_string(input: Cursor) -> Result<Cursor, LexError> {
340340
let input = input.advance(i + 1);
341341
return Ok(literal_suffix(input));
342342
}
343-
'\r' => {
344-
if let Some((_, '\n')) = chars.next() {
345-
// ...
346-
} else {
347-
break;
348-
}
349-
}
343+
'\r' => match chars.next() {
344+
Some((_, '\n')) => {}
345+
_ => break,
346+
},
350347
'\\' => match chars.next() {
351348
Some((_, 'x')) => {
352349
if !backslash_x_char(&mut chars) {
@@ -401,13 +398,10 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, LexError> {
401398
let input = input.advance(offset + 1);
402399
return Ok(literal_suffix(input));
403400
}
404-
b'\r' => {
405-
if let Some((_, b'\n')) = bytes.next() {
406-
// ...
407-
} else {
408-
break;
409-
}
410-
}
401+
b'\r' => match bytes.next() {
402+
Some((_, b'\n')) => {}
403+
_ => break,
404+
},
411405
b'\\' => match bytes.next() {
412406
Some((_, b'x')) => {
413407
if !backslash_x_byte(&mut bytes) {
@@ -463,11 +457,10 @@ fn raw_string(input: Cursor) -> Result<Cursor, LexError> {
463457
let rest = input.advance(i + 1 + n);
464458
return Ok(literal_suffix(rest));
465459
}
466-
'\r' => {
467-
if chars.next().map_or(true, |(_, ch)| ch != '\n') {
468-
return Err(LexError);
469-
}
470-
}
460+
'\r' => match chars.next() {
461+
Some((_, '\n')) => {}
462+
_ => break,
463+
},
471464
_ => {}
472465
}
473466
}

0 commit comments

Comments
 (0)