1
Fork 0

libcore: Add is_absolute() to paths. Closes #5851.

This commit is contained in:
Patrick Walton 2013-04-19 22:22:46 -07:00
parent d0451eebc4
commit 2c5afa4753

View file

@ -67,6 +67,8 @@ pub trait GenericPath {
fn is_restricted(&self) -> bool; fn is_restricted(&self) -> bool;
fn normalize(&self) -> Self; fn normalize(&self) -> Self;
fn is_absolute(&self) -> bool;
} }
#[cfg(windows)] #[cfg(windows)]
@ -379,10 +381,11 @@ impl ToStr for PosixPath {
// FIXME (#3227): when default methods in traits are working, de-duplicate // FIXME (#3227): when default methods in traits are working, de-duplicate
// PosixPath and WindowsPath, most of their methods are common. // PosixPath and WindowsPath, most of their methods are common.
impl GenericPath for PosixPath { impl GenericPath for PosixPath {
fn from_str(s: &str) -> PosixPath { fn from_str(s: &str) -> PosixPath {
let mut components = ~[]; let mut components = ~[];
for str::each_split_nonempty(s, |c| c == '/') |s| { components.push(s.to_owned()) } for str::each_split_nonempty(s, |c| c == '/') |s| {
components.push(s.to_owned())
}
let is_absolute = (s.len() != 0 && s[0] == '/' as u8); let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
return PosixPath { is_absolute: is_absolute, return PosixPath { is_absolute: is_absolute,
components: components } components: components }
@ -540,6 +543,10 @@ impl GenericPath for PosixPath {
// ..self // ..self
} }
} }
fn is_absolute(&self) -> bool {
self.is_absolute
}
} }
@ -563,7 +570,6 @@ impl ToStr for WindowsPath {
impl GenericPath for WindowsPath { impl GenericPath for WindowsPath {
fn from_str(s: &str) -> WindowsPath { fn from_str(s: &str) -> WindowsPath {
let host; let host;
let device; let device;
@ -809,6 +815,10 @@ impl GenericPath for WindowsPath {
components: normalize(self.components) components: normalize(self.components)
} }
} }
fn is_absolute(&self) -> bool {
self.is_absolute
}
} }