@@ -7,13 +7,13 @@ use ast::*;
77
88
99impl ast:: ComponentValue {
10- pub fn to_css ( & mut self ) -> ~ str {
11- let mut css = ~"" ;
10+ pub fn to_css ( & mut self ) -> StrBuf {
11+ let mut css = StrBuf :: new ( ) ;
1212 self . to_css_push ( & mut css) ;
1313 css
1414 }
1515
16- pub fn to_css_push ( & self , css : & mut ~ str ) {
16+ pub fn to_css_push ( & self , css : & mut StrBuf ) {
1717 match * self {
1818 Ident ( ref value) => serialize_identifier ( value. as_slice ( ) , css) ,
1919 AtKeyword ( ref value) => {
@@ -22,7 +22,7 @@ impl ast::ComponentValue {
2222 } ,
2323 Hash ( ref value) => {
2424 css. push_char ( '#' ) ;
25- for c in value. chars ( ) {
25+ for c in value. as_slice ( ) . chars ( ) {
2626 serialize_char ( c, css, /* is_identifier_start = */ false ) ;
2727 }
2828 } ,
@@ -38,13 +38,13 @@ impl ast::ComponentValue {
3838 } ,
3939 Delim ( value) => css. push_char ( value) ,
4040
41- Number ( ref value) => css. push_str ( value. representation ) ,
41+ Number ( ref value) => css. push_str ( value. representation . as_slice ( ) ) ,
4242 Percentage ( ref value) => {
43- css. push_str ( value. representation ) ;
43+ css. push_str ( value. representation . as_slice ( ) ) ;
4444 css. push_char ( '%' ) ;
4545 } ,
4646 Dimension ( ref value, ref unit) => {
47- css. push_str ( value. representation ) ;
47+ css. push_str ( value. representation . as_slice ( ) ) ;
4848 // Disambiguate with scientific notation.
4949 let unit = unit. as_slice ( ) ;
5050 if unit == "e" || unit == "E" || unit. starts_with ( "e-" ) || unit. starts_with ( "E-" ) {
@@ -109,7 +109,7 @@ impl ast::ComponentValue {
109109}
110110
111111
112- pub fn serialize_identifier ( value : & str , css : & mut ~ str ) {
112+ pub fn serialize_identifier ( value : & str , css : & mut StrBuf ) {
113113 // TODO: avoid decoding/re-encoding UTF-8?
114114 let mut iter = value. chars ( ) ;
115115 let mut c = iter. next ( ) . unwrap ( ) ;
@@ -127,7 +127,7 @@ pub fn serialize_identifier(value: &str, css: &mut ~str) {
127127
128128
129129#[ inline]
130- fn serialize_char ( c : char , css : & mut ~ str , is_identifier_start : bool ) {
130+ fn serialize_char ( c : char , css : & mut StrBuf , is_identifier_start : bool ) {
131131 match c {
132132 '0' ..'9' if is_identifier_start => css. push_str ( format ! ( "\\ \\ 3{} " , c) ) ,
133133 '-' if is_identifier_start => css. push_str ( "\\ -" ) ,
@@ -141,7 +141,7 @@ fn serialize_char(c: char, css: &mut ~str, is_identifier_start: bool) {
141141}
142142
143143
144- pub fn serialize_string ( value : & str , css : & mut ~ str ) {
144+ pub fn serialize_string ( value : & str , css : & mut StrBuf ) {
145145 css. push_char ( '"' ) ;
146146 // TODO: avoid decoding/re-encoding UTF-8?
147147 for c in value. chars ( ) {
@@ -159,18 +159,18 @@ pub fn serialize_string(value: &str, css: &mut ~str) {
159159
160160
161161pub trait ToCss {
162- fn to_css ( & mut self ) -> ~ str {
163- let mut css = ~"" ;
162+ fn to_css ( & mut self ) -> StrBuf {
163+ let mut css = StrBuf :: new ( ) ;
164164 self . to_css_push ( & mut css) ;
165165 css
166166 }
167167
168- fn to_css_push ( & mut self , css : & mut ~ str ) ;
168+ fn to_css_push ( & mut self , css : & mut StrBuf ) ;
169169}
170170
171171
172172impl < ' a , I : Iterator < & ' a ComponentValue > > ToCss for I {
173- fn to_css_push ( & mut self , css : & mut ~ str ) {
173+ fn to_css_push ( & mut self , css : & mut StrBuf ) {
174174 let mut previous = match self . next ( ) {
175175 None => return ,
176176 Some ( first) => { first. to_css_push ( css) ; first }
0 commit comments