Skip to content

Commit a58fae9

Browse files
committed
Merge pull request servo#16 from brson/master
Use char::from_u32 to cast to char
2 parents 56b3cb3 + a41aec5 commit a58fae9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tokenizer.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// http://dev.w3.org/csswg/css3-syntax/#tokenization
66

7-
use std::{str, u32, i64, f64};
7+
use std::{char, str, u32, i64, f64};
88
use std::ascii::StrAsciiExt;
99

1010
use ast::*;
@@ -593,10 +593,14 @@ fn consume_escape(tokenizer: &mut Tokenizer) -> char {
593593
_ => ()
594594
}
595595
}
596-
let c = u32::from_str_radix(hex, 16).unwrap() as char as char;
597-
static MAX_UNICODE: char = '\U0010FFFF';
598-
if '\x00' < c && c <= MAX_UNICODE { c }
599-
else { '\uFFFD' } // Replacement character
596+
static REPLACEMENT_CHAR: char = '\uFFFD';
597+
let c = u32::from_str_radix(hex, 16).unwrap();
598+
if c != 0 {
599+
let c = char::from_u32(c);
600+
c.unwrap_or_default(REPLACEMENT_CHAR)
601+
} else {
602+
REPLACEMENT_CHAR
603+
}
600604
},
601605
c => c
602606
}

0 commit comments

Comments
 (0)