@@ -143,7 +143,9 @@ impl Color {
143143 /// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
144144 pub fn parse ( input : & mut Parser ) -> Result < Color , ( ) > {
145145 match try!( input. next ( ) ) {
146- Token :: Hash ( value) | Token :: IDHash ( value) => parse_color_hash ( & * value) ,
146+ Token :: Hash ( value) | Token :: IDHash ( value) => {
147+ Color :: parse_hash ( value. as_bytes ( ) )
148+ } ,
147149 Token :: Ident ( value) => parse_color_keyword ( & * value) ,
148150 Token :: Function ( name) => {
149151 input. parse_nested_block ( |arguments| {
@@ -153,6 +155,37 @@ impl Color {
153155 _ => Err ( ( ) )
154156 }
155157 }
158+
159+ /// Parse a color hash, without the leading '#' character.
160+ #[ inline]
161+ fn parse_hash ( value : & [ u8 ] ) -> Result < Self , ( ) > {
162+ match value. len ( ) {
163+ 8 => rgba (
164+ try!( from_hex ( value[ 0 ] ) ) * 16 + try!( from_hex ( value[ 1 ] ) ) ,
165+ try!( from_hex ( value[ 2 ] ) ) * 16 + try!( from_hex ( value[ 3 ] ) ) ,
166+ try!( from_hex ( value[ 4 ] ) ) * 16 + try!( from_hex ( value[ 5 ] ) ) ,
167+ try!( from_hex ( value[ 6 ] ) ) * 16 + try!( from_hex ( value[ 7 ] ) ) ,
168+ ) ,
169+ 6 => rgb (
170+ try!( from_hex ( value[ 0 ] ) ) * 16 + try!( from_hex ( value[ 1 ] ) ) ,
171+ try!( from_hex ( value[ 2 ] ) ) * 16 + try!( from_hex ( value[ 3 ] ) ) ,
172+ try!( from_hex ( value[ 4 ] ) ) * 16 + try!( from_hex ( value[ 5 ] ) ) ,
173+ ) ,
174+ 4 => rgba (
175+ try!( from_hex ( value[ 0 ] ) ) * 17 ,
176+ try!( from_hex ( value[ 1 ] ) ) * 17 ,
177+ try!( from_hex ( value[ 2 ] ) ) * 17 ,
178+ try!( from_hex ( value[ 3 ] ) ) * 17 ,
179+ ) ,
180+ 3 => rgb (
181+ try!( from_hex ( value[ 0 ] ) ) * 17 ,
182+ try!( from_hex ( value[ 1 ] ) ) * 17 ,
183+ try!( from_hex ( value[ 2 ] ) ) * 17 ,
184+ ) ,
185+ _ => Err ( ( ) )
186+ }
187+ }
188+
156189}
157190
158191
@@ -354,37 +387,6 @@ fn from_hex(c: u8) -> Result<u8, ()> {
354387 }
355388}
356389
357-
358- #[ inline]
359- fn parse_color_hash ( value : & str ) -> Result < Color , ( ) > {
360- let value = value. as_bytes ( ) ;
361- match value. len ( ) {
362- 8 => rgba (
363- try!( from_hex ( value[ 0 ] ) ) * 16 + try!( from_hex ( value[ 1 ] ) ) ,
364- try!( from_hex ( value[ 2 ] ) ) * 16 + try!( from_hex ( value[ 3 ] ) ) ,
365- try!( from_hex ( value[ 4 ] ) ) * 16 + try!( from_hex ( value[ 5 ] ) ) ,
366- try!( from_hex ( value[ 6 ] ) ) * 16 + try!( from_hex ( value[ 7 ] ) ) ,
367- ) ,
368- 6 => rgb (
369- try!( from_hex ( value[ 0 ] ) ) * 16 + try!( from_hex ( value[ 1 ] ) ) ,
370- try!( from_hex ( value[ 2 ] ) ) * 16 + try!( from_hex ( value[ 3 ] ) ) ,
371- try!( from_hex ( value[ 4 ] ) ) * 16 + try!( from_hex ( value[ 5 ] ) ) ,
372- ) ,
373- 4 => rgba (
374- try!( from_hex ( value[ 0 ] ) ) * 17 ,
375- try!( from_hex ( value[ 1 ] ) ) * 17 ,
376- try!( from_hex ( value[ 2 ] ) ) * 17 ,
377- try!( from_hex ( value[ 3 ] ) ) * 17 ,
378- ) ,
379- 3 => rgb (
380- try!( from_hex ( value[ 0 ] ) ) * 17 ,
381- try!( from_hex ( value[ 1 ] ) ) * 17 ,
382- try!( from_hex ( value[ 2 ] ) ) * 17 ,
383- ) ,
384- _ => Err ( ( ) )
385- }
386- }
387-
388390fn clamp_unit_f32 ( val : f32 ) -> u8 {
389391 // Whilst scaling by 256 and flooring would provide
390392 // an equal distribution of integers to percentage inputs,
0 commit comments