Skip to content

Commit b900eb7

Browse files
committed
Rename some unescaping functions.
`unescape_raw_str_or_raw_byte_str` only does checking, no unescaping. And it also now handles C string literals. `unescape_raw_str` is used for all the non-raw strings.
1 parent a50efe2 commit b900eb7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

compiler/rustc_lexer/src/unescape.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ where
9292
let res = unescape_char_or_byte(&mut chars, mode);
9393
callback(0..(src.len() - chars.as_str().len()), res);
9494
}
95-
Str | ByteStr => unescape_str_common(src, mode, callback),
96-
RawStr | RawByteStr => unescape_raw_str_or_raw_byte_str(src, mode, callback),
95+
Str | ByteStr => unescape_non_raw_common(src, mode, callback),
96+
RawStr | RawByteStr => check_raw_common(src, mode, callback),
9797
CStr | RawCStr => unreachable!(),
9898
}
9999
}
@@ -122,12 +122,10 @@ where
122122
{
123123
match mode {
124124
CStr => {
125-
unescape_str_common(src, mode, callback);
125+
unescape_non_raw_common(src, mode, callback);
126126
}
127127
RawCStr => {
128-
unescape_raw_str_or_raw_byte_str(src, mode, &mut |r, result| {
129-
callback(r, result.map(CStrUnit::Char))
130-
});
128+
check_raw_common(src, mode, &mut |r, result| callback(r, result.map(CStrUnit::Char)));
131129
}
132130
Char | Byte | Str | RawStr | ByteStr | RawByteStr => unreachable!(),
133131
}
@@ -325,7 +323,7 @@ fn unescape_char_or_byte(chars: &mut Chars<'_>, mode: Mode) -> Result<char, Esca
325323

326324
/// Takes a contents of a string literal (without quotes) and produces a
327325
/// sequence of escaped characters or errors.
328-
fn unescape_str_common<F, T: From<u8> + From<char>>(src: &str, mode: Mode, callback: &mut F)
326+
fn unescape_non_raw_common<F, T: From<u8> + From<char>>(src: &str, mode: Mode, callback: &mut F)
329327
where
330328
F: FnMut(Range<usize>, Result<T, EscapeError>),
331329
{
@@ -392,15 +390,15 @@ where
392390
/// sequence of characters or errors.
393391
/// NOTE: Raw strings do not perform any explicit character escaping, here we
394392
/// only produce errors on bare CR.
395-
fn unescape_raw_str_or_raw_byte_str<F>(src: &str, mode: Mode, callback: &mut F)
393+
fn check_raw_common<F>(src: &str, mode: Mode, callback: &mut F)
396394
where
397395
F: FnMut(Range<usize>, Result<char, EscapeError>),
398396
{
399397
let mut chars = src.chars();
400398
let chars_should_be_ascii = mode.chars_should_be_ascii(); // get this outside the loop
401399

402400
// The `start` and `end` computation here matches the one in
403-
// `unescape_str_common` for consistency, even though this function
401+
// `unescape_non_raw_common` for consistency, even though this function
404402
// doesn't have to worry about skipping any chars.
405403
while let Some(c) = chars.next() {
406404
let start = src.len() - chars.as_str().len() - c.len_utf8();

0 commit comments

Comments
 (0)