mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Refactor common::bytes::repr using common::escape
This commit is contained in:
parent
bbbe25336a
commit
e09b23d3fb
2 changed files with 9 additions and 7 deletions
|
@ -41,12 +41,13 @@ 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) => {
|
||||
use rustpython_common::escape::Escape;
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(s.as_str()).write_quoted(f)
|
||||
}
|
||||
Constant::Str(s) => rustpython_common::escape::UnicodeEscape::new_repr(s.as_str())
|
||||
.str_repr()
|
||||
.write(f),
|
||||
Constant::Bytes(b) => {
|
||||
f.pad(&rustpython_common::bytes::repr(b).map_err(|_err| std::fmt::Error)?)
|
||||
let escape = rustpython_common::escape::AsciiEscape::new_repr(b);
|
||||
let repr = escape.bytes_repr().to_string().unwrap();
|
||||
f.pad(&repr)
|
||||
}
|
||||
Constant::Int(i) => i.fmt(f),
|
||||
Constant::Tuple(tup) => {
|
||||
|
|
|
@ -509,10 +509,11 @@ 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));
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(&body).write_quoted(&mut self.f)
|
||||
rustpython_common::escape::UnicodeEscape::new_repr(&body)
|
||||
.str_repr()
|
||||
.write(&mut self.f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue