ascii: Apply codereview

This commit is contained in:
Dong-hee Na
2019-07-31 19:44:06 +09:00
parent 5bfa4cec7c
commit fafeed1450

View File

@@ -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)