about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-04-19 22:22:46 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-04-22 10:31:30 -0700
commit2c5afa4753a7a5b525be83e42a767cf556103faa (patch)
tree33e9c4e3d864aa7b21e253bb3491ec37607f5fd2
parentd0451eebc41d4eaddcc299c868b5ad983e8c8eb9 (diff)
downloadrust-2c5afa4753a7a5b525be83e42a767cf556103faa.tar.gz
rust-2c5afa4753a7a5b525be83e42a767cf556103faa.zip
libcore: Add `is_absolute()` to paths. Closes #5851.
-rw-r--r--src/libcore/path.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index 0e8dbd144b1..23f7e912f96 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -67,6 +67,8 @@ pub trait GenericPath {
     fn is_restricted(&self) -> bool;
 
     fn normalize(&self) -> Self;
+
+    fn is_absolute(&self) -> bool;
 }
 
 #[cfg(windows)]
@@ -379,10 +381,11 @@ impl ToStr for PosixPath {
 // FIXME (#3227): when default methods in traits are working, de-duplicate
 // PosixPath and WindowsPath, most of their methods are common.
 impl GenericPath for PosixPath {
-
     fn from_str(s: &str) -> PosixPath {
         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);
         return PosixPath { is_absolute: is_absolute,
                            components: components }
@@ -540,6 +543,10 @@ impl GenericPath for PosixPath {
           //  ..self
         }
     }
+
+    fn is_absolute(&self) -> bool {
+        self.is_absolute
+    }
 }
 
 
@@ -563,7 +570,6 @@ impl ToStr for WindowsPath {
 
 
 impl GenericPath for WindowsPath {
-
     fn from_str(s: &str) -> WindowsPath {
         let host;
         let device;
@@ -809,6 +815,10 @@ impl GenericPath for WindowsPath {
             components: normalize(self.components)
         }
     }
+
+    fn is_absolute(&self) -> bool {
+        self.is_absolute
+    }
 }