diff options
Diffstat (limited to 'src/components/util')
-rw-r--r-- | src/components/util/debug.rs | 18 | ||||
-rw-r--r-- | src/components/util/geometry.rs | 7 | ||||
-rw-r--r-- | src/components/util/io.rs | 14 | ||||
-rw-r--r-- | src/components/util/range.rs | 17 | ||||
-rw-r--r-- | src/components/util/time.rs | 8 | ||||
-rw-r--r-- | src/components/util/url.rs | 4 | ||||
-rw-r--r-- | src/components/util/util.rc | 3 | ||||
-rw-r--r-- | src/components/util/vec.rs | 2 |
8 files changed, 52 insertions, 21 deletions
diff --git a/src/components/util/debug.rs b/src/components/util/debug.rs index 67a1d7d5f21..5c9aa700d5b 100644 --- a/src/components/util/debug.rs +++ b/src/components/util/debug.rs @@ -2,30 +2,32 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::io; +use std::rt::io; +use std::rt::io::Writer; use std::vec::raw::buf_as_slice; use std::cast::transmute; use std::mem::size_of; fn hexdump_slice(buf: &[u8]) { - let stderr = io::stderr(); - stderr.write_str(" "); + let mut stderr = io::stderr(); + stderr.write(bytes!(" ")); for (i, &v) in buf.iter().enumerate() { - stderr.write_str(fmt!("%02X ", v as uint)); + let output = format!("{:02X} ", v as uint); + stderr.write(output.as_bytes()); match i % 16 { - 15 => stderr.write_str("\n "), - 7 => stderr.write_str(" "), + 15 => stderr.write(bytes!("\n ")), + 7 => stderr.write(bytes!(" ")), _ => () } stderr.flush(); } - stderr.write_char('\n'); + stderr.write(bytes!("\n")); } pub fn hexdump<T>(obj: &T) { unsafe { let buf: *u8 = transmute(obj); - debug!("dumping at %p", buf); + debug!("dumping at {:p}", buf); buf_as_slice(buf, size_of::<T>(), hexdump_slice); } } diff --git a/src/components/util/geometry.rs b/src/components/util/geometry.rs index febb33660f4..ed0dcd5c420 100644 --- a/src/components/util/geometry.rs +++ b/src/components/util/geometry.rs @@ -7,6 +7,7 @@ use geom::rect::Rect; use geom::size::Size2D; use std::num::{NumCast, One, Zero}; +use std::fmt; pub struct Au(i32); @@ -18,6 +19,12 @@ impl Clone for Au { } } +impl fmt::Default for Au { + fn fmt(obj: &Au, f: &mut fmt::Formatter) { + write!(f.buf, "Au({})", *obj); + } +} + impl Eq for Au { #[inline] fn eq(&self, other: &Au) -> bool { diff --git a/src/components/util/io.rs b/src/components/util/io.rs new file mode 100644 index 00000000000..9fa4dda4a4f --- /dev/null +++ b/src/components/util/io.rs @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use std::rt::io::{io_error, EndOfFile}; + +/// Ignore the end-of-file condition within a block of code. +pub fn ignoring_eof<U>(cb: &fn() -> U) -> U { + io_error::cond.trap(|e| + match e.kind { + EndOfFile => (), + _ => io_error::cond.raise(e) + }).inside(cb) +} diff --git a/src/components/util/range.rs b/src/components/util/range.rs index e52dbae02ab..c256ce3d1c8 100644 --- a/src/components/util/range.rs +++ b/src/components/util/range.rs @@ -4,6 +4,7 @@ use std::cmp::{max, min}; use std::iter; +use std::fmt; enum RangeRelation { OverlapsBegin(/* overlap */ uint), @@ -21,6 +22,12 @@ pub struct Range { priv len: uint } +impl fmt::Default for Range { + fn fmt(obj: &Range, f: &mut fmt::Formatter) { + write!(f.buf, "[{} .. {})", obj.begin(), obj.end()); + } +} + impl Range { #[inline] pub fn new(off: uint, len: uint) -> Range { @@ -131,15 +138,15 @@ impl Range { let overlap = other.end() - self.begin(); return OverlapsEnd(overlap); } - fail!(fmt!("relation_to_range(): didn't classify self=%?, other=%?", - self, other)); + fail!("relation_to_range(): didn't classify self={:?}, other={:?}", + self, other); } #[inline] pub fn repair_after_coalesced_range(&mut self, other: &Range) { let relation = self.relation_to_range(other); - debug!("repair_after_coalesced_range: possibly repairing range %?", self); - debug!("repair_after_coalesced_range: relation of original range and coalesced range(%?): %?", + debug!("repair_after_coalesced_range: possibly repairing range {:?}", self); + debug!("repair_after_coalesced_range: relation of original range and coalesced range({:?}): {:?}", other, relation); match relation { EntirelyBefore => { }, @@ -152,6 +159,6 @@ impl Range { self.reset(other.begin(), len); } }; - debug!("repair_after_coalesced_range: new range: ---- %?", self); + debug!("repair_after_coalesced_range: new range: ---- {:?}", self); } } diff --git a/src/components/util/time.rs b/src/components/util/time.rs index 9937dbd40e0..bfc1a1bd43c 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -86,7 +86,7 @@ impl ProfilerCategory { LayoutMainCategory | LayoutDispListBuildCategory | LayoutShapingCategory=> " - ", _ => "" }; - fmt!("%s%?", padding, self) + format!("{:s}{:?}", padding, self) } } @@ -159,7 +159,7 @@ impl Profiler { } fn print_buckets(&mut self) { - println(fmt!("%31s %15s %15s %15s %15s %15s", + println(format!("{:31s} {:15s} {:15s} {:15s} {:15s} {:15s}", "_category_", "_mean (ms)_", "_median (ms)_", "_min (ms)_", "_max (ms)_", "_bucket size_")); for (category, data) in self.buckets.iter() { @@ -173,7 +173,7 @@ impl Profiler { data[data_len / 2], data.iter().min().unwrap(), data.iter().max().unwrap()); - println(fmt!("%-30s: %15.4f %15.4f %15.4f %15.4f %15u", + println(format!("{:-30s}: {:15.4f} {:15.4f} {:15.4f} {:15.4f} {:15u}", category.format(), mean, median, min, max, data_len)); } } @@ -200,7 +200,7 @@ pub fn time<T>(msg: &str, callback: &fn() -> T) -> T{ let end_time = precise_time_ns(); let ms = ((end_time - start_time) as f64 / 1000000f64); if ms >= 5f64 { - debug!("%s took %? ms", msg, ms); + debug!("{:s} took {} ms", msg, ms); } return val; } diff --git a/src/components/util/url.rs b/src/components/util/url.rs index 309117081ec..29385decd58 100644 --- a/src/components/util/url.rs +++ b/src/components/util/url.rs @@ -34,7 +34,7 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url { } } else { let current_url = current_url.unwrap(); - debug!("make_url: current_url: %?", current_url); + debug!("make_url: current_url: {:?}", current_url); if str_url.starts_with("//") { current_url.scheme + ":" + str_url } else if current_url.path.is_empty() || @@ -94,7 +94,7 @@ mod make_url_tests { fn should_create_absolute_file_url_if_current_url_is_none_and_str_url_looks_filey() { let file = ~"local.html"; let url = make_url(file, None); - debug!("url: %?", url); + debug!("url: {:?}", url); assert!(url.scheme == ~"file"); let path = os::getcwd(); // FIXME (#1094): not the right way to transform a path diff --git a/src/components/util/util.rc b/src/components/util/util.rc index c84a87b13e5..fd2110c839e 100644 --- a/src/components/util/util.rc +++ b/src/components/util/util.rc @@ -8,7 +8,7 @@ url = "http://servo.org/")]; #[crate_type = "lib"]; -#[feature(macro_rules)]; +#[feature(macro_rules, managed_boxes)]; extern mod extra; extern mod geom; @@ -22,3 +22,4 @@ pub mod tree; pub mod url; pub mod vec; pub mod debug; +pub mod io; diff --git a/src/components/util/vec.rs b/src/components/util/vec.rs index 76ddb5cd978..7682eeab2ae 100644 --- a/src/components/util/vec.rs +++ b/src/components/util/vec.rs @@ -51,7 +51,7 @@ fn test_miss_all_elems<T: Eq + Ord>(arr: &[T], misses: &[T]) { let mut i = 0; while i < misses.len() { let res = arr.binary_search(&misses[i]); - debug!("%? == %? ?", misses[i], res); + debug!("{:?} == {:?} ?", misses[i], res); assert!(!test_match(&misses[i], arr.binary_search(&misses[i]))); i += 1; } |