Extract unescape from rustc_lexer into its own crate
This commit is contained in:
@@ -5,6 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
literal-escaper = { path = "../../library/literal-escaper" }
|
||||
rustc_index = { path = "../rustc_index", default-features = false }
|
||||
rustc_lexer = { path = "../rustc_lexer" }
|
||||
# tidy-alphabetical-end
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
pub use Alignment::*;
|
||||
pub use Count::*;
|
||||
pub use Position::*;
|
||||
use rustc_lexer::unescape;
|
||||
|
||||
// Note: copied from rustc_span
|
||||
/// Range inside of a `Span` used for diagnostics when we only have access to relative positions.
|
||||
@@ -1095,12 +1094,14 @@ fn find_width_map_from_snippet(
|
||||
fn unescape_string(string: &str) -> Option<String> {
|
||||
let mut buf = String::new();
|
||||
let mut ok = true;
|
||||
unescape::unescape_unicode(string, unescape::Mode::Str, &mut |_, unescaped_char| {
|
||||
match unescaped_char {
|
||||
literal_escaper::unescape_unicode(
|
||||
string,
|
||||
literal_escaper::Mode::Str,
|
||||
&mut |_, unescaped_char| match unescaped_char {
|
||||
Ok(c) => buf.push(c),
|
||||
Err(_) => ok = false,
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
ok.then_some(buf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user