about summary refs log tree commit diff
path: root/src/libglob
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-10 21:01:41 -0700
committerbors <bors@rust-lang.org>2014-04-10 21:01:41 -0700
commitcea8def62068b405495ecd1810124ebc88b4f90b (patch)
tree65d5755bd532a9213799c52572db6d6683d5e942 /src/libglob
parent0156af156d70efd5a3c96d0c5b8fc9bec39a7ae5 (diff)
parentdef90f43e2df9968cda730a2a30cb7ccb9513002 (diff)
downloadrust-cea8def62068b405495ecd1810124ebc88b4f90b.tar.gz
rust-cea8def62068b405495ecd1810124ebc88b4f90b.zip
auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it.

Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
Diffstat (limited to 'src/libglob')
-rw-r--r--src/libglob/lib.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs
index ca1fd2b560e..21f04a83e49 100644
--- a/src/libglob/lib.rs
+++ b/src/libglob/lib.rs
@@ -37,6 +37,7 @@ use std::cell::Cell;
 use std::{cmp, os, path};
 use std::io::fs;
 use std::path::is_sep;
+use std::strbuf::StrBuf;
 
 /**
  * An iterator that yields Paths from the filesystem that match a particular
@@ -310,7 +311,7 @@ impl Pattern {
      * match the input string and nothing else.
      */
     pub fn escape(s: &str) -> ~str {
-        let mut escaped = ~"";
+        let mut escaped = StrBuf::new();
         for c in s.chars() {
             match c {
                 // note that ! does not need escaping because it is only special inside brackets
@@ -324,7 +325,7 @@ impl Pattern {
                 }
             }
         }
-        escaped
+        escaped.into_owned()
     }
 
     /**
@@ -463,8 +464,8 @@ impl Pattern {
 fn fill_todo(todo: &mut Vec<(Path, uint)>, patterns: &[Pattern], idx: uint, path: &Path,
              options: MatchOptions) {
     // convert a pattern that's just many Char(_) to a string
-    fn pattern_as_str(pattern: &Pattern) -> Option<~str> {
-        let mut s = ~"";
+    fn pattern_as_str(pattern: &Pattern) -> Option<StrBuf> {
+        let mut s = StrBuf::new();
         for token in pattern.tokens.iter() {
             match *token {
                 Char(c) => s.push_char(c),
@@ -494,8 +495,8 @@ fn fill_todo(todo: &mut Vec<(Path, uint)>, patterns: &[Pattern], idx: uint, path
             // continue. So instead of passing control back to the iterator,
             // we can just check for that one entry and potentially recurse
             // right away.
-            let special = "." == s || ".." == s;
-            let next_path = path.join(s);
+            let special = "." == s.as_slice() || ".." == s.as_slice();
+            let next_path = path.join(s.as_slice());
             if (special && path.is_dir()) || (!special && next_path.exists()) {
                 add(todo, next_path);
             }