Skip to content

Upgrade Rust. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,
}
Expand All @@ -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, // :
Expand All @@ -53,7 +53,7 @@ pub enum ComponentValue {
CDC, // -->

// Function
Function(StrBuf, Vec<ComponentValue>), // name, arguments
Function(String, Vec<ComponentValue>), // name, arguments

// Simple block
ParenthesisBlock(Vec<ComponentValue>), // (…)
Expand All @@ -72,7 +72,7 @@ pub enum ComponentValue {
#[deriving(Eq)]
pub struct Declaration {
pub location: SourceLocation,
pub name: StrBuf,
pub name: String,
pub value: Vec<ComponentValue>,
pub important: bool,
}
Expand All @@ -87,7 +87,7 @@ pub struct QualifiedRule {
#[deriving(Eq)]
pub struct AtRule {
pub location: SourceLocation,
pub name: StrBuf,
pub name: String,
pub prelude: Vec<ComponentValue>,
pub block: Option<Vec<Node>>,
}
Expand Down Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ fn parse_color_hash(value: &str) -> Option<Color> {
fn parse_color_function(name: &str, arguments: &[ComponentValue])
-> Option<Color> {
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) }
Expand Down
8 changes: 4 additions & 4 deletions from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EncodingRef>)
-> (StrBuf, EncodingRef) {
-> (String, EncodingRef) {
// http://dev.w3.org/csswg/css-syntax/#the-input-byte-stream
match protocol_encoding_label {
None => (),
Expand All @@ -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::<Vec<char>>().as_slice());
match encoding_from_whatwg_label(label.as_slice()) {
None => (),
Some(fallback) => match fallback.name() {
"utf-16be" | "utf-16le"
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

extern crate encoding; // https://github.com/lifthrasiir/rust-encoding

extern crate debug;

#[cfg(test)]
extern crate test;

Expand Down
9 changes: 6 additions & 3 deletions nth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ for DeclarationListParser<T> {
}


fn parse_at_rule<T: Iterator<Node>>(iter: &mut T, name: StrBuf, location: SourceLocation)
fn parse_at_rule<T: Iterator<Node>>(iter: &mut T, name: String, location: SourceLocation)
-> AtRule {
let mut prelude = Vec::new();
let mut block = None;
Expand Down
26 changes: 13 additions & 13 deletions serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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),
Expand All @@ -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() {
Expand All @@ -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 }
Expand Down
Loading