Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ascii: Apply codereview
  • Loading branch information
corona10 committed Jul 31, 2019
commit fafeed14502b9f79ccef1a17c2baddad0722125f
14 changes: 8 additions & 6 deletions vm/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down