File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1+ use std:: fmt:: Write ;
12use std:: collections:: BTreeMap ;
23use std:: str:: FromStr ;
34
@@ -51,7 +52,7 @@ impl LispObject {
5152 } else if ( c as u32 ) < 32 || ( c as u32 ) == 127 {
5253 // not printable
5354 // NOTE: cannot use escape for c in 128..=255, otherwise the string would become unibyte
54- result += & format ! ( "\\ {:03o}" , c as u32 ) ;
55+ write ! ( result , "\\ {:03o}" , c as u32 ) . unwrap ( ) ;
5556 } else {
5657 result. push ( c) ;
5758 }
@@ -78,14 +79,14 @@ impl LispObject {
7879 27 => result += "\\ e" ,
7980 // NOTE: do not use 0..=7 in this branch, because it takes one more byte than the next branch
8081 8 ..=26 => { // \^@ \^A \^B ... \^Z
81- result += & format ! ( "\\ ^{}" , ( * c as u32 + 64 ) as u8 as char ) ;
82+ write ! ( & mut result , "\\ ^{}" , ( * c as u32 + 64 ) as u8 as char ) . unwrap ( ) ;
8283 } ,
8384 0 ..=7 | 27 ..=31 | 128 ..=255 | 34 | 92 => { // oct, for unprintable and '"' and '\\'
84- let oct_s = format ! ( "\\ {:o}" , * c as u32 ) ;
85- if oct_s. len ( ) < 4 {
85+ let last_len = result. len ( ) ;
86+ write ! ( result, "\\ {:o}" , * c as u32 ) . unwrap ( ) ;
87+ if result. len ( ) - last_len < 4 {
8688 oct_escape_not_full = true ;
8789 }
88- result += & oct_s;
8990 } ,
9091 _ => { // printable
9192 // https://www.gnu.org/software/emacs/manual/html_node/elisp/Non_002dASCII-in-St
You can’t perform that action at this time.
0 commit comments