Skip to content

Commit c97ba60

Browse files
authored
serializer: Use match_byte in the serializer. (#361)
1 parent 88134d4 commit c97ba60

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/serializer.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
use crate::match_byte;
56
use dtoa_short::{self, Notation};
67
use itoa;
78
use std::fmt::{self, Write};
@@ -226,11 +227,15 @@ where
226227
{
227228
let mut chunk_start = 0;
228229
for (i, b) in value.bytes().enumerate() {
229-
let escaped = match b {
230+
let escaped = match_byte! { b,
230231
b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'_' | b'-' => continue,
231-
_ if !b.is_ascii() => continue,
232232
b'\0' => Some("\u{FFFD}"),
233-
_ => None,
233+
b => {
234+
if !b.is_ascii() {
235+
continue;
236+
}
237+
None
238+
},
234239
};
235240
dest.write_str(&value[chunk_start..i])?;
236241
if let Some(escaped) = escaped {
@@ -251,7 +256,7 @@ where
251256
{
252257
let mut chunk_start = 0;
253258
for (i, b) in value.bytes().enumerate() {
254-
let hex = match b {
259+
let hex = match_byte! { b,
255260
b'\0'..=b' ' | b'\x7F' => true,
256261
b'(' | b')' | b'"' | b'\'' | b'\\' => false,
257262
_ => continue,
@@ -304,7 +309,7 @@ where
304309
{
305310
/// Wrap a text writer to create a `CssStringWriter`.
306311
pub fn new(inner: &'a mut W) -> CssStringWriter<'a, W> {
307-
CssStringWriter { inner: inner }
312+
CssStringWriter { inner }
308313
}
309314
}
310315

@@ -315,7 +320,7 @@ where
315320
fn write_str(&mut self, s: &str) -> fmt::Result {
316321
let mut chunk_start = 0;
317322
for (i, b) in s.bytes().enumerate() {
318-
let escaped = match b {
323+
let escaped = match_byte! { b,
319324
b'"' => Some("\\\""),
320325
b'\\' => Some("\\\\"),
321326
b'\0' => Some("\u{FFFD}"),

0 commit comments

Comments
 (0)