From 51f920dd62aef70bd0a85199bea4821cd10e15d9 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 3 Apr 2018 21:20:27 +1000 Subject: [PATCH] Have UnicodeRange not serialize question marks. --- Cargo.toml | 2 +- src/unicode_range.rs | 30 +++--------------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbd5593b..130b86f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.23.3" +version = "0.23.4" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3" diff --git a/src/unicode_range.rs b/src/unicode_range.rs index f6a4b704..5cdb665c 100644 --- a/src/unicode_range.rs +++ b/src/unicode_range.rs @@ -6,7 +6,6 @@ use {Parser, ToCss, BasicParseError}; use std::char; -use std::cmp; use std::fmt; use tokenizer::Token; @@ -166,32 +165,9 @@ impl fmt::Debug for UnicodeRange { impl ToCss for UnicodeRange { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - dest.write_str("U+")?; - - // How many bits are 0 at the end of start and also 1 at the end of end. - let bits = cmp::min(self.start.trailing_zeros(), (!self.end).trailing_zeros()); - - let question_marks = bits / 4; - - // How many lower bits can be represented as question marks - let bits = question_marks * 4; - - let truncated_start = self.start >> bits; - let truncated_end = self.end >> bits; - if truncated_start == truncated_end { - // Bits not covered by question marks are the same in start and end, - // we can use the question mark syntax. - if truncated_start != 0 { - write!(dest, "{:X}", truncated_start)?; - } - for _ in 0..question_marks { - dest.write_str("?")?; - } - } else { - write!(dest, "{:X}", self.start)?; - if self.end != self.start { - write!(dest, "-{:X}", self.end)?; - } + write!(dest, "U+{:X}", self.start)?; + if self.end != self.start { + write!(dest, "-{:X}", self.end)?; } Ok(()) }