Skip to content

Commit 8214af3

Browse files
committed
Replace format! with Option<&str>
1 parent 2b0681f commit 8214af3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/serializer.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,20 @@ impl<'a, W> fmt::Write for CssStringWriter<'a, W> where W: fmt::Write {
250250
fn write_str(&mut self, s: &str) -> fmt::Result {
251251
let mut chunk_start = 0;
252252
for (i, b) in s.bytes().enumerate() {
253-
let string;
254253
let escaped = match b {
255-
b'"' => "\\\"",
256-
b'\\' => "\\\\",
257-
b'\n' => "\\A ",
258-
b'\r' => "\\D ",
259-
b'\0' => "\u{FFFD}",
260-
b'\x01'...b'\x1F' | b'\x7F' => {
261-
string = format!("\\{:x} ", b);
262-
&string
263-
},
254+
b'"' => Some("\\\""),
255+
b'\\' => Some("\\\\"),
256+
b'\n' => Some("\\A "),
257+
b'\r' => Some("\\D "),
258+
b'\0' => Some("\u{FFFD}"),
259+
b'\x01'...b'\x1F' | b'\x7F' => None,
264260
_ => continue,
265261
};
266262
try!(self.inner.write_str(&s[chunk_start..i]));
267-
try!(self.inner.write_str(escaped));
263+
match escaped {
264+
Some(x) => try!(self.inner.write_str(x)),
265+
None => try!(write!(self.inner, "\\{:x} ", b)),
266+
};
268267
chunk_start = i + 1;
269268
}
270269
self.inner.write_str(&s[chunk_start..])

0 commit comments

Comments
 (0)