summary refs log tree commit diff
path: root/src/libstd/path/posix.rs
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2014-01-18 09:17:44 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2014-01-18 09:19:10 -0800
commitf13086f4571e13f712b9606fddbee47f40c40842 (patch)
treeb99cef3530fcef75227bbd1ffab271c72a3f0006 /src/libstd/path/posix.rs
parentbf07c80838e59cb21748f7e3b092ced96f41a208 (diff)
downloadrust-f13086f4571e13f712b9606fddbee47f40c40842.tar.gz
rust-f13086f4571e13f712b9606fddbee47f40c40842.zip
Expose platform independent path separators
Diffstat (limited to 'src/libstd/path/posix.rs')
-rw-r--r--src/libstd/path/posix.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs
index 0a93f385a06..b228dc7f1ff 100644
--- a/src/libstd/path/posix.rs
+++ b/src/libstd/path/posix.rs
@@ -45,19 +45,21 @@ pub struct Path {
 }
 
 /// The standard path separator character
-pub static sep: char = '/';
-static sep_byte: u8 = sep as u8;
+pub static SEP: char = '/';
+
+/// The standard path separator byte
+pub static SEP_BYTE: u8 = SEP as u8;
 
 /// Returns whether the given byte is a path separator
 #[inline]
 pub fn is_sep_byte(u: &u8) -> bool {
-    *u as char == sep
+    *u as char == SEP
 }
 
 /// Returns whether the given char is a path separator
 #[inline]
 pub fn is_sep(c: char) -> bool {
-    c == sep
+    c == SEP
 }
 
 impl Eq for Path {
@@ -115,7 +117,7 @@ impl GenericPathUnsafe for Path {
     unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
         let path = Path::normalize(path.container_as_bytes());
         assert!(!path.is_empty());
-        let idx = path.rposition_elem(&sep_byte);
+        let idx = path.rposition_elem(&SEP_BYTE);
         Path{ repr: path, sepidx: idx }
     }
 
@@ -125,7 +127,7 @@ impl GenericPathUnsafe for Path {
             None if bytes!("..") == self.repr => {
                 let mut v = vec::with_capacity(3 + filename.len());
                 v.push_all(dot_dot_static);
-                v.push(sep_byte);
+                v.push(SEP_BYTE);
                 v.push_all(filename);
                 self.repr = Path::normalize(v);
             }
@@ -135,7 +137,7 @@ impl GenericPathUnsafe for Path {
             Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => {
                 let mut v = vec::with_capacity(self.repr.len() + 1 + filename.len());
                 v.push_all(self.repr);
-                v.push(sep_byte);
+                v.push(SEP_BYTE);
                 v.push_all(filename);
                 self.repr = Path::normalize(v);
             }
@@ -146,22 +148,22 @@ impl GenericPathUnsafe for Path {
                 self.repr = Path::normalize(v);
             }
         }
-        self.sepidx = self.repr.rposition_elem(&sep_byte);
+        self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
     }
 
     unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
         let path = path.container_as_bytes();
         if !path.is_empty() {
-            if path[0] == sep_byte {
+            if path[0] == SEP_BYTE {
                 self.repr = Path::normalize(path);
             }  else {
                 let mut v = vec::with_capacity(self.repr.len() + path.len() + 1);
                 v.push_all(self.repr);
-                v.push(sep_byte);
+                v.push(SEP_BYTE);
                 v.push_all(path);
                 self.repr = Path::normalize(v);
             }
-            self.sepidx = self.repr.rposition_elem(&sep_byte);
+            self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
         }
     }
 }
@@ -211,7 +213,7 @@ impl GenericPath for Path {
                 } else {
                     self.repr.truncate(idx);
                 }
-                self.sepidx = self.repr.rposition_elem(&sep_byte);
+                self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
                 true
             }
         }
@@ -227,7 +229,7 @@ impl GenericPath for Path {
 
     #[inline]
     fn is_absolute(&self) -> bool {
-        self.repr[0] == sep_byte
+        self.repr[0] == SEP_BYTE
     }
 
     fn is_ancestor_of(&self, other: &Path) -> bool {
@@ -291,7 +293,7 @@ impl GenericPath for Path {
                     }
                 }
             }
-            Some(Path::new(comps.connect_vec(&sep_byte)))
+            Some(Path::new(comps.connect_vec(&SEP_BYTE)))
         }
     }
 
@@ -333,14 +335,14 @@ impl Path {
     fn normalize<V: Vector<u8>+CopyableVector<u8>>(v: V) -> ~[u8] {
         // borrowck is being very picky
         let val = {
-            let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == sep_byte;
+            let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE;
             let v_ = if is_abs { v.as_slice().slice_from(1) } else { v.as_slice() };
             let comps = normalize_helper(v_, is_abs);
             match comps {
                 None => None,
                 Some(comps) => {
                     if is_abs && comps.is_empty() {
-                        Some(~[sep_byte])
+                        Some(~[SEP_BYTE])
                     } else {
                         let n = if is_abs { comps.len() } else { comps.len() - 1} +
                                 comps.iter().map(|v| v.len()).sum();
@@ -353,7 +355,7 @@ impl Path {
                             }
                         }
                         for comp in it {
-                            v.push(sep_byte);
+                            v.push(SEP_BYTE);
                             v.push_all(comp);
                         }
                         Some(v)
@@ -372,7 +374,7 @@ impl Path {
     /// /a/b/c and a/b/c yield the same set of components.
     /// A path of "/" yields no components. A path of "." yields one component.
     pub fn components<'a>(&'a self) -> Components<'a> {
-        let v = if self.repr[0] == sep_byte {
+        let v = if self.repr[0] == SEP_BYTE {
             self.repr.slice_from(1)
         } else { self.repr.as_slice() };
         let mut ret = v.split(is_sep_byte);
@@ -386,7 +388,7 @@ impl Path {
     /// Returns an iterator that yields each component of the path in reverse.
     /// See components() for details.
     pub fn rev_components<'a>(&'a self) -> RevComponents<'a> {
-        let v = if self.repr[0] == sep_byte {
+        let v = if self.repr[0] == SEP_BYTE {
             self.repr.slice_from(1)
         } else { self.repr.as_slice() };
         let mut ret = v.rsplit(is_sep_byte);