Skip to content

Commit 3c20a59

Browse files
committed
Skip utf-8 decode during parsing raw strings
1 parent 1244b5c commit 3c20a59

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/parse.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,15 @@ fn cooked_string(input: Cursor) -> Result<Cursor, Reject> {
419419

420420
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
421421
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) => {
422+
let mut bytes = input.bytes().enumerate();
423+
while let Some((i, byte)) = bytes.next() {
424+
match byte {
425+
b'"' if input.rest[i + 1..].starts_with(delimiter) => {
426426
let rest = input.advance(i + 1 + delimiter.len());
427427
return Ok(literal_suffix(rest));
428428
}
429-
'\r' => match chars.next() {
430-
Some((_, '\n')) => {}
429+
b'\r' => match bytes.next() {
430+
Some((_, b'\n')) => {}
431431
_ => break,
432432
},
433433
_ => {}
@@ -518,15 +518,15 @@ fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> {
518518

519519
fn raw_byte_string(input: Cursor) -> Result<Cursor, Reject> {
520520
let (input, delimiter) = delimiter_of_raw_string(input)?;
521-
let mut chars = input.char_indices();
522-
while let Some((i, ch)) = chars.next() {
523-
match ch {
524-
'"' if input.rest[i + 1..].starts_with(delimiter) => {
521+
let mut bytes = input.bytes().enumerate();
522+
while let Some((i, byte)) = bytes.next() {
523+
match byte {
524+
b'"' if input.rest[i + 1..].starts_with(delimiter) => {
525525
let rest = input.advance(i + 1 + delimiter.len());
526526
return Ok(literal_suffix(rest));
527527
}
528-
'\r' => match chars.next() {
529-
Some((_, '\n')) => {}
528+
b'\r' => match bytes.next() {
529+
Some((_, b'\n')) => {}
530530
_ => break,
531531
},
532532
other => {

0 commit comments

Comments
 (0)