diff --git a/ast.rs b/ast.rs index c76289d1..a75ddf50 100644 --- a/ast.rs +++ b/ast.rs @@ -9,7 +9,7 @@ use std::vec; #[deriving(Eq)] pub struct NumericValue { - pub representation: StrBuf, + pub representation: String, pub value: f64, pub int_value: Option, } @@ -28,16 +28,16 @@ pub type Node = (ComponentValue, SourceLocation); // TODO this is not a good na #[deriving(Eq)] pub enum ComponentValue { // Preserved tokens. - Ident(StrBuf), - AtKeyword(StrBuf), - Hash(StrBuf), - IDHash(StrBuf), // Hash that is a valid ID selector. - String(StrBuf), - URL(StrBuf), + Ident(String), + AtKeyword(String), + Hash(String), + IDHash(String), // Hash that is a valid ID selector. + String(String), + URL(String), Delim(char), Number(NumericValue), Percentage(NumericValue), - Dimension(NumericValue, StrBuf), + Dimension(NumericValue, String), UnicodeRange(u32, u32), // (start, end) of range WhiteSpace, Colon, // : @@ -53,7 +53,7 @@ pub enum ComponentValue { CDC, // --> // Function - Function(StrBuf, Vec), // name, arguments + Function(String, Vec), // name, arguments // Simple block ParenthesisBlock(Vec), // (…) @@ -72,7 +72,7 @@ pub enum ComponentValue { #[deriving(Eq)] pub struct Declaration { pub location: SourceLocation, - pub name: StrBuf, + pub name: String, pub value: Vec, pub important: bool, } @@ -87,7 +87,7 @@ pub struct QualifiedRule { #[deriving(Eq)] pub struct AtRule { pub location: SourceLocation, - pub name: StrBuf, + pub name: String, pub prelude: Vec, pub block: Option>, } @@ -123,7 +123,7 @@ pub enum ErrorReason { impl fmt::Show for SyntaxError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f.buf, "{:u}:{:u} {:?}", self.location.line, self.location.column, self.reason) + write!(f, "{:u}:{:u} {:?}", self.location.line, self.location.column, self.reason) } } diff --git a/color.rs b/color.rs index 0cd3debd..e3735af8 100644 --- a/color.rs +++ b/color.rs @@ -241,6 +241,7 @@ fn parse_color_hash(value: &str) -> Option { fn parse_color_function(name: &str, arguments: &[ComponentValue]) -> Option { let lower_name = name.to_ascii_lower(); + let lower_name = lower_name.as_slice(); let (is_rgb, has_alpha) = if "rgba" == lower_name { (true, true) } diff --git a/from_bytes.rs b/from_bytes.rs index 1400df44..d02eed80 100644 --- a/from_bytes.rs +++ b/from_bytes.rs @@ -33,7 +33,7 @@ use parser::{parse_stylesheet_rules, StylesheetParser}; /// and the `Encoding` object that was used. pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>, environment_encoding: Option) - -> (StrBuf, EncodingRef) { + -> (String, EncodingRef) { // http://dev.w3.org/csswg/css-syntax/#the-input-byte-stream match protocol_encoding_label { None => (), @@ -50,8 +50,8 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str> Some(label_length) => if css.slice_from(10 + label_length).starts_with("\";".as_bytes()) { let label = css.slice(10, 10 + label_length); - let label = str::from_chars(label.iter().map(|&b| b as char).collect::<~[char]>()); - match encoding_from_whatwg_label(label) { + let label = str::from_chars(label.iter().map(|&b| b as char).collect::>().as_slice()); + match encoding_from_whatwg_label(label.as_slice()) { None => (), Some(fallback) => match fallback.name() { "utf-16be" | "utf-16le" @@ -71,7 +71,7 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str> #[inline] -fn decode_replace(input: &[u8], fallback_encoding: EncodingRef)-> (StrBuf, EncodingRef) { +fn decode_replace(input: &[u8], fallback_encoding: EncodingRef)-> (String, EncodingRef) { let (result, used_encoding) = decode(input, DecodeReplace, fallback_encoding); (result.unwrap(), used_encoding) } diff --git a/lib.rs b/lib.rs index 896824ba..7285e881 100644 --- a/lib.rs +++ b/lib.rs @@ -11,6 +11,8 @@ extern crate encoding; // https://github.com/lifthrasiir/rust-encoding +extern crate debug; + #[cfg(test)] extern crate test; diff --git a/nth.rs b/nth.rs index fddb13b5..aeb63aed 100644 --- a/nth.rs +++ b/nth.rs @@ -19,7 +19,8 @@ pub fn parse_nth(input: &[ComponentValue]) -> Option<(i32, i32)> { }, Some(&Dimension(ref value, ref unit)) => match value.int_value { Some(a) => { - let unit: &str = unit.as_slice().to_ascii_lower(); + let unit = unit.as_slice().to_ascii_lower(); + let unit = unit.as_slice(); match unit { "n" => parse_b(iter, a as i32), "n-" => parse_signless_b(iter, a as i32, -1), @@ -32,7 +33,8 @@ pub fn parse_nth(input: &[ComponentValue]) -> Option<(i32, i32)> { _ => None, }, Some(&Ident(ref value)) => { - let ident: &str = value.as_slice().to_ascii_lower(); + let ident = value.as_slice().to_ascii_lower(); + let ident = ident.as_slice(); match ident { "even" => parse_end(iter, 2, 0), "odd" => parse_end(iter, 2, 1), @@ -52,7 +54,8 @@ pub fn parse_nth(input: &[ComponentValue]) -> Option<(i32, i32)> { }, Some(&Delim('+')) => match iter.iter_with_whitespace.next() { Some(&Ident(ref value)) => { - let ident: &str = value.as_slice().to_ascii_lower(); + let ident = value.as_slice().to_ascii_lower(); + let ident = ident.as_slice(); match ident { "n" => parse_b(iter, 1), "n-" => parse_signless_b(iter, 1, -1), diff --git a/parser.rs b/parser.rs index 4cd2a81f..fa490c8a 100644 --- a/parser.rs +++ b/parser.rs @@ -173,7 +173,7 @@ for DeclarationListParser { } -fn parse_at_rule>(iter: &mut T, name: StrBuf, location: SourceLocation) +fn parse_at_rule>(iter: &mut T, name: String, location: SourceLocation) -> AtRule { let mut prelude = Vec::new(); let mut block = None; diff --git a/serializer.rs b/serializer.rs index 561462a4..2fcb0c70 100644 --- a/serializer.rs +++ b/serializer.rs @@ -7,13 +7,13 @@ use ast::*; impl ast::ComponentValue { - pub fn to_css(&mut self) -> StrBuf { - let mut css = StrBuf::new(); + pub fn to_css(&mut self) -> String { + let mut css = String::new(); self.to_css_push(&mut css); css } - pub fn to_css_push(&self, css: &mut StrBuf) { + pub fn to_css_push(&self, css: &mut String) { match *self { Ident(ref value) => serialize_identifier(value.as_slice(), css), AtKeyword(ref value) => { @@ -58,9 +58,9 @@ impl ast::ComponentValue { }, UnicodeRange(start, end) => { - css.push_str(format!("U+{:X}", start)); + css.push_str(format!("U+{:X}", start).as_slice()); if end != start { - css.push_str(format!("-{:X}", end)); + css.push_str(format!("-{:X}", end).as_slice()); } } @@ -109,7 +109,7 @@ impl ast::ComponentValue { } -pub fn serialize_identifier(value: &str, css: &mut StrBuf) { +pub fn serialize_identifier(value: &str, css: &mut String) { // TODO: avoid decoding/re-encoding UTF-8? let mut iter = value.chars(); let mut c = iter.next().unwrap(); @@ -127,9 +127,9 @@ pub fn serialize_identifier(value: &str, css: &mut StrBuf) { #[inline] -fn serialize_char(c: char, css: &mut StrBuf, is_identifier_start: bool) { +fn serialize_char(c: char, css: &mut String, is_identifier_start: bool) { match c { - '0'..'9' if is_identifier_start => css.push_str(format!("\\\\3{} ", c)), + '0'..'9' if is_identifier_start => css.push_str(format!("\\\\3{} ", c).as_slice()), '-' if is_identifier_start => css.push_str("\\-"), '0'..'9' | 'A'..'Z' | 'a'..'z' | '_' | '-' => css.push_char(c), _ if c > '\x7F' => css.push_char(c), @@ -141,7 +141,7 @@ fn serialize_char(c: char, css: &mut StrBuf, is_identifier_start: bool) { } -pub fn serialize_string(value: &str, css: &mut StrBuf) { +pub fn serialize_string(value: &str, css: &mut String) { css.push_char('"'); // TODO: avoid decoding/re-encoding UTF-8? for c in value.chars() { @@ -159,18 +159,18 @@ pub fn serialize_string(value: &str, css: &mut StrBuf) { pub trait ToCss { - fn to_css(&mut self) -> StrBuf { - let mut css = StrBuf::new(); + fn to_css(&mut self) -> String { + let mut css = String::new(); self.to_css_push(&mut css); css } - fn to_css_push(&mut self, css: &mut StrBuf); + fn to_css_push(&mut self, css: &mut String); } impl<'a, I: Iterator<&'a ComponentValue>> ToCss for I { - fn to_css_push(&mut self, css: &mut StrBuf) { + fn to_css_push(&mut self, css: &mut String) { let mut previous = match self.next() { None => return, Some(first) => { first.to_css_push(css); first } diff --git a/tests.rs b/tests.rs index 6ce1cca4..4443fda4 100644 --- a/tests.rs +++ b/tests.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::{io, str, task}; -use std::io::{File, Process, Writer, TempDir}; +use std::io::{File, Command, Writer, TempDir}; use serialize::{json}; use serialize::json::ToJson; use test; @@ -14,7 +14,11 @@ use super::*; use ast::*; macro_rules! JString { - ($e: expr) => { json::String($e.to_owned()) } + ($e: expr) => { json::String($e.to_string()) } +} + +macro_rules! JList { + ($($e: expr),*) => { json::List(vec!( $($e),* )) } } @@ -40,23 +44,23 @@ fn almost_equals(a: &json::Json, b: &json::Json) -> bool { } -fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) { +fn assert_json_eq(results: json::Json, expected: json::Json, message: String) { if !almost_equals(&results, &expected) { let temp = TempDir::new("rust-cssparser-tests").unwrap(); - let results = results.to_pretty_str() + "\n"; - let expected = expected.to_pretty_str() + "\n"; + let results = results.to_pretty_str().append("\n"); + let expected = expected.to_pretty_str().append("\n"); task::try(proc() { let mut result_path = temp.path().clone(); result_path.push("results.json"); let mut expected_path = temp.path().clone(); expected_path.push("expected.json"); - write_whole_file(&result_path, results); - write_whole_file(&expected_path, expected); - Process::status( - "colordiff", - ["-u1000".to_owned(), result_path.display().to_str(), - expected_path.display().to_str()] - ).unwrap(); + write_whole_file(&result_path, results.as_slice()); + write_whole_file(&expected_path, expected.as_slice()); + Command::new("colordiff") + .arg("-u1000") + .arg(result_path.display().to_str()) + .arg(expected_path.display().to_str()) + .status().unwrap(); }).unwrap(); fail!(message) @@ -83,11 +87,11 @@ fn run_raw_json_tests(json_data: &str, run: |json::Json, json::Json|) { } -fn run_json_tests(json_data: &str, parse: |input: ~str| -> T) { +fn run_json_tests(json_data: &str, parse: |input: &str| -> T) { run_raw_json_tests(json_data, |input, expected| { match input { json::String(input) => { - let result = parse(input.to_owned()).to_json(); + let result = parse(input.as_slice()).to_json(); assert_json_eq(result, expected, input); }, _ => fail!("Unexpected JSON") @@ -99,7 +103,7 @@ fn run_json_tests(json_data: &str, parse: |input: ~str| -> T) { #[test] fn component_value_list() { run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| { - tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>() + tokenize(input).map(|(c, _)| c).collect::>() }); } @@ -115,7 +119,7 @@ fn one_component_value() { #[test] fn declaration_list() { run_json_tests(include_str!("css-parsing-tests/declaration_list.json"), |input| { - parse_declaration_list(tokenize(input)).collect::<~[Result]>() + parse_declaration_list(tokenize(input)).collect::>>() }); } @@ -131,7 +135,7 @@ fn one_declaration() { #[test] fn rule_list() { run_json_tests(include_str!("css-parsing-tests/rule_list.json"), |input| { - parse_rule_list(tokenize(input)).collect::<~[Result]>() + parse_rule_list(tokenize(input)).collect::>>() }); } @@ -139,7 +143,7 @@ fn rule_list() { #[test] fn stylesheet() { run_json_tests(include_str!("css-parsing-tests/stylesheet.json"), |input| { - parse_stylesheet_rules(tokenize(input)).collect::<~[Result]>() + parse_stylesheet_rules(tokenize(input)).collect::>>() }); } @@ -162,23 +166,23 @@ fn stylesheet_from_bytes() { }; let result = { - let css = get_string(map, &"css_bytes".to_owned()).unwrap().chars().map(|c| { + let css = get_string(map, &"css_bytes".to_string()).unwrap().chars().map(|c| { assert!(c as u32 <= 0xFF); c as u8 - }).collect::<~[u8]>(); - let protocol_encoding_label = get_string(map, &"protocol_encoding".to_owned()); - let environment_encoding = get_string(map, &"environment_encoding".to_owned()) + }).collect::>(); + let protocol_encoding_label = get_string(map, &"protocol_encoding".to_string()); + let environment_encoding = get_string(map, &"environment_encoding".to_string()) .and_then(encoding_from_whatwg_label); let (mut rules, used_encoding) = parse_stylesheet_rules_from_bytes( - css, protocol_encoding_label, environment_encoding); + css.as_slice(), protocol_encoding_label, environment_encoding); - (rules.collect::<~[Result]>(), used_encoding.name().to_owned()).to_json() + (rules.collect::>>(), used_encoding.name().to_string()).to_json() }; assert_json_eq(result, expected, json::Object(map).to_str()); }); - fn get_string<'a>(map: &'a json::Object, key: &~str) -> Option<&'a str> { + fn get_string<'a>(map: &'a json::Object, key: &String) -> Option<&'a str> { match map.find(key) { Some(&json::String(ref s)) => Some(s.as_slice()), Some(&json::Null) => None, @@ -217,7 +221,7 @@ fn color3_keywords() { run_color_tests(include_str!("css-parsing-tests/color3_keywords.json"), |c| { match c { Some(RGBA(RGBA { red: r, green: g, blue: b, alpha: a })) - => (~[r * 255., g * 255., b * 255., a]).to_json(), + => vec!(r * 255., g * 255., b * 255., a).to_json(), Some(CurrentColor) => JString!("currentColor"), None => json::Null, } @@ -249,7 +253,7 @@ fn bench_color_lookup_fail(b: &mut test::Bencher) { #[test] fn nth() { run_json_tests(include_str!("css-parsing-tests/An+B.json"), |input| { - parse_nth(tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>()) + parse_nth(tokenize(input).map(|(c, _)| c).collect::>().as_slice()) }); } @@ -257,9 +261,9 @@ fn nth() { #[test] fn serializer() { run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| { - let component_values = tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>(); + let component_values = tokenize(input).map(|(c, _)| c).collect::>(); let serialized = component_values.iter().to_css(); - tokenize(serialized.as_slice()).map(|(c, _)| c).collect::<~[ComponentValue]>() + tokenize(serialized.as_slice()).map(|(c, _)| c).collect::>() }); } @@ -306,11 +310,11 @@ impl ToJson for Result { impl ToJson for SyntaxError { fn to_json(&self) -> json::Json { - json::List(~[JString!("error"), JString!(match self.reason { + json::List(vec!(JString!("error"), JString!(match self.reason { ErrEmptyInput => "empty", ErrExtraInput => "extra-input", _ => "invalid", - })]) + }))) } } @@ -318,7 +322,7 @@ impl ToJson for SyntaxError { impl ToJson for Color { fn to_json(&self) -> json::Json { match *self { - RGBA(RGBA { red: r, green: g, blue: b, alpha: a }) => (~[r, g, b, a]).to_json(), + RGBA(RGBA { red: r, green: g, blue: b, alpha: a }) => vec!(r, g, b, a).to_json(), CurrentColor => JString!("currentColor"), } } @@ -345,7 +349,7 @@ impl ToJson for DeclarationListItem { } -fn list_to_json(list: &Vec<(ComponentValue, SourceLocation)>) -> ~[json::Json] { +fn list_to_json(list: &Vec<(ComponentValue, SourceLocation)>) -> Vec { list.iter().map(|tuple| { match *tuple { (ref c, _) => c.to_json() @@ -358,8 +362,8 @@ impl ToJson for AtRule { fn to_json(&self) -> json::Json { match *self { AtRule{name: ref name, prelude: ref prelude, block: ref block, ..} - => json::List(~[JString!("at-rule"), name.to_json(), - prelude.to_json(), block.as_ref().map(list_to_json).to_json()]) + => json::List(vec!(JString!("at-rule"), name.to_json(), + prelude.to_json(), block.as_ref().map(list_to_json).to_json())) } } } @@ -369,8 +373,8 @@ impl ToJson for QualifiedRule { fn to_json(&self) -> json::Json { match *self { QualifiedRule{prelude: ref prelude, block: ref block, ..} - => json::List(~[JString!("qualified rule"), - prelude.to_json(), json::List(list_to_json(block))]) + => json::List(vec!(JString!("qualified rule"), + prelude.to_json(), json::List(list_to_json(block)))) } } } @@ -380,8 +384,8 @@ impl ToJson for Declaration { fn to_json(&self) -> json::Json { match *self { Declaration{name: ref name, value: ref value, important: ref important, ..} - => json::List(~[JString!("declaration"), name.to_json(), - value.to_json(), important.to_json()]) + => json::List(vec!(JString!("declaration"), name.to_json(), + value.to_json(), important.to_json())) } } } @@ -389,34 +393,32 @@ impl ToJson for Declaration { impl ToJson for ComponentValue { fn to_json(&self) -> json::Json { - use JList = serialize::json::List; - - fn numeric(value: &NumericValue) -> ~[json::Json] { + fn numeric(value: &NumericValue) -> Vec { match *value { NumericValue{representation: ref r, value: ref v, int_value: ref i} - => ~[r.to_json(), v.to_json(), - JString!(match *i { Some(_) => "integer", _ => "number" })] + => vec!(r.to_json(), v.to_json(), + JString!(match *i { Some(_) => "integer", _ => "number" })) } } match *self { - Ident(ref value) => JList(~[JString!("ident"), value.to_json()]), - AtKeyword(ref value) => JList(~[JString!("at-keyword"), value.to_json()]), - Hash(ref value) => JList(~[JString!("hash"), value.to_json(), - JString!("unrestricted")]), - IDHash(ref value) => JList(~[JString!("hash"), value.to_json(), JString!("id")]), - String(ref value) => JList(~[JString!("string"), value.to_json()]), - URL(ref value) => JList(~[JString!("url"), value.to_json()]), + Ident(ref value) => JList!(JString!("ident"), value.to_json()), + AtKeyword(ref value) => JList!(JString!("at-keyword"), value.to_json()), + Hash(ref value) => JList!(JString!("hash"), value.to_json(), + JString!("unrestricted")), + IDHash(ref value) => JList!(JString!("hash"), value.to_json(), JString!("id")), + String(ref value) => JList!(JString!("string"), value.to_json()), + URL(ref value) => JList!(JString!("url"), value.to_json()), Delim('\\') => JString!("\\"), Delim(value) => json::String(str::from_char(value)), - Number(ref value) => JList(~[JString!("number")] + numeric(value)), - Percentage(ref value) => JList(~[JString!("percentage")] + numeric(value)), + Number(ref value) => json::List(vec!(JString!("number")) + numeric(value)), + Percentage(ref value) => json::List(vec!(JString!("percentage")) + numeric(value)), Dimension(ref value, ref unit) - => JList(~[JString!("dimension")] + numeric(value) + ~[unit.to_json()]), + => json::List(vec!(JString!("dimension")) + numeric(value) + &[unit.to_json()]), UnicodeRange(start, end) - => JList(~[JString!("unicode-range"), start.to_json(), end.to_json()]), + => JList!(JString!("unicode-range"), start.to_json(), end.to_json()), WhiteSpace => JString!(" "), Colon => JString!(":"), @@ -432,20 +434,20 @@ impl ToJson for ComponentValue { CDC => JString!("-->"), Function(ref name, ref arguments) - => JList(~[JString!("function"), name.to_json()] + - arguments.iter().map(|a| a.to_json()).collect::<~[json::Json]>()), + => json::List(vec!(JString!("function"), name.to_json()) + + arguments.iter().map(|a| a.to_json()).collect::>()), ParenthesisBlock(ref content) - => JList(~[JString!("()")] + content.iter().map(|c| c.to_json()).collect::<~[json::Json]>()), + => json::List(vec!(JString!("()")) + content.iter().map(|c| c.to_json()).collect::>()), SquareBracketBlock(ref content) - => JList(~[JString!("[]")] + content.iter().map(|c| c.to_json()).collect::<~[json::Json]>()), + => json::List(vec!(JString!("[]")) + content.iter().map(|c| c.to_json()).collect::>()), CurlyBracketBlock(ref content) - => JList(~[JString!("{}")] + list_to_json(content)), + => json::List(vec!(JString!("{}")) + list_to_json(content)), - BadURL => JList(~[JString!("error"), JString!("bad-url")]), - BadString => JList(~[JString!("error"), JString!("bad-string")]), - CloseParenthesis => JList(~[JString!("error"), JString!(")")]), - CloseSquareBracket => JList(~[JString!("error"), JString!("]")]), - CloseCurlyBracket => JList(~[JString!("error"), JString!("}")]), + BadURL => JList!(JString!("error"), JString!("bad-url")), + BadString => JList!(JString!("error"), JString!("bad-string")), + CloseParenthesis => JList!(JString!("error"), JString!(")")), + CloseSquareBracket => JList!(JString!("error"), JString!("]")), + CloseCurlyBracket => JList!(JString!("error"), JString!("}")), } } } diff --git a/tokenizer.rs b/tokenizer.rs index 29726282..c70c8b06 100644 --- a/tokenizer.rs +++ b/tokenizer.rs @@ -32,7 +32,7 @@ impl Iterator for Tokenizer { #[inline] -fn preprocess(input: &str) -> ~str { +fn preprocess(input: &str) -> String { // TODO: Is this faster if done in one pass? input.replace("\r\n", "\n").replace("\r", "\n").replace("\x0C", "\n").replace("\x00", "\uFFFD") } @@ -40,14 +40,14 @@ fn preprocess(input: &str) -> ~str { #[test] fn test_preprocess() { - assert!("" == preprocess("")); + assert!("" == preprocess("").as_slice()); assert!("Lorem\n\t\uFFFDipusm\ndoror\uFFFD\n" == - preprocess("Lorem\r\n\t\x00ipusm\ndoror\uFFFD\r")); + preprocess("Lorem\r\n\t\x00ipusm\ndoror\uFFFD\r").as_slice()); } pub struct Tokenizer { - input: ~str, + input: String, length: uint, // All counted in bytes, not characters position: uint, // All counted in bytes, not characters line: uint, @@ -65,25 +65,25 @@ impl Tokenizer { #[inline] fn char_at(&self, offset: uint) -> char { - self.input.char_at(self.position + offset) + self.input.as_slice().char_at(self.position + offset) } #[inline] fn consume_char(&mut self) -> char { - let range = self.input.char_range_at(self.position); + let range = self.input.as_slice().char_range_at(self.position); self.position = range.next; range.ch } #[inline] fn starts_with(&self, needle: &str) -> bool { - self.input.slice_from(self.position).starts_with(needle) + self.input.as_slice().slice_from(self.position).starts_with(needle) } #[inline] fn new_line(&mut self) { if cfg!(test) { - assert!(self.input.char_at(self.position - 1) == '\n') + assert!(self.input.as_slice().char_at(self.position - 1) == '\n') } self.line += 1; self.last_line_start = self.position; @@ -101,7 +101,7 @@ fn next_component_value(tokenizer: &mut Tokenizer) -> Option { consume_comments(tokenizer); if tokenizer.is_eof() { if cfg!(test) { - assert!(tokenizer.line == tokenizer.input.split('\n').len(), + assert!(tokenizer.line == tokenizer.input.as_slice().split('\n').len(), "The tokenizer is missing a tokenizer.new_line() call somewhere.") } return None @@ -314,9 +314,9 @@ fn consume_string(tokenizer: &mut Tokenizer, single_quote: bool) -> ComponentVal // Return None on syntax error (ie. unescaped newline) -fn consume_quoted_string(tokenizer: &mut Tokenizer, single_quote: bool) -> Option { +fn consume_quoted_string(tokenizer: &mut Tokenizer, single_quote: bool) -> Option { tokenizer.position += 1; // Skip the initial quote - let mut string = StrBuf::new(); + let mut string = String::new(); while !tokenizer.is_eof() { match tokenizer.consume_char() { '"' if !single_quote => break, @@ -348,7 +348,7 @@ fn is_ident_start(tokenizer: &mut Tokenizer) -> bool { 'a'..'z' | 'A'..'Z' | '_' => true, '-' => tokenizer.position + 1 < tokenizer.length && match tokenizer.char_at(1) { 'a'..'z' | 'A'..'Z' | '_' => true, - '\\' => !tokenizer.input.slice_from(tokenizer.position + 1).starts_with("\\\n"), + '\\' => !tokenizer.input.as_slice().slice_from(tokenizer.position + 1).starts_with("\\\n"), c => c > '\x7F', // Non-ASCII }, '\\' => !tokenizer.starts_with("\\\n"), @@ -367,8 +367,8 @@ fn consume_ident_like(tokenizer: &mut Tokenizer) -> ComponentValue { } } -fn consume_name(tokenizer: &mut Tokenizer) -> StrBuf { - let mut value = StrBuf::new(); +fn consume_name(tokenizer: &mut Tokenizer) -> String { + let mut value = String::new(); while !tokenizer.is_eof() { let c = tokenizer.current_char(); value.push_char(match c { @@ -389,7 +389,7 @@ fn consume_name(tokenizer: &mut Tokenizer) -> StrBuf { fn consume_numeric(tokenizer: &mut Tokenizer) -> ComponentValue { // Parse [+-]?\d*(\.\d+)?([eE][+-]?\d+)? // But this is always called so that there is at least one digit in \d*(\.\d+)? - let mut representation = StrBuf::new(); + let mut representation = String::new(); let mut is_integer = true; if is_match!(tokenizer.current_char(), '-' | '+') { representation.push_char(tokenizer.consume_char()) @@ -471,7 +471,7 @@ fn consume_url(tokenizer: &mut Tokenizer) -> ComponentValue { _ => return consume_unquoted_url(tokenizer), } } - return URL(StrBuf::new()); + return URL(String::new()); fn consume_quoted_url(tokenizer: &mut Tokenizer, single_quote: bool) -> ComponentValue { match consume_quoted_string(tokenizer, single_quote) { @@ -481,7 +481,7 @@ fn consume_url(tokenizer: &mut Tokenizer) -> ComponentValue { } fn consume_unquoted_url(tokenizer: &mut Tokenizer) -> ComponentValue { - let mut string = StrBuf::new(); + let mut string = String::new(); while !tokenizer.is_eof() { let next_char = match tokenizer.consume_char() { ' ' | '\t' => return consume_url_end(tokenizer, string), @@ -505,7 +505,7 @@ fn consume_url(tokenizer: &mut Tokenizer) -> ComponentValue { URL(string) } - fn consume_url_end(tokenizer: &mut Tokenizer, string: StrBuf) -> ComponentValue { + fn consume_url_end(tokenizer: &mut Tokenizer, string: String) -> ComponentValue { while !tokenizer.is_eof() { match tokenizer.consume_char() { ' ' | '\t' => (), @@ -535,7 +535,7 @@ fn consume_url(tokenizer: &mut Tokenizer) -> ComponentValue { fn consume_unicode_range(tokenizer: &mut Tokenizer) -> ComponentValue { tokenizer.position += 2; // Skip U+ - let mut hex = StrBuf::new(); + let mut hex = String::new(); while hex.len() < 6 && !tokenizer.is_eof() && is_match!(tokenizer.current_char(), '0'..'9' | 'A'..'F' | 'a'..'f') { hex.push_char(tokenizer.consume_char()); @@ -550,8 +550,8 @@ fn consume_unicode_range(tokenizer: &mut Tokenizer) -> ComponentValue { let start; let end; if question_marks > 0 { - start = num::from_str_radix(hex.clone().append("0".repeat(question_marks)).as_slice(), 16).unwrap(); - end = num::from_str_radix(hex.append("F".repeat(question_marks)).as_slice(), 16).unwrap(); + start = num::from_str_radix(hex.clone().append("0".repeat(question_marks).as_slice()).as_slice(), 16).unwrap(); + end = num::from_str_radix(hex.append("F".repeat(question_marks).as_slice()).as_slice(), 16).unwrap(); } else { start = num::from_str_radix(hex.as_slice(), 16).unwrap(); hex.truncate(0); @@ -580,7 +580,7 @@ fn consume_escape(tokenizer: &mut Tokenizer) -> char { let c = tokenizer.consume_char(); match c { '0'..'9' | 'A'..'F' | 'a'..'f' => { - let mut hex = StrBuf::from_char(1, c); + let mut hex = String::from_char(1, c); while hex.len() < 6 && !tokenizer.is_eof() { let c = tokenizer.current_char(); match c {