Rename the unescaping functions.

`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string`
becomes `unescape_mixed`. Because rfc3349 will mean that C string
literals will no longer be the only mixed utf8 literals.
This commit is contained in:
Nicholas Nethercote 2024-01-24 15:24:58 +11:00
parent 56514076ac
commit 858f4aca6c
3 changed files with 14 additions and 14 deletions

View File

@ -379,14 +379,14 @@ fn unescape_string_error_message(text: &str, mode: Mode) -> &'static str {
let mut error_message = ""; let mut error_message = "";
match mode { match mode {
Mode::CStr => { Mode::CStr => {
rustc_lexer::unescape::unescape_c_string(text, mode, &mut |_, res| { rustc_lexer::unescape::unescape_mixed(text, mode, &mut |_, res| {
if let Err(e) = res { if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode); error_message = error_to_diagnostic_message(e, mode);
} }
}); });
} }
Mode::ByteStr | Mode::Str => { Mode::ByteStr | Mode::Str => {
rustc_lexer::unescape::unescape_literal(text, mode, &mut |_, res| { rustc_lexer::unescape::unescape_unicode(text, mode, &mut |_, res| {
if let Err(e) = res { if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode); error_message = error_to_diagnostic_message(e, mode);
} }

View File

@ -6,7 +6,7 @@
}; };
use rustc_lexer::unescape::{ use rustc_lexer::unescape::{
unescape_byte, unescape_c_string, unescape_char, unescape_literal, MixedUnit, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
}; };
use crate::{ use crate::{
@ -193,7 +193,7 @@ fn escaped_char_ranges(
let text = &self.text()[text_range_no_quotes - start]; let text = &self.text()[text_range_no_quotes - start];
let offset = text_range_no_quotes.start() - start; let offset = text_range_no_quotes.start() - start;
unescape_literal(text, Self::MODE, &mut |range, unescaped_char| { unescape_unicode(text, Self::MODE, &mut |range, unescaped_char| {
let text_range = let text_range =
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()); TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
cb(text_range + offset, unescaped_char); cb(text_range + offset, unescaped_char);
@ -226,7 +226,7 @@ pub fn value(&self) -> Option<Cow<'_, str>> {
let mut buf = String::new(); let mut buf = String::new();
let mut prev_end = 0; let mut prev_end = 0;
let mut has_error = false; let mut has_error = false;
unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match ( unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
unescaped_char, unescaped_char,
buf.capacity() == 0, buf.capacity() == 0,
) { ) {
@ -270,7 +270,7 @@ pub fn value(&self) -> Option<Cow<'_, [u8]>> {
let mut buf: Vec<u8> = Vec::new(); let mut buf: Vec<u8> = Vec::new();
let mut prev_end = 0; let mut prev_end = 0;
let mut has_error = false; let mut has_error = false;
unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match ( unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
unescaped_char, unescaped_char,
buf.capacity() == 0, buf.capacity() == 0,
) { ) {
@ -311,7 +311,7 @@ fn escaped_char_ranges(
let text = &self.text()[text_range_no_quotes - start]; let text = &self.text()[text_range_no_quotes - start];
let offset = text_range_no_quotes.start() - start; let offset = text_range_no_quotes.start() - start;
unescape_c_string(text, Self::MODE, &mut |range, unescaped_char| { unescape_mixed(text, Self::MODE, &mut |range, unescaped_char| {
let text_range = let text_range =
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()); TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
// XXX: This method should only be used for highlighting ranges. The unescaped // XXX: This method should only be used for highlighting ranges. The unescaped
@ -340,7 +340,7 @@ pub fn value(&self) -> Option<Cow<'_, [u8]>> {
MixedUnit::Char(c) => buf.extend(c.encode_utf8(&mut [0; 4]).as_bytes()), MixedUnit::Char(c) => buf.extend(c.encode_utf8(&mut [0; 4]).as_bytes()),
MixedUnit::HighByte(b) => buf.push(b), MixedUnit::HighByte(b) => buf.push(b),
}; };
unescape_c_string(text, Self::MODE, &mut |char_range, unescaped| match ( unescape_mixed(text, Self::MODE, &mut |char_range, unescaped| match (
unescaped, unescaped,
buf.capacity() == 0, buf.capacity() == 0,
) { ) {

View File

@ -5,7 +5,7 @@
mod block; mod block;
use rowan::Direction; use rowan::Direction;
use rustc_lexer::unescape::{self, unescape_c_string, unescape_literal, Mode}; use rustc_lexer::unescape::{self, unescape_mixed, unescape_unicode, Mode};
use crate::{ use crate::{
algo, algo,
@ -140,7 +140,7 @@ fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
ast::LiteralKind::String(s) => { ast::LiteralKind::String(s) => {
if !s.is_raw() { if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 1, '"') { if let Some(without_quotes) = unquote(text, 1, '"') {
unescape_literal(without_quotes, Mode::Str, &mut |range, char| { unescape_unicode(without_quotes, Mode::Str, &mut |range, char| {
if let Err(err) = char { if let Err(err) = char {
push_err(1, range.start, err); push_err(1, range.start, err);
} }
@ -151,7 +151,7 @@ fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
ast::LiteralKind::ByteString(s) => { ast::LiteralKind::ByteString(s) => {
if !s.is_raw() { if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') { if let Some(without_quotes) = unquote(text, 2, '"') {
unescape_literal(without_quotes, Mode::ByteStr, &mut |range, char| { unescape_unicode(without_quotes, Mode::ByteStr, &mut |range, char| {
if let Err(err) = char { if let Err(err) = char {
push_err(1, range.start, err); push_err(1, range.start, err);
} }
@ -162,7 +162,7 @@ fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
ast::LiteralKind::CString(s) => { ast::LiteralKind::CString(s) => {
if !s.is_raw() { if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') { if let Some(without_quotes) = unquote(text, 2, '"') {
unescape_c_string(without_quotes, Mode::CStr, &mut |range, char| { unescape_mixed(without_quotes, Mode::CStr, &mut |range, char| {
if let Err(err) = char { if let Err(err) = char {
push_err(1, range.start, err); push_err(1, range.start, err);
} }
@ -172,7 +172,7 @@ fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
} }
ast::LiteralKind::Char(_) => { ast::LiteralKind::Char(_) => {
if let Some(without_quotes) = unquote(text, 1, '\'') { if let Some(without_quotes) = unquote(text, 1, '\'') {
unescape_literal(without_quotes, Mode::Char, &mut |range, char| { unescape_unicode(without_quotes, Mode::Char, &mut |range, char| {
if let Err(err) = char { if let Err(err) = char {
push_err(1, range.start, err); push_err(1, range.start, err);
} }
@ -181,7 +181,7 @@ fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
} }
ast::LiteralKind::Byte(_) => { ast::LiteralKind::Byte(_) => {
if let Some(without_quotes) = unquote(text, 2, '\'') { if let Some(without_quotes) = unquote(text, 2, '\'') {
unescape_literal(without_quotes, Mode::Byte, &mut |range, char| { unescape_unicode(without_quotes, Mode::Byte, &mut |range, char| {
if let Err(err) = char { if let Err(err) = char {
push_err(2, range.start, err); push_err(2, range.start, err);
} }