mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
ascii: Apply codereview
This commit is contained in:
@@ -64,13 +64,15 @@ fn builtin_ascii(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let mut ascii = String::new();
|
||||
for c in repr.value.chars() {
|
||||
if c.is_ascii() {
|
||||
ascii.push(c);
|
||||
} else if (c as i64) < 0x10000 {
|
||||
let hex = format!("\\u{:04x}", c as i64);
|
||||
ascii.push_str(&hex);
|
||||
ascii.push(c)
|
||||
} else {
|
||||
let hex = format!("\\U{:08x}", c as i64);
|
||||
ascii.push_str(&hex);
|
||||
let c = c as i64;
|
||||
let hex = if c < 0x10000 {
|
||||
format!("\\u{:04x}", c)
|
||||
} else {
|
||||
format!("\\U{:08x}", c)
|
||||
};
|
||||
ascii.push_str(&hex)
|
||||
}
|
||||
}
|
||||
Ok(ascii)
|
||||
|
||||
Reference in New Issue
Block a user