Fixed all strings in the old format

This commit is contained in:
Margaret Meyerhofer 2012-07-17 17:00:48 -07:00
parent c25cb50d9d
commit 6148309ce1
36 changed files with 238 additions and 238 deletions

@ -1 +1 @@
Subproject commit 29aafdbc3c5aa7567ee457276f65cb72638ad5c5 Subproject commit 065a91cf8855489a71b06157d19c1e61888af5b7

@ -1 +1 @@
Subproject commit 3adac7fed761eb238df17300b6bba96e06aa3fe9 Subproject commit a090f22aed9143abba074f65b9518a83f4c8d830

@ -1 +1 @@
Subproject commit 37e72fca69a5b9051f81b3d2be6d30efc4939c7e Subproject commit 899def413d8aab57af49f1ae4204531fb69bfb62

@ -1 +1 @@
Subproject commit f31dd12655523ee96b72da24c8195a76d988b50f Subproject commit ad076e2738332ac8464856f6a470eaf1e25f03ca

@ -1 +1 @@
Subproject commit fc51299da10833faa6fe322ced5e998139015c76 Subproject commit 678688c3b624761ece89afe45e650158f7ecbc8d

@ -1 +1 @@
Subproject commit 2339847a9b992af83412d31c0b24111a115e26da Subproject commit 598bd4d5826792ea5420e5ca7267678c17338b71

@ -1 +1 @@
Subproject commit ce58ddadbc61b3c79033db13b3e63ac2946c7588 Subproject commit 0f3d130e46b1314f1c98b99ce91f443805a9efa6

@ -1 +1 @@
Subproject commit 30f1c06c32979da20f6dc82119b4037deba08229 Subproject commit 795ac08b121f343d8dac06a2add917aad0972ac0

View file

@ -15,21 +15,21 @@ enum NodeData = {
enum NodeKind { enum NodeKind {
Element(ElementData), Element(ElementData),
Text(str) Text(~str)
} }
class ElementData { class ElementData {
let tag_name: str; let tag_name: ~str;
let kind: ~ElementKind; let kind: ~ElementKind;
let attrs: dvec<~Attr>; let attrs: dvec<~Attr>;
new(-tag_name: str, -kind: ~ElementKind) { new(-tag_name: ~str, -kind: ~ElementKind) {
self.tag_name = tag_name; self.tag_name = tag_name;
self.kind = kind; self.kind = kind;
self.attrs = dvec(); self.attrs = dvec();
} }
fn get_attr(attr_name: str) -> option<str> { fn get_attr(attr_name: ~str) -> option<~str> {
let mut i = 0u; let mut i = 0u;
while i < self.attrs.len() { while i < self.attrs.len() {
if attr_name == self.attrs[i].name { if attr_name == self.attrs[i].name {
@ -43,10 +43,10 @@ class ElementData {
} }
class Attr { class Attr {
let name: str; let name: ~str;
let value: str; let value: ~str;
new(-name: str, -value: str) { new(-name: ~str, -value: ~str) {
self.name = name; self.name = name;
self.value = value; self.value = value;
} }

View file

@ -229,7 +229,7 @@ impl WriterMethods<T:copy send,A> for Scope<T,A> {
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
mod test { mod test {
type animal = {name: str, species: species}; type animal = {name: ~str, species: species};
enum species { enum species {
chicken(~chicken), chicken(~chicken),
bull(~bull) bull(~bull)
@ -244,8 +244,8 @@ mod test {
#[test] #[test]
fn handles_get_freed() { fn handles_get_freed() {
let s: animal_scope = Scope(); let s: animal_scope = Scope();
s.handle({name:"henrietta", species:chicken(~{mut eggs_per_day:22u})}); s.handle({name:~"henrietta", species:chicken(~{mut eggs_per_day:22u})});
s.handle({name:"ferdinand", species:bull(~{mut horns:3u})}); s.handle({name:~"ferdinand", species:bull(~{mut horns:3u})});
} }
fn mutate(a: animal) { fn mutate(a: animal) {
@ -266,10 +266,10 @@ mod test {
fn interspersed_execution() { fn interspersed_execution() {
let s: animal_scope = Scope(); let s: animal_scope = Scope();
let henrietta = let henrietta =
s.handle({name:"henrietta", s.handle({name:~"henrietta",
species:chicken(~{mut eggs_per_day:0u})}); species:chicken(~{mut eggs_per_day:0u})});
let ferdinand = let ferdinand =
s.handle({name:"ferdinand", s.handle({name:~"ferdinand",
species:bull(~{mut horns:0u})}); species:bull(~{mut horns:0u})});
let iter1 = 3u; let iter1 = 3u;

View file

@ -14,14 +14,14 @@ enum StyleDeclaration{
} }
enum Attr{ enum Attr{
Exists(str), Exists(~str),
Exact(str, str), Exact(~str, ~str),
Includes(str, str), Includes(~str, ~str),
StartsWith(str, str) StartsWith(~str, ~str)
} }
enum Selector{ enum Selector{
Element(str, ~[Attr]), Element(~str, ~[Attr]),
Child(~Selector, ~Selector), Child(~Selector, ~Selector),
Descendant(~Selector, ~Selector), Descendant(~Selector, ~Selector),
Sibling(~Selector, ~Selector) Sibling(~Selector, ~Selector)

View file

@ -41,7 +41,7 @@ fn Renderer<S: Sink send copy>(sink: S) -> chan<Msg> {
let draw_target = draw_target_ch.recv(); let draw_target = draw_target_ch.recv();
#debug("renderer: rendering"); #debug("renderer: rendering");
do util::time::time("rendering") { do util::time::time(~"rendering") {
clear(draw_target); clear(draw_target);
draw_display_list(draw_target, display_list); draw_display_list(draw_target, display_list);
#debug("renderer: returning surface"); #debug("renderer: returning surface");
@ -79,7 +79,7 @@ fn draw_display_list(draw_target: AzDrawTargetRef, display_list: dl::display_lis
draw_text(draw_target, item, text_run); draw_text(draw_target, item, text_run);
} }
dl::padding(*) { dl::padding(*) {
fail "should never see padding"; fail ~"should never see padding";
} }
} }
} }

View file

@ -94,9 +94,9 @@ impl BoxTreeWriteMethods of tree::WriteMethods<@Box> for BTree {
impl layout_methods_priv for @Box { impl layout_methods_priv for @Box {
#[doc="Dumps the box tree, for debugging, with indentation."] #[doc="Dumps the box tree, for debugging, with indentation."]
fn dump_indent(indent: uint) { fn dump_indent(indent: uint) {
let mut s = ""; let mut s = ~"";
for uint::range(0u, indent) |_i| { for uint::range(0u, indent) |_i| {
s += " "; s += ~" ";
} }
s += #fmt("%?", self.kind); s += #fmt("%?", self.kind);
@ -137,9 +137,9 @@ impl layout_methods for @Box {
impl PrivateNodeMethods for Node { impl PrivateNodeMethods for Node {
#[doc="Dumps the node tree, for debugging, with indentation."] #[doc="Dumps the node tree, for debugging, with indentation."]
fn dump_indent(indent: uint) { fn dump_indent(indent: uint) {
let mut s = ""; let mut s = ~"";
for uint::range(0u, indent) |_i| { for uint::range(0u, indent) |_i| {
s += " "; s += ~" ";
} }
s += #fmt("%?", self.read(|n| copy n.kind )); s += #fmt("%?", self.read(|n| copy n.kind ));
@ -201,10 +201,10 @@ mod test {
~HTMLImageElement({mut size: size}) ~HTMLImageElement({mut size: size})
} }
let n0 = s.new_node(Element(ElementData("img", mk_img(Size2D(au(10),au(10)))))); let n0 = s.new_node(Element(ElementData(~"img", mk_img(Size2D(au(10),au(10))))));
let n1 = s.new_node(Element(ElementData("img", mk_img(Size2D(au(10),au(10)))))); let n1 = s.new_node(Element(ElementData(~"img", mk_img(Size2D(au(10),au(10))))));
let n2 = s.new_node(Element(ElementData("img", mk_img(Size2D(au(10),au(20)))))); let n2 = s.new_node(Element(ElementData(~"img", mk_img(Size2D(au(10),au(20))))));
let n3 = s.new_node(Element(ElementData("div", ~HTMLDivElement))); let n3 = s.new_node(Element(ElementData(~"div", ~HTMLDivElement)));
tree::add_child(s, n3, n0); tree::add_child(s, n3, n0);
tree::add_child(s, n3, n1); tree::add_child(s, n3, n1);

View file

@ -118,7 +118,7 @@ fn should_convert_text_boxes_to_solid_color_background_items() {
#[ignore(reason = "crashy")]; #[ignore(reason = "crashy")];
let s = Scope(); let s = Scope();
let n = s.new_node(Text("firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
@ -136,7 +136,7 @@ fn should_convert_text_boxes_to_text_items() {
#[ignore(reason = "crashy")]; #[ignore(reason = "crashy")];
let s = Scope(); let s = Scope();
let n = s.new_node(Text("firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
@ -153,7 +153,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
#[ignore]; #[ignore];
let s = Scope(); let s = Scope();
let n = s.new_node(Text("firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
@ -172,7 +172,7 @@ fn should_calculate_the_bounds_of_the_text_items() {
#[ignore]; #[ignore];
let s = Scope(); let s = Scope();
let n = s.new_node(Text("firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);

View file

@ -40,7 +40,7 @@ fn Layout(renderer: Renderer) -> Layout {
#debug("layout: received layout request for:"); #debug("layout: received layout request for:");
node.dump(); node.dump();
do util::time::time("layout") { do util::time::time(~"layout") {
node.initialize_style_for_subtree(); node.initialize_style_for_subtree();
node.recompute_style_for_subtree(arc(copy styles)); node.recompute_style_for_subtree(arc(copy styles));

View file

@ -26,7 +26,7 @@ impl ApplyStyleBoxMethods for @Box {
alt element.kind { alt element.kind {
~HTMLImageElement(*) { ~HTMLImageElement(*) {
alt element.get_attr("src") { alt element.get_attr(~"src") {
some(url) { some(url) {
// FIXME: Some sort of BASE HREF support! // FIXME: Some sort of BASE HREF support!
// FIXME: Parse URLs! // FIXME: Parse URLs!

View file

@ -29,7 +29,7 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
Includes(name, val) { Includes(name, val) {
// Comply with css spec, if the specified attribute is empty // Comply with css spec, if the specified attribute is empty
// it cannot match. // it cannot match.
if val == "" { ret false; } if val == ~"" { ret false; }
alt elmt.get_attr(name) { alt elmt.get_attr(name) {
some(value) { ret value.split_char(' ').contains(val); } some(value) { ret value.split_char(' ').contains(val); }
@ -41,11 +41,11 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
some(value) { some(value) {
//check that there is only one attribute value and it //check that there is only one attribute value and it
//starts with the perscribed value //starts with the perscribed value
if !value.starts_with(val) || value.contains(" ") { ret false; } if !value.starts_with(val) || value.contains(~" ") { ret false; }
// We match on either the exact value or value-foo // We match on either the exact value or value-foo
if value.len() == val.len() { ret true; } if value.len() == val.len() { ret true; }
else { ret value.starts_with(val + "-"); } else { ret value.starts_with(val + ~"-"); }
} }
none { none {
ret false; ret false;
@ -66,7 +66,7 @@ impl priv_matching_methods for Node {
Element(tag, attrs) { Element(tag, attrs) {
alt self.read(|n| copy *n.kind) { alt self.read(|n| copy *n.kind) {
base::Element(elmt) { base::Element(elmt) {
if !(tag == "*" || tag == elmt.tag_name) { if !(tag == ~"*" || tag == elmt.tag_name) {
ret false; ret false;
} }
@ -207,8 +207,8 @@ mod test {
import io::println; import io::println;
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
fn new_node_from_attr(scope: NodeScope, -name: str, -val: str) -> Node { fn new_node_from_attr(scope: NodeScope, -name: ~str, -val: ~str) -> Node {
let elmt = ElementData("div", ~HTMLDivElement); let elmt = ElementData(~"div", ~HTMLDivElement);
let attr = ~Attr(name, val); let attr = ~Attr(name, val);
elmt.attrs.push(attr); elmt.attrs.push(attr);
ret scope.new_node(base::Element(elmt)); ret scope.new_node(base::Element(elmt));
@ -217,9 +217,9 @@ mod test {
#[test] #[test]
fn test_match_pipe1() { fn test_match_pipe1() {
let scope = NodeScope(); let scope = NodeScope();
let node = new_node_from_attr(scope, "lang", "en-us"); let node = new_node_from_attr(scope, ~"lang", ~"en-us");
let sel = Element("*", ~[StartsWith("lang", "en")]); let sel = Element(~"*", ~[StartsWith(~"lang", ~"en")]);
assert node.matches_selector(~sel); assert node.matches_selector(~sel);
} }
@ -227,9 +227,9 @@ mod test {
#[test] #[test]
fn test_match_pipe2() { fn test_match_pipe2() {
let scope = NodeScope(); let scope = NodeScope();
let node = new_node_from_attr(scope, "lang", "en"); let node = new_node_from_attr(scope, ~"lang", ~"en");
let sel = Element("*", ~[StartsWith("lang", "en")]); let sel = Element(~"*", ~[StartsWith(~"lang", ~"en")]);
assert node.matches_selector(~sel); assert node.matches_selector(~sel);
} }
@ -237,9 +237,9 @@ mod test {
#[test] #[test]
fn test_not_match_pipe() { fn test_not_match_pipe() {
let scope = NodeScope(); let scope = NodeScope();
let node = new_node_from_attr(scope, "lang", "english"); let node = new_node_from_attr(scope, ~"lang", ~"english");
let sel = Element("*", ~[StartsWith("lang", "en")]); let sel = Element(~"*", ~[StartsWith(~"lang", ~"en")]);
assert !node.matches_selector(~sel); assert !node.matches_selector(~sel);
} }
@ -247,9 +247,9 @@ mod test {
#[test] #[test]
fn test_match_includes() { fn test_match_includes() {
let scope = NodeScope(); let scope = NodeScope();
let node = new_node_from_attr(scope, "mad", "hatter cobler cooper"); let node = new_node_from_attr(scope, ~"mad", ~"hatter cobler cooper");
let sel = Element("div", ~[Includes("mad", "hatter")]); let sel = Element(~"div", ~[Includes(~"mad", ~"hatter")]);
assert node.matches_selector(~sel); assert node.matches_selector(~sel);
} }
@ -257,10 +257,10 @@ mod test {
#[test] #[test]
fn test_match_exists() { fn test_match_exists() {
let scope = NodeScope(); let scope = NodeScope();
let node = new_node_from_attr(scope, "mad", "hatter cobler cooper"); let node = new_node_from_attr(scope, ~"mad", ~"hatter cobler cooper");
let sel1 = Element("div", ~[Exists("mad")]); let sel1 = Element(~"div", ~[Exists(~"mad")]);
let sel2 = Element("div", ~[Exists("hatter")]); let sel2 = Element(~"div", ~[Exists(~"hatter")]);
assert node.matches_selector(~sel1); assert node.matches_selector(~sel1);
assert !node.matches_selector(~sel2); assert !node.matches_selector(~sel2);
@ -269,10 +269,10 @@ mod test {
#[test] #[test]
fn test_match_exact() { fn test_match_exact() {
let scope = NodeScope(); let scope = NodeScope();
let node1 = new_node_from_attr(scope, "mad", "hatter cobler cooper"); let node1 = new_node_from_attr(scope, ~"mad", ~"hatter cobler cooper");
let node2 = new_node_from_attr(scope, "mad", "hatter"); let node2 = new_node_from_attr(scope, ~"mad", ~"hatter");
let sel = Element("div", ~[Exact("mad", "hatter")]); let sel = Element(~"div", ~[Exact(~"mad", ~"hatter")]);
assert !node1.matches_selector(~copy sel); assert !node1.matches_selector(~copy sel);
assert node2.matches_selector(~sel); assert node2.matches_selector(~sel);
@ -282,12 +282,12 @@ mod test {
fn match_tree() { fn match_tree() {
let scope = NodeScope(); let scope = NodeScope();
let root = new_node_from_attr(scope, "class", "blue"); let root = new_node_from_attr(scope, ~"class", ~"blue");
let child1 = new_node_from_attr(scope, "id", "green"); let child1 = new_node_from_attr(scope, ~"id", ~"green");
let child2 = new_node_from_attr(scope, "flag", "black"); let child2 = new_node_from_attr(scope, ~"flag", ~"black");
let gchild = new_node_from_attr(scope, "flag", "grey"); let gchild = new_node_from_attr(scope, ~"flag", ~"grey");
let ggchild = new_node_from_attr(scope, "flag", "white"); let ggchild = new_node_from_attr(scope, ~"flag", ~"white");
let gggchild = new_node_from_attr(scope, "flag", "purple"); let gggchild = new_node_from_attr(scope, ~"flag", ~"purple");
scope.add_child(root, child1); scope.add_child(root, child1);
scope.add_child(root, child2); scope.add_child(root, child2);
@ -295,8 +295,8 @@ mod test {
scope.add_child(gchild, ggchild); scope.add_child(gchild, ggchild);
scope.add_child(ggchild, gggchild); scope.add_child(ggchild, gggchild);
let sel1 = Descendant(~Element("*", ~[Exact("class", "blue")]), let sel1 = Descendant(~Element(~"*", ~[Exact(~"class", ~"blue")]),
~Element("*", ~[])); ~Element(~"*", ~[]));
assert !root.matches_selector(~copy sel1); assert !root.matches_selector(~copy sel1);
assert child1.matches_selector(~copy sel1); assert child1.matches_selector(~copy sel1);
@ -305,9 +305,9 @@ mod test {
assert ggchild.matches_selector(~copy sel1); assert ggchild.matches_selector(~copy sel1);
assert gggchild.matches_selector(~sel1); assert gggchild.matches_selector(~sel1);
let sel2 = Descendant(~Child(~Element("*", ~[Exact("class", "blue")]), let sel2 = Descendant(~Child(~Element(~"*", ~[Exact(~"class", ~"blue")]),
~Element("*", ~[])), ~Element(~"*", ~[])),
~Element("div", ~[Exists("flag")])); ~Element(~"div", ~[Exists(~"flag")]));
assert !root.matches_selector(~copy sel2); assert !root.matches_selector(~copy sel2);
assert !child1.matches_selector(~copy sel2); assert !child1.matches_selector(~copy sel2);
@ -316,7 +316,7 @@ mod test {
assert ggchild.matches_selector(~copy sel2); assert ggchild.matches_selector(~copy sel2);
assert gggchild.matches_selector(~sel2); assert gggchild.matches_selector(~sel2);
let sel3 = Sibling(~Element("*", ~[]), ~Element("*", ~[])); let sel3 = Sibling(~Element(~"*", ~[]), ~Element(~"*", ~[]));
assert !root.matches_selector(~copy sel3); assert !root.matches_selector(~copy sel3);
assert child1.matches_selector(~copy sel3); assert child1.matches_selector(~copy sel3);
@ -325,9 +325,9 @@ mod test {
assert !ggchild.matches_selector(~copy sel3); assert !ggchild.matches_selector(~copy sel3);
assert !gggchild.matches_selector(~sel3); assert !gggchild.matches_selector(~sel3);
let sel4 = Descendant(~Child(~Element("*", ~[Exists("class")]), let sel4 = Descendant(~Child(~Element(~"*", ~[Exists(~"class")]),
~Element("*", ~[])), ~Element(~"*", ~[])),
~Element("*", ~[])); ~Element(~"*", ~[]));
assert !root.matches_selector(~copy sel4); assert !root.matches_selector(~copy sel4);
assert !child1.matches_selector(~copy sel4); assert !child1.matches_selector(~copy sel4);

View file

@ -68,7 +68,7 @@ impl style_methods for Node {
"] "]
fn get_computed_style() -> computed_style { fn get_computed_style() -> computed_style {
if !self.has_aux() { if !self.has_aux() {
fail "get_computed_style() called on a node without a style!"; fail ~"get_computed_style() called on a node without a style!";
} }
ret copy *self.aux(|x| copy x).computed_style; ret copy *self.aux(|x| copy x).computed_style;
} }

View file

@ -7,10 +7,10 @@ import servo_text::font_library::FontLibrary;
import base::{Box, TextBox}; import base::{Box, TextBox};
class text_box { class text_box {
let text: str; let text: ~str;
let mut run: option<TextRun>; let mut run: option<TextRun>;
new(-text: str) { new(-text: ~str) {
self.text = text; self.text = text;
self.run = none; self.run = none;
} }
@ -21,7 +21,7 @@ impl text_layout_methods for @Box {
fn reflow_text(_available_width: au, subbox: @text_box) { fn reflow_text(_available_width: au, subbox: @text_box) {
alt self.kind { alt self.kind {
TextBox(*) { /* ok */ } TextBox(*) { /* ok */ }
_ { fail "expected text box in reflow_text!" } _ { fail ~"expected text box in reflow_text!" }
}; };
// FIXME: The font library should not be initialized here // FIXME: The font library should not be initialized here
@ -44,7 +44,7 @@ fn should_calculate_the_size_of_the_text_box() {
import gfx::geometry::px_to_au; import gfx::geometry::px_to_au;
let s = Scope(); let s = Scope();
let n = s.new_node(Text("firecracker")); let n = s.new_node(Text(~"firecracker"));
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };

View file

@ -13,7 +13,7 @@ iface channel {
} }
iface io_service { iface io_service {
fn new_uri(spec: str) -> uri; fn new_uri(spec: ~str) -> uri;
fn new_channel(uri: uri) -> channel; fn new_channel(uri: uri) -> channel;
} }

View file

@ -1,13 +1,13 @@
export uri, build_uri; export uri, build_uri;
type uri = { type uri = {
spec: str, spec: ~str,
scheme: str, scheme: ~str,
host: option<str>, host: option<~str>,
port: option<uint>, port: option<uint>,
path: str path: ~str
}; };
fn build_uri(_spec: str) -> uri { fn build_uri(_spec: ~str) -> uri {
fail fail
} }

View file

@ -6,23 +6,23 @@ from command line arguments.
"]; "];
type Opts = { type Opts = {
urls: ~[str], urls: ~[~str],
render_mode: RenderMode render_mode: RenderMode
}; };
enum RenderMode { enum RenderMode {
Screen, Screen,
Png(str) Png(~str)
} }
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
fn from_cmdline_args(args: ~[str]) -> Opts { fn from_cmdline_args(args: ~[~str]) -> Opts {
import std::getopts; import std::getopts;
let args = args.tail(); let args = args.tail();
let opts = ~[ let opts = ~[
getopts::optopt("o") getopts::optopt(~"o")
]; ];
let match = alt getopts::getopts(args, opts) { let match = alt getopts::getopts(args, opts) {
@ -31,12 +31,12 @@ fn from_cmdline_args(args: ~[str]) -> Opts {
}; };
let urls = if match.free.is_empty() { let urls = if match.free.is_empty() {
fail "servo asks that you provide 1 or more URLs" fail ~"servo asks that you provide 1 or more URLs"
} else { } else {
copy match.free copy match.free
}; };
let render_mode = alt getopts::opt_maybe_str(match, "o") { let render_mode = alt getopts::opt_maybe_str(match, ~"o") {
some(output_file) { Png(copy output_file) } some(output_file) { Png(copy output_file) }
none { Screen } none { Screen }
}; };

View file

@ -35,7 +35,7 @@ fn parse_element(reader : TokenReader) -> option<~style::Selector> {
let elmt_name = alt reader.get() { let elmt_name = alt reader.get() {
Element(tag) { copy tag } Element(tag) { copy tag }
Eof { ret none; } Eof { ret none; }
_ { fail "Expected an element" } _ { fail ~"Expected an element" }
}; };
let mut attr_list = ~[]; let mut attr_list = ~[];
@ -50,10 +50,10 @@ fn parse_element(reader : TokenReader) -> option<~style::Selector> {
break; break;
} }
Eof { ret none; } Eof { ret none; }
Element(_) { fail "Unexpected second element without " Element(_) { fail ~"Unexpected second element without "
+ "relation to first element"; } + ~"relation to first element"; }
EndDescription { fail "Unexpected '}'"; } EndDescription { fail ~"Unexpected '}'"; }
Description(_, _) { fail "Unexpected description"; } Description(_, _) { fail ~"Unexpected description"; }
} }
} }
@ -141,28 +141,28 @@ fn parse_rule(reader : TokenReader) -> option<~style::Rule> {
EndDescription { break; } EndDescription { break; }
Description(prop, val) { Description(prop, val) {
alt prop { alt prop {
"font-size" { ~"font-size" {
// TODO, support more ways to declare a font size than # pt // TODO, support more ways to declare a font size than # pt
assert val.ends_with("pt"); assert val.ends_with(~"pt");
let num = val.substr(0u, val.len() - 2u); let num = val.substr(0u, val.len() - 2u);
alt uint::from_str(num) { alt uint::from_str(num) {
some(n) { push(desc_list, FontSize(n)); } some(n) { push(desc_list, FontSize(n)); }
none { fail "Nonnumber provided as font size"; } none { fail ~"Nonnumber provided as font size"; }
} }
} }
"display" { ~"display" {
alt val { alt val {
"inline" { push(desc_list, Display(DisInline)); } ~"inline" { push(desc_list, Display(DisInline)); }
"block" { push(desc_list, Display(DisBlock)); } ~"block" { push(desc_list, Display(DisBlock)); }
"none" { push(desc_list, Display(DisNone)); } ~"none" { push(desc_list, Display(DisNone)); }
_ { #debug["Recieved unknown display value '%s'", val]; } _ { #debug["Recieved unknown display value '%s'", val]; }
} }
} }
"color" { ~"color" {
push(desc_list, TextColor(parse_color(val))); push(desc_list, TextColor(parse_color(val)));
} }
"background-color" { ~"background-color" {
push(desc_list, BackgroundColor(parse_color(val))); push(desc_list, BackgroundColor(parse_color(val)));
} }
_ { #debug["Recieved unknown style property '%s'", val]; } _ { #debug["Recieved unknown style property '%s'", val]; }

View file

@ -25,9 +25,9 @@ enum Token {
Child, Child,
Sibling, Sibling,
Comma, Comma,
Element(str), Element(~str),
Attr(style::Attr), Attr(style::Attr),
Description(str, str), Description(~str, ~str),
Eof Eof
} }
@ -74,10 +74,10 @@ impl css_methods for CssLexer {
if c == '.' as u8 || c == '#' as u8 { if c == '.' as u8 || c == '#' as u8 {
self.parser_state = CssAttribute; self.parser_state = CssAttribute;
self.input_state.unget(c); self.input_state.unget(c);
ret Element("*"); ret Element(~"*");
} else if c == '*' as u8 { } else if c == '*' as u8 {
self.parser_state = CssAttribute; self.parser_state = CssAttribute;
ret Element("*"); ret Element(~"*");
} }
self.input_state.unget(c); self.input_state.unget(c);
@ -99,21 +99,21 @@ impl css_methods for CssLexer {
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c } CoeChar(c) { ch = c }
CoeEof { fail "File ended before description of style" } CoeEof { fail ~"File ended before description of style" }
} }
ret self.parse_css_relation(ch); ret self.parse_css_relation(ch);
} }
alt ch { alt ch {
'.' as u8 { ret Attr(style::Includes("class", self.input_state.parse_ident())); } '.' as u8 { ret Attr(style::Includes(~"class", self.input_state.parse_ident())); }
'#' as u8 { ret Attr(style::Includes("id", self.input_state.parse_ident())); } '#' as u8 { ret Attr(style::Includes(~"id", self.input_state.parse_ident())); }
'[' as u8 { '[' as u8 {
let attr_name = self.input_state.parse_ident(); let attr_name = self.input_state.parse_ident();
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c; } CoeChar(c) { ch = c; }
CoeEof { fail "File ended before description finished"; } CoeEof { fail ~"File ended before description finished"; }
} }
if ch == ']' as u8 { if ch == ']' as u8 {
@ -152,7 +152,7 @@ impl css_methods for CssLexer {
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c } CoeChar(c) { ch = c }
CoeEof { fail "Reached end of file in CSS description" } CoeEof { fail ~"Reached end of file in CSS description" }
} }
} }
@ -164,7 +164,7 @@ impl css_methods for CssLexer {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
} else if ch == ':' as u8 { } else if ch == ':' as u8 {
if desc_name.len() == 0u { if desc_name.len() == 0u {
fail "Expected descriptor name"; fail ~"Expected descriptor name";
} else { } else {
break; break;
} }
@ -174,7 +174,7 @@ impl css_methods for CssLexer {
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c } CoeChar(c) { ch = c }
CoeEof { fail "Reached end of file in CSS description" } CoeEof { fail ~"Reached end of file in CSS description" }
} }
} }
@ -185,21 +185,21 @@ impl css_methods for CssLexer {
loop { loop {
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c } CoeChar(c) { ch = c }
CoeEof { fail "Reached end of file in CSS description" } CoeEof { fail ~"Reached end of file in CSS description" }
} }
if ch.is_whitespace() { if ch.is_whitespace() {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
} else if ch == '}' as u8 { } else if ch == '}' as u8 {
if desc_val.len() == 0u { if desc_val.len() == 0u {
fail "Expected descriptor value"; fail ~"Expected descriptor value";
} else { } else {
self.input_state.unget('}' as u8); self.input_state.unget('}' as u8);
break; break;
} }
} else if ch == ';' as u8 { } else if ch == ';' as u8 {
if desc_val.len() == 0u { if desc_val.len() == 0u {
fail "Expected descriptor value"; fail ~"Expected descriptor value";
} else { } else {
break; break;
} }
@ -223,7 +223,7 @@ fn spawn_css_lexer_task(-filename: ~str) -> port<Token> {
let result_chan = chan(result_port); let result_chan = chan(result_port);
task::spawn(|| { task::spawn(|| {
assert (copy filename).ends_with(".css"); assert (copy filename).ends_with(~".css");
let file_try = io::read_whole_file(filename); let file_try = io::read_whole_file(filename);
// Check if the given css file existed, if it does, parse it, // Check if the given css file existed, if it does, parse it,

View file

@ -19,14 +19,14 @@ enum css_message {
} }
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) { fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
// TODO: Implement atoms so that we don't always perform string comparisons. // TODO: Implement atoms so that we don't always perform string comparisons.
scope.read(node, |node_contents| { scope.read(node, |node_contents| {
alt *node_contents.kind { alt *node_contents.kind {
Element(element) { Element(element) {
element.attrs.push(~Attr(copy key, copy value)); element.attrs.push(~Attr(copy key, copy value));
alt *element.kind { alt *element.kind {
HTMLImageElement(img) if key == "width" { HTMLImageElement(img) if key == ~"width" {
alt int::from_str(value) { alt int::from_str(value) {
none { none {
// Drop on the floor. // Drop on the floor.
@ -34,7 +34,7 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) {
some(s) { img.size.width = geometry::px_to_au(s); } some(s) { img.size.width = geometry::px_to_au(s); }
} }
} }
HTMLImageElement(img) if key == "height" { HTMLImageElement(img) if key == ~"height" {
alt int::from_str(value) { alt int::from_str(value) {
none { none {
// Drop on the floor. // Drop on the floor.
@ -51,22 +51,22 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: str, -value: str) {
} }
Text(*) { Text(*) {
fail "attempt to link up an attribute to a text node" fail ~"attempt to link up an attribute to a text node"
} }
} }
}) })
} }
fn build_element_kind(tag_name: str) -> ~ElementKind { fn build_element_kind(tag_name: ~str) -> ~ElementKind {
alt tag_name { alt tag_name {
"div" { ~HTMLDivElement } ~"div" { ~HTMLDivElement }
"img" { ~"img" {
~HTMLImageElement({ ~HTMLImageElement({
mut size: Size2D(geometry::px_to_au(100), mut size: Size2D(geometry::px_to_au(100),
geometry::px_to_au(100)) geometry::px_to_au(100))
}) })
} }
"head" { ~HTMLHeadElement } ~"head" { ~HTMLHeadElement }
_ { ~UnknownElement } _ { ~UnknownElement }
} }
} }
@ -117,7 +117,7 @@ fn css_link_listener(to_parent : chan<Stylesheet>, from_parent : port<css_messag
#[warn(no_non_implicitly_copyable_typarams)] #[warn(no_non_implicitly_copyable_typarams)]
fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>) { fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>) {
// The current reference node. // The current reference node.
let mut cur_node = scope.new_node(Element(ElementData("html", ~HTMLDivElement))); let mut cur_node = scope.new_node(Element(ElementData(~"html", ~HTMLDivElement)));
// We will spawn a separate task to parse any css that is // We will spawn a separate task to parse any css that is
// encountered, each link to a stylesheet is sent to the waiting // encountered, each link to a stylesheet is sent to the waiting
// task. After the html sheet has been fully read, the spawned // task. After the html sheet has been fully read, the spawned
@ -153,10 +153,10 @@ fn build_dom(scope: NodeScope, stream: port<Token>) -> (Node, port<Stylesheet>)
//TODO: check for things other than the link tag //TODO: check for things other than the link tag
scope.read(cur_node, |n| { scope.read(cur_node, |n| {
alt *n.kind { alt *n.kind {
Element(elmt) if elmt.tag_name == "link" { Element(elmt) if elmt.tag_name == ~"link" {
alt elmt.get_attr("rel") { alt elmt.get_attr(~"rel") {
some(r) if r == "stylesheet" { some(r) if r == ~"stylesheet" {
alt elmt.get_attr("href") { alt elmt.get_attr(~"href") {
some(filename) { some(filename) {
#debug["Linking to a css sheet named: %s", filename]; #debug["Linking to a css sheet named: %s", filename];
style_chan.send(file(copy filename)); style_chan.send(file(copy filename));

View file

@ -6,12 +6,12 @@ import vec::push;
import lexer_util::*; import lexer_util::*;
enum Token { enum Token {
StartOpeningTag(str), StartOpeningTag(~str),
EndOpeningTag, EndOpeningTag,
EndTag(str), EndTag(~str),
SelfCloseTag, SelfCloseTag,
Text(str), Text(~str),
Attr(str, str), Attr(~str, ~str),
Doctype, Doctype,
Eof Eof
} }
@ -47,14 +47,14 @@ impl html_methods for HtmlLexer {
if ch == ('<' as u8) { if ch == ('<' as u8) {
alt self.input_state.get() { alt self.input_state.get() {
CoeChar(c) { ch = c; } CoeChar(c) { ch = c; }
CoeEof { self.input_state.parse_err("eof after '<'") } CoeEof { self.input_state.parse_err(~"eof after '<'") }
} }
if ch == ('!' as u8) { if ch == ('!' as u8) {
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
self.input_state.expect_ident("DOCTYPE"); self.input_state.expect_ident(~"DOCTYPE");
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
self.input_state.expect_ident("html"); self.input_state.expect_ident(~"html");
self.input_state.eat_whitespace(); self.input_state.eat_whitespace();
self.input_state.expect('>' as u8); self.input_state.expect('>' as u8);
ret Doctype; ret Doctype;
@ -169,7 +169,7 @@ fn spawn_html_lexer_task(-filename: ~str) -> port<Token> {
task::spawn(|| { task::spawn(|| {
let filename = copy html_file; let filename = copy html_file;
assert (copy filename).ends_with(".html"); assert (copy filename).ends_with(~".html");
let file_data = io::read_whole_file(filename).get(); let file_data = io::read_whole_file(filename).get();
let reader = io::bytes_reader(file_data); let reader = io::bytes_reader(file_data);

View file

@ -45,7 +45,7 @@ impl util_methods for InputState {
self.lookahead = some(CoeChar(ch)); self.lookahead = some(CoeChar(ch));
} }
fn parse_err(err: str) -> ! { fn parse_err(err: ~str) -> ! {
fail err fail err
} }
@ -62,7 +62,7 @@ impl util_methods for InputState {
} }
} }
fn parse_ident() -> str { fn parse_ident() -> ~str {
let mut result: ~[u8] = ~[]; let mut result: ~[u8] = ~[];
loop { loop {
alt self.get() { alt self.get() {
@ -70,21 +70,21 @@ impl util_methods for InputState {
if (c.is_alpha()) { if (c.is_alpha()) {
push(result, c); push(result, c);
} else if result.len() == 0u { } else if result.len() == 0u {
self.parse_err("expected ident"); self.parse_err(~"expected ident");
} else { } else {
self.unget(c); self.unget(c);
break; break;
} }
} }
CoeEof { CoeEof {
self.parse_err("expected ident"); self.parse_err(~"expected ident");
} }
} }
} }
ret str::from_bytes(result); ret str::from_bytes(result);
} }
fn expect_ident(expected: str) { fn expect_ident(expected: ~str) {
let actual = self.parse_ident(); let actual = self.parse_ident();
if expected != actual { if expected != actual {
self.parse_err(#fmt("expected '%s' but found '%s'", expected, actual)); self.parse_err(#fmt("expected '%s' but found '%s'", expected, actual));

View file

@ -43,7 +43,7 @@ fn mainloop(po: port<Msg>) {
let surfaces = @surface_set(); let surfaces = @surface_set();
let window = glut::create_window("Servo"); let window = glut::create_window(~"Servo");
glut::reshape_window(window, 800, 600); glut::reshape_window(window, 800, 600);
let context = layers::rendergl::init_render_context(); let context = layers::rendergl::init_render_context();
@ -109,7 +109,7 @@ fn mainloop(po: port<Msg>) {
#debug("osmain: drawing to screen"); #debug("osmain: drawing to screen");
do util::time::time("compositing") { do util::time::time(~"compositing") {
layers::rendergl::render_scene(context, *scene); layers::rendergl::render_scene(context, *scene);
} }

View file

@ -5,7 +5,7 @@ import osmain::{OSMain, AddKeyHandler};
import opts::{Opts, Screen, Png}; import opts::{Opts, Screen, Png};
import engine::{Engine, LoadURLMsg}; import engine::{Engine, LoadURLMsg};
fn main(args: ~[str]) { fn main(args: ~[~str]) {
run(opts::from_cmdline_args(args)) run(opts::from_cmdline_args(args))
} }
@ -18,14 +18,14 @@ fn run(opts: Opts) {
Png(outfile) { Png(outfile) {
assert opts.urls.is_not_empty(); assert opts.urls.is_not_empty();
if opts.urls.len() > 1u { if opts.urls.len() > 1u {
fail "servo asks that you stick to a single URL in PNG output mode" fail ~"servo asks that you stick to a single URL in PNG output mode"
} }
run_pipeline_png(opts.urls.head(), outfile) run_pipeline_png(opts.urls.head(), outfile)
} }
} }
} }
fn run_pipeline_screen(urls: ~[str]) { fn run_pipeline_screen(urls: ~[~str]) {
// The platform event handler thread // The platform event handler thread
let osmain = OSMain(); let osmain = OSMain();
@ -55,7 +55,7 @@ fn run_pipeline_screen(urls: ~[str]) {
osmain.send(osmain::Exit); osmain.send(osmain::Exit);
} }
fn run_pipeline_png(-url: str, outfile: str) { fn run_pipeline_png(-url: ~str, outfile: ~str) {
// Use a PNG encoder as the graphics sink // Use a PNG encoder as the graphics sink
import gfx::pngsink; import gfx::pngsink;

View file

@ -116,7 +116,7 @@ class Font {
let status_str = unsafe { from_c_str(status_cstr) }; let status_str = unsafe { from_c_str(status_cstr) };
#error("cairo_scaled_font_glyph_extents status: %s", status_str); #error("cairo_scaled_font_glyph_extents status: %s", status_str);
fail "failed to get glyph extents from cairo" fail ~"failed to get glyph extents from cairo"
} }
} }
} }
@ -162,7 +162,7 @@ fn get_cairo_font(buf: &~[u8]) -> (*cairo_scaled_font_t, fn@()) {
// FIXME: Need negative tests // FIXME: Need negative tests
if cfont.is_null() { if cfont.is_null() {
dtor(); dtor();
fail "unable to create cairo scaled font"; fail ~"unable to create cairo scaled font";
} }
dtor = fn@(move dtor) { cairo_scaled_font_destroy(cfont); dtor() }; dtor = fn@(move dtor) { cairo_scaled_font_destroy(cfont); dtor() };
@ -199,7 +199,7 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
if FT_New_Memory_Face(library, cbuf, (*buf).len() as FT_Long, if FT_New_Memory_Face(library, cbuf, (*buf).len() as FT_Long,
0 as FT_Long, addr_of(face)).failed() { 0 as FT_Long, addr_of(face)).failed() {
dtor(); dtor();
fail "unable to create FreeType face"; fail ~"unable to create FreeType face";
} }
}); });
dtor = fn@(move dtor) { FT_Done_Face(face).for_sure(); dtor() }; dtor = fn@(move dtor) { FT_Done_Face(face).for_sure(); dtor() };
@ -208,7 +208,7 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
if cface.is_null() { if cface.is_null() {
// FIXME: Need tests for failure case // FIXME: Need tests for failure case
dtor(); dtor();
fail "unable to create cairo font face"; fail ~"unable to create cairo font face";
} }
dtor = fn@(move dtor) { cairo_font_face_destroy(cface); dtor() }; dtor = fn@(move dtor) { cairo_font_face_destroy(cface); dtor() };
@ -247,7 +247,7 @@ fn get_cairo_face(buf: &~[u8]) -> (*cairo_font_face_t, fn@()) {
dtor = fn@(move dtor) { CGDataProviderRelease(fontprov); dtor() }; dtor = fn@(move dtor) { CGDataProviderRelease(fontprov); dtor() };
let cgfont = CGFontCreateWithDataProvider(fontprov); let cgfont = CGFontCreateWithDataProvider(fontprov);
if cgfont.is_null() { fail "could not create quartz font" } if cgfont.is_null() { fail ~"could not create quartz font" }
dtor = fn@(move dtor) { CGFontRelease(cgfont); dtor() }; dtor = fn@(move dtor) { CGFontRelease(cgfont); dtor() };
let cface = cairo_quartz_font_face_create_for_cgfont(cgfont); let cface = cairo_quartz_font_face_create_for_cgfont(cgfont);

View file

@ -28,7 +28,7 @@ class FreeTypeNativeFont/& {
drop { drop {
assert self.face.is_not_null(); assert self.face.is_not_null();
if !FT_Done_Face(self.face).succeeded() { if !FT_Done_Face(self.face).succeeded() {
fail "FT_Done_Face failed"; fail ~"FT_Done_Face failed";
} }
} }
@ -73,7 +73,7 @@ fn create(lib: FT_Library, buf: &~[u8]) -> result<FreeTypeNativeFont, ()> {
0 as FT_Long, addr_of(face)).succeeded() { 0 as FT_Long, addr_of(face)).succeeded() {
// FIXME: These values are placeholders // FIXME: These values are placeholders
let res = FT_Set_Char_Size(face, 0, 20*64, 0, 72); let res = FT_Set_Char_Size(face, 0, 20*64, 0, 72);
if !res.succeeded() { fail "unable to set font char size" } if !res.succeeded() { fail ~"unable to set font char size" }
ok(FreeTypeNativeFont(face)) ok(FreeTypeNativeFont(face))
} else { } else {
err(()) err(())

View file

@ -35,7 +35,7 @@ import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy,
Calculate the layout metrics associated with a some given text Calculate the layout metrics associated with a some given text
when rendered in a specific font. when rendered in a specific font.
"] "]
fn shape_text(font: &Font, text: str) -> ~[Glyph] unsafe { fn shape_text(font: &Font, text: ~str) -> ~[Glyph] unsafe {
#debug("shaping text '%s'", text); #debug("shaping text '%s'", text);
let face_blob = vec::as_buf(*(*font).buf(), |buf| { let face_blob = vec::as_buf(*(*font).buf(), |buf| {
@ -146,7 +146,7 @@ fn should_get_glyph_indexes() {
#[ignore(reason = "random failures")]; #[ignore(reason = "random failures")];
let font = font::create_test_font(); let font = font::create_test_font();
let glyphs = shape_text(font, "firecracker"); let glyphs = shape_text(font, ~"firecracker");
let idxs = glyphs.map(|glyph| glyph.index); let idxs = glyphs.map(|glyph| glyph.index);
assert idxs == ~[32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u]; assert idxs == ~[32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
} }
@ -156,7 +156,7 @@ fn should_get_glyph_h_advance() {
#[ignore(reason = "random failures")]; #[ignore(reason = "random failures")];
let font = font::create_test_font(); let font = font::create_test_font();
let glyphs = shape_text(font, "firecracker"); let glyphs = shape_text(font, ~"firecracker");
let actual = glyphs.map(|g| g.pos.advance.x); let actual = glyphs.map(|g| g.pos.advance.x);
let expected = (~[6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7]).map(|a| px_to_au(a)); let expected = (~[6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7]).map(|a| px_to_au(a));
assert expected == actual; assert expected == actual;

View file

@ -11,7 +11,7 @@ import shaper::shape_text;
class TextRun { class TextRun {
let glyphs: ~[Glyph]; let glyphs: ~[Glyph];
new(font: Font, text: str) { new(font: Font, text: ~str) {
self.glyphs = shape_text(&font, text); self.glyphs = shape_text(&font, text);
} }
@ -34,7 +34,7 @@ fn should_calculate_the_total_size() {
let flib = FontLibrary(); let flib = FontLibrary();
let font = flib.get_test_font(); let font = flib.get_test_font();
let run = TextRun(*font, "firecracker"); let run = TextRun(*font, ~"firecracker");
let expected = Size2D(px_to_au(84), px_to_au(20)); let expected = Size2D(px_to_au(84), px_to_au(20));
assert run.size() == expected; assert run.size() == expected;
} }

View file

@ -41,7 +41,7 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color {
1.0/6.0 to 1.0/2.0 { ret m2; } 1.0/6.0 to 1.0/2.0 { ret m2; }
1.0/2.0 to 2.0/3.0 { ret m1 + (m2 - m1)*(4.0 - 6.0*h); } 1.0/2.0 to 2.0/3.0 { ret m1 + (m2 - m1)*(4.0 - 6.0*h); }
2.0/3.0 to 1.0 { ret m1; } 2.0/3.0 to 1.0 { ret m1; }
_ { fail "unexpected hue value"; } _ { fail ~"unexpected hue value"; }
} }
} }
@ -57,7 +57,7 @@ fn hsl(h : float, s : float, l : float) -> Color {
} }
impl methods for Color { impl methods for Color {
fn print() -> str { fn print() -> ~str {
#fmt["rgba(%u,%u,%u,%f)", self.red as uint, self.green as uint, #fmt["rgba(%u,%u,%u,%f)", self.red as uint, self.green as uint,
self.blue as uint, self.alpha] self.blue as uint, self.alpha]
} }
@ -68,37 +68,37 @@ mod parsing {
// TODO, fail by ignoring the rule instead of setting the // TODO, fail by ignoring the rule instead of setting the
// color to black // color to black
fn fail_unrecognized(col : str) -> Color { fn fail_unrecognized(col : ~str) -> Color {
#warn["Unrecognized color %s", col]; #warn["Unrecognized color %s", col];
ret black(); ret black();
} }
#[doc="Match an exact color keyword."] #[doc="Match an exact color keyword."]
fn parse_by_name(color : str) -> Color { fn parse_by_name(color : ~str) -> Color {
alt color.to_lower() { alt color.to_lower() {
"black" { black() } ~"black" { black() }
"silver" { silver() } ~"silver" { silver() }
"gray" { gray() } ~"gray" { gray() }
"grey" { gray() } ~"grey" { gray() }
"white" { white() } ~"white" { white() }
"maroon" { maroon() } ~"maroon" { maroon() }
"red" { red() } ~"red" { red() }
"purple" { purple() } ~"purple" { purple() }
"fuchsia" { fuchsia() } ~"fuchsia" { fuchsia() }
"green" { green() } ~"green" { green() }
"lime" { lime() } ~"lime" { lime() }
"olive" { olive() } ~"olive" { olive() }
"yellow" { yellow() } ~"yellow" { yellow() }
"navy" { navy() } ~"navy" { navy() }
"blue" { blue() } ~"blue" { blue() }
"teal" { teal() } ~"teal" { teal() }
"aqua" { aqua() } ~"aqua" { aqua() }
_ { fail_unrecognized(color) } _ { fail_unrecognized(color) }
} }
} }
#[doc="Parses a color specification in the form rgb(foo,bar,baz)"] #[doc="Parses a color specification in the form rgb(foo,bar,baz)"]
fn parse_rgb(color : str) -> Color { fn parse_rgb(color : ~str) -> Color {
// Shave off the rgb( and the ) // Shave off the rgb( and the )
let only_colors = color.substr(4u, color.len() - 5u); let only_colors = color.substr(4u, color.len() - 5u);
@ -114,7 +114,7 @@ mod parsing {
} }
#[doc="Parses a color specification in the form rgba(foo,bar,baz,qux)"] #[doc="Parses a color specification in the form rgba(foo,bar,baz,qux)"]
fn parse_rgba(color : str) -> Color { fn parse_rgba(color : ~str) -> Color {
// Shave off the rgba( and the ) // Shave off the rgba( and the )
let only_vals = color.substr(5u, color.len() - 6u); let only_vals = color.substr(5u, color.len() - 6u);
@ -130,7 +130,7 @@ mod parsing {
} }
#[doc="Parses a color specification in the form hsl(foo,bar,baz)"] #[doc="Parses a color specification in the form hsl(foo,bar,baz)"]
fn parse_hsl(color : str) -> Color { fn parse_hsl(color : ~str) -> Color {
// Shave off the hsl( and the ) // Shave off the hsl( and the )
let only_vals = color.substr(4u, color.len() - 5u); let only_vals = color.substr(4u, color.len() - 5u);
@ -146,7 +146,7 @@ mod parsing {
} }
#[doc="Parses a color specification in the form hsla(foo,bar,baz,qux)"] #[doc="Parses a color specification in the form hsla(foo,bar,baz,qux)"]
fn parse_hsla(color : str) -> Color { fn parse_hsla(color : ~str) -> Color {
// Shave off the hsla( and the ) // Shave off the hsla( and the )
let only_vals = color.substr(5u, color.len() - 6u); let only_vals = color.substr(5u, color.len() - 6u);
@ -163,12 +163,12 @@ mod parsing {
// Currently colors are supported in rgb(a,b,c) form and also by // Currently colors are supported in rgb(a,b,c) form and also by
// keywords for several common colors. // keywords for several common colors.
// TODO: extend this // TODO: extend this
fn parse_color(color : str) -> Color { fn parse_color(color : ~str) -> Color {
alt color { alt color {
c if c.starts_with("rgb(") { parse_rgb(c) } c if c.starts_with(~"rgb(") { parse_rgb(c) }
c if c.starts_with("rgba(") { parse_rgba(c) } c if c.starts_with(~"rgba(") { parse_rgba(c) }
c if c.starts_with("hsl(") { parse_hsl(c) } c if c.starts_with(~"hsl(") { parse_hsl(c) }
c if c.starts_with("hsla(") { parse_hsla(c) } c if c.starts_with(~"hsla(") { parse_hsla(c) }
c { parse_by_name(c) } c { parse_by_name(c) }
} }
} }
@ -181,54 +181,54 @@ mod test {
#[test] #[test]
fn test_parse_by_name() { fn test_parse_by_name() {
assert red().eq(parse_color("red")); assert red().eq(parse_color(~"red"));
assert lime().eq(parse_color("Lime")); assert lime().eq(parse_color(~"Lime"));
assert blue().eq(parse_color("BLUE")); assert blue().eq(parse_color(~"BLUE"));
assert green().eq(parse_color("GreEN")); assert green().eq(parse_color(~"GreEN"));
assert white().eq(parse_color("white")); assert white().eq(parse_color(~"white"));
assert black().eq(parse_color("Black")); assert black().eq(parse_color(~"Black"));
assert gray().eq(parse_color("Gray")); assert gray().eq(parse_color(~"Gray"));
assert silver().eq(parse_color("SiLvEr")); assert silver().eq(parse_color(~"SiLvEr"));
assert maroon().eq(parse_color("maroon")); assert maroon().eq(parse_color(~"maroon"));
assert purple().eq(parse_color("PURPLE")); assert purple().eq(parse_color(~"PURPLE"));
assert fuchsia().eq(parse_color("FUCHSIA")); assert fuchsia().eq(parse_color(~"FUCHSIA"));
assert olive().eq(parse_color("oLiVe")); assert olive().eq(parse_color(~"oLiVe"));
assert yellow().eq(parse_color("yellow")); assert yellow().eq(parse_color(~"yellow"));
assert navy().eq(parse_color("NAVY")); assert navy().eq(parse_color(~"NAVY"));
assert teal().eq(parse_color("Teal")); assert teal().eq(parse_color(~"Teal"));
assert aqua().eq(parse_color("Aqua")); assert aqua().eq(parse_color(~"Aqua"));
} }
#[test] #[test]
fn test_parsing_rgb() { fn test_parsing_rgb() {
assert red().eq(parse_color("rgb(255,0,0)")); assert red().eq(parse_color(~"rgb(255,0,0)"));
assert red().eq(parse_color("rgba(255,0,0,1.0)")); assert red().eq(parse_color(~"rgba(255,0,0,1.0)"));
assert red().eq(parse_color("rgba(255,0,0,1)")); assert red().eq(parse_color(~"rgba(255,0,0,1)"));
assert lime().eq(parse_color("rgba(0,255,0,1.00)")); assert lime().eq(parse_color(~"rgba(0,255,0,1.00)"));
assert rgb(1u8,2u8,3u8).eq(parse_color("rgb(1,2,03)")); assert rgb(1u8,2u8,3u8).eq(parse_color(~"rgb(1,2,03)"));
assert rgba(15u8,250u8,3u8,0.5).eq(parse_color("rgba(15,250,3,.5)")); assert rgba(15u8,250u8,3u8,0.5).eq(parse_color(~"rgba(15,250,3,.5)"));
assert rgba(15u8,250u8,3u8,0.5).eq(parse_color("rgba(15,250,3,0.5)")); assert rgba(15u8,250u8,3u8,0.5).eq(parse_color(~"rgba(15,250,3,0.5)"));
} }
#[test] #[test]
fn test_parsing_hsl() { fn test_parsing_hsl() {
assert red().eq(parse_color("hsl(0,1,.5)")); assert red().eq(parse_color(~"hsl(0,1,.5)"));
assert lime().eq(parse_color("hsl(120.0,1.0,.5)")); assert lime().eq(parse_color(~"hsl(120.0,1.0,.5)"));
assert blue().eq(parse_color("hsl(240.0,1.0,.5)")); assert blue().eq(parse_color(~"hsl(240.0,1.0,.5)"));
assert green().eq(parse_color("hsl(120.0,1.0,.25)")); assert green().eq(parse_color(~"hsl(120.0,1.0,.25)"));
assert white().eq(parse_color("hsl(1.0,1.,1.0)")); assert white().eq(parse_color(~"hsl(1.0,1.,1.0)"));
assert white().eq(parse_color("hsl(129.0,0.3,1.0)")); assert white().eq(parse_color(~"hsl(129.0,0.3,1.0)"));
assert black().eq(parse_color("hsl(231.2,0.75,0.0)")); assert black().eq(parse_color(~"hsl(231.2,0.75,0.0)"));
assert black().eq(parse_color("hsl(11.2,0.0,0.0)")); assert black().eq(parse_color(~"hsl(11.2,0.0,0.0)"));
assert gray().eq(parse_color("hsl(0.0,0.0,0.5)")); assert gray().eq(parse_color(~"hsl(0.0,0.0,0.5)"));
assert maroon().eq(parse_color("hsl(0.0,1.0,0.25)")); assert maroon().eq(parse_color(~"hsl(0.0,1.0,0.25)"));
assert purple().eq(parse_color("hsl(300.0,1.0,0.25)")); assert purple().eq(parse_color(~"hsl(300.0,1.0,0.25)"));
assert fuchsia().eq(parse_color("hsl(300,1.0,0.5)")); assert fuchsia().eq(parse_color(~"hsl(300,1.0,0.5)"));
assert olive().eq(parse_color("hsl(60.,1.0,0.25)")); assert olive().eq(parse_color(~"hsl(60.,1.0,0.25)"));
assert yellow().eq(parse_color("hsl(60.,1.0,0.5)")); assert yellow().eq(parse_color(~"hsl(60.,1.0,0.5)"));
assert navy().eq(parse_color("hsl(240.0,1.0,.25)")); assert navy().eq(parse_color(~"hsl(240.0,1.0,.25)"));
assert teal().eq(parse_color("hsl(180.0,1.0,.25)")); assert teal().eq(parse_color(~"hsl(180.0,1.0,.25)"));
assert aqua().eq(parse_color("hsl(180.0,1.0,.5)")); assert aqua().eq(parse_color(~"hsl(180.0,1.0,.5)"));
} }
} }

View file

@ -1,7 +1,7 @@
// Timing functions. // Timing functions.
import std::time::precise_time_ns; import std::time::precise_time_ns;
fn time(msg: str, callback: fn()) { fn time(msg: ~str, callback: fn()) {
let start_time = precise_time_ns(); let start_time = precise_time_ns();
callback(); callback();
let end_time = precise_time_ns(); let end_time = precise_time_ns();

View file

@ -43,7 +43,7 @@ fn add_child<T:copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
ops.with_tree_fields(child, |child_tf| { ops.with_tree_fields(child, |child_tf| {
alt child_tf.parent { alt child_tf.parent {
some(_) { fail "Already has a parent"; } some(_) { fail ~"Already has a parent"; }
none { child_tf.parent = some(parent); } none { child_tf.parent = some(parent); }
} }