mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Refactor common::str::repr using common::escape
This commit is contained in:
parent
31fd625321
commit
bbbe25336a
2 changed files with 6 additions and 2 deletions
|
@ -41,7 +41,10 @@ impl std::fmt::Display for Constant {
|
|||
match self {
|
||||
Constant::None => f.pad("None"),
|
||||
Constant::Bool(b) => f.pad(if *b { "True" } else { "False" }),
|
||||
Constant::Str(s) => rustpython_common::str::repr(s).fmt(f),
|
||||
Constant::Str(s) => {
|
||||
use rustpython_common::escape::Escape;
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(s.as_str()).write_quoted(f)
|
||||
}
|
||||
Constant::Bytes(b) => {
|
||||
f.pad(&rustpython_common::bytes::repr(b).map_err(|_err| std::fmt::Error)?)
|
||||
}
|
||||
|
|
|
@ -509,9 +509,10 @@ impl<'a> Unparser<'a> {
|
|||
if is_spec {
|
||||
self.unparse_fstring_body(values, is_spec)
|
||||
} else {
|
||||
use rustpython_common::escape::Escape;
|
||||
self.p("f")?;
|
||||
let body = to_string_fmt(|f| Unparser::new(f).unparse_fstring_body(values, is_spec));
|
||||
fmt::Display::fmt(&rustpython_common::str::repr(&body), &mut self.f)
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(&body).write_quoted(&mut self.f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue