]> git.lizzy.rs Git - rust.git/commitdiff
std: move StrUtil::as_c_str into StrSlice
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 23 Jul 2013 04:41:46 +0000 (21:41 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 23 Jul 2013 23:56:22 +0000 (16:56 -0700)
23 files changed:
src/libextra/rl.rs
src/librustc/back/link.rs
src/librustc/back/passes.rs
src/librustc/lib/llvm.rs
src/librustc/metadata/loader.rs
src/librustc/middle/trans/asm.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/builder.rs
src/librustc/middle/trans/consts.rs
src/librustc/middle/trans/context.rs
src/librustc/middle/trans/controlflow.rs
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/trans/glue.rs
src/librustpkg/util.rs
src/libstd/io.rs
src/libstd/os.rs
src/libstd/path.rs
src/libstd/prelude.rs
src/libstd/ptr.rs
src/libstd/rt/logging.rs
src/libstd/rt/uv/uvll.rs
src/libstd/run.rs
src/libstd/str.rs

index 8d291377b1eb99277c72158dcef0e8a49e979ff5..08e1c240a4c65378f8e486b44f31ef80b5390876 100644 (file)
@@ -32,7 +32,7 @@ pub mod rustrt {
 
 /// Add a line to history
 pub unsafe fn add_history(line: &str) -> bool {
-    do str::as_c_str(line) |buf| {
+    do line.as_c_str |buf| {
         rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
     }
 }
@@ -44,21 +44,21 @@ pub unsafe fn set_history_max_len(len: int) -> bool {
 
 /// Save line history to a file
 pub unsafe fn save_history(file: &str) -> bool {
-    do str::as_c_str(file) |buf| {
+    do file.as_c_str |buf| {
         rustrt::linenoiseHistorySave(buf) == 1 as c_int
     }
 }
 
 /// Load line history from a file
 pub unsafe fn load_history(file: &str) -> bool {
-    do str::as_c_str(file) |buf| {
+    do file.as_c_str |buf| {
         rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
     }
 }
 
 /// Print out a prompt and then wait for input and return it
 pub unsafe fn read(prompt: &str) -> Option<~str> {
-    do str::as_c_str(prompt) |buf| {
+    do prompt.as_c_str |buf| {
         let line = rustrt::linenoise(buf);
 
         if line.is_null() { None }
@@ -80,7 +80,7 @@ pub unsafe fn complete(cb: CompletionCb) {
 
             unsafe {
                 do cb(str::raw::from_c_str(line)) |suggestion| {
-                    do str::as_c_str(suggestion) |buf| {
+                    do suggestion.as_c_str |buf| {
                         rustrt::linenoiseAddCompletion(completions, buf);
                     }
                 }
index f9910462db5a2f460415693ae46ae11067c1e49b..d932dc80d518742c847b5884217b6a2c23ddd4c7 100644 (file)
@@ -76,9 +76,9 @@ pub fn WriteOutputFile(sess: Session,
         OptLevel: c_int,
         EnableSegmentedStacks: bool) {
     unsafe {
-        do str::as_c_str(Triple) |Triple| {
-            do str::as_c_str(Feature) |Feature| {
-                do str::as_c_str(Output) |Output| {
+        do Triple.as_c_str |Triple| {
+            do Feature.as_c_str |Feature| {
+                do Output.as_c_str |Output| {
                     let result = llvm::LLVMRustWriteOutputFile(
                             PM,
                             M,
@@ -263,16 +263,16 @@ pub fn run_passes(sess: Session,
                   output_type_bitcode => {
                     if opts.optimize != session::No {
                         let filename = output.with_filetype("no-opt.bc");
-                        str::as_c_str(filename.to_str(), |buf| {
-                            llvm::LLVMWriteBitcodeToFile(llmod, buf)
-                        });
+                        do filename.to_str().as_c_str |buf| {
+                            llvm::LLVMWriteBitcodeToFile(llmod, buf);
+                        }
                     }
                   }
                   _ => {
                     let filename = output.with_filetype("bc");
-                    str::as_c_str(filename.to_str(), |buf| {
-                        llvm::LLVMWriteBitcodeToFile(llmod, buf)
-                    });
+                    do filename.to_str().as_c_str |buf| {
+                        llvm::LLVMWriteBitcodeToFile(llmod, buf);
+                    }
                   }
                 }
             }
@@ -333,9 +333,9 @@ pub fn run_passes(sess: Session,
                     // Always output the bitcode file with --save-temps
 
                     let filename = output.with_filetype("opt.bc");
-                    str::as_c_str(filename.to_str(), |buf| {
+                    do filename.to_str().as_c_str |buf| {
                         llvm::LLVMWriteBitcodeToFile(llmod, buf)
-                    });
+                    };
                     // Save the assembly file if -S is used
                     if output_type == output_type_assembly {
                         WriteOutputFile(
@@ -391,13 +391,15 @@ pub fn run_passes(sess: Session,
 
             if output_type == output_type_llvm_assembly {
                 // Given options "-S --emit-llvm": output LLVM assembly
-                str::as_c_str(output.to_str(), |buf_o| {
-                    llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
+                do output.to_str().as_c_str |buf_o| {
+                    llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
+                }
             } else {
                 // If only a bitcode file is asked for by using the
                 // '--emit-llvm' flag, then output it here
-                str::as_c_str(output.to_str(),
-                            |buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) );
+                do output.to_str().as_c_str |buf| {
+                    llvm::LLVMWriteBitcodeToFile(llmod, buf);
+                }
             }
 
             llvm::LLVMDisposeModule(llmod);
index f9dc88074d3b15044ec670bd2a9c32c82faa592f..4533aeebbcb37ef3927a0fd237acd8e523b406ea 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::str;
 use std::io;
 
 use driver::session::{OptLevel, No, Less, Aggressive};
@@ -174,7 +173,7 @@ pub fn populate_pass_manager(sess: Session, pm: &mut PassManager, pass_list:&[~s
 }
 
 pub fn create_pass(name:&str) -> Option<PassRef> {
-    do str::as_c_str(name) |s| {
+    do name.as_c_str |s| {
         unsafe {
             let p = llvm::LLVMCreatePass(s);
             if p.is_null() {
index d1a9e387d00ed6445c580a6cea7a83148e3fa7c4..f3bca7a6ab373dd59a89d285a0cd1ee4bb5f5151 100644 (file)
@@ -12,7 +12,6 @@
 use std::hashmap::HashMap;
 use std::libc::{c_uint, c_ushort};
 use std::option;
-use std::str;
 
 use middle::trans::type_::Type;
 
@@ -2287,10 +2286,9 @@ pub struct TargetData {
 }
 
 pub fn mk_target_data(string_rep: &str) -> TargetData {
-    let lltd =
-        str::as_c_str(string_rep, |buf| unsafe {
-            llvm::LLVMCreateTargetData(buf)
-        });
+    let lltd = do string_rep.as_c_str |buf| {
+        unsafe { llvm::LLVMCreateTargetData(buf) }
+    };
 
     TargetData {
         lltd: lltd,
index d6687b4313a254ef3d206560f274cbff313ceb23..a0789b3e3232980ae841bf449cb3f48c558f4fae 100644 (file)
@@ -186,9 +186,9 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem],
 fn get_metadata_section(os: os,
                         filename: &Path) -> Option<@~[u8]> {
     unsafe {
-        let mb = str::as_c_str(filename.to_str(), |buf| {
+        let mb = do filename.to_str().as_c_str |buf| {
             llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
-        });
+        };
         if mb as int == 0 { return option::None::<@~[u8]>; }
         let of = match mk_object_file(mb) {
             option::Some(of) => of,
index fadeab0f1f7708bdac1bd52a70889d07c414c0c7..903f36c4f8a71e49dc622f061ec7fa2de37f9fe4 100644 (file)
@@ -21,7 +21,6 @@
 
 use middle::trans::type_::Type;
 
-use std::str;
 use syntax::ast;
 
 // Take an inline assembly expression and splat it out via LLVM
@@ -123,8 +122,8 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
         ast::asm_intel => lib::llvm::AD_Intel
     };
 
-    let r = do str::as_c_str(ia.asm) |a| {
-        do str::as_c_str(constraints) |c| {
+    let r = do ia.asm.as_c_str |a| {
+        do constraints.as_c_str |c| {
             InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
         }
     };
index 32a5ebe0c39cb100bd884a200a6c5ed4ca9e37c0..9c3eeed5a344a0aedde62ab301a834f58c4623e8 100644 (file)
@@ -70,7 +70,6 @@
 use std::int;
 use std::io;
 use std::libc::c_uint;
-use std::str;
 use std::uint;
 use std::vec;
 use std::local_data;
@@ -549,11 +548,11 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
 // Structural comparison: a rather involved form of glue.
 pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) {
     if cx.sess.opts.save_temps {
-        let _: () = str::as_c_str(s, |buf| {
+        do s.as_c_str |buf| {
             unsafe {
                 llvm::LLVMSetValueName(v, buf)
             }
-        });
+        }
     }
 }
 
@@ -1577,16 +1576,18 @@ pub struct BasicBlocks {
 pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef {
     unsafe {
         let cx = task_llcx();
-        str::as_c_str("static_allocas",
-                      |buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
+        do "static_allocas".as_c_str | buf| {
+            llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
+        }
     }
 }
 
 pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
     unsafe {
         let cx = task_llcx();
-        str::as_c_str("return",
-                      |buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
+        do "return".as_c_str |buf| {
+            llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
+        }
     }
 }
 
@@ -2353,11 +2354,11 @@ fn create_entry_fn(ccx: @mut CrateContext,
             };
             decl_cdecl_fn(ccx.llmod, main_name, llfty)
         };
-        let llbb = str::as_c_str("top", |buf| {
+        let llbb = do "top".as_c_str |buf| {
             unsafe {
                 llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
             }
-        });
+        };
         let bld = ccx.builder.B;
         unsafe {
             llvm::LLVMPositionBuilderAtEnd(bld, llbb);
@@ -2457,9 +2458,9 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
                 exprt = m == ast::m_mutbl;
                 unsafe {
                     let llty = llvm::LLVMTypeOf(v);
-                    let g = str::as_c_str(s, |buf| {
+                    let g = do s.as_c_str |buf| {
                         llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
-                    });
+                    };
                     ccx.item_symbols.insert(i.id, s);
                     g
                 }
@@ -2509,7 +2510,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
                 ast::foreign_item_static(*) => {
                     let typ = ty::node_id_to_type(ccx.tcx, ni.id);
                     let ident = token::ident_to_str(&ni.ident);
-                    let g = do str::as_c_str(ident) |buf| {
+                    let g = do ident.as_c_str |buf| {
                         unsafe {
                             let ty = type_of(ccx, typ);
                             llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf)
@@ -2609,11 +2610,11 @@ pub fn trans_constant(ccx: &mut CrateContext, it: @ast::item) {
             let s = mangle_exported_name(ccx, p, ty::mk_int()).to_managed();
             let disr_val = vi[i].disr_val;
             note_unique_llvm_symbol(ccx, s);
-            let discrim_gvar = str::as_c_str(s, |buf| {
+            let discrim_gvar = do s.as_c_str |buf| {
                 unsafe {
                     llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
                 }
-            });
+            };
             unsafe {
                 llvm::LLVMSetInitializer(discrim_gvar, C_int(ccx, disr_val));
                 llvm::LLVMSetGlobalConstant(discrim_gvar, True);
@@ -2750,7 +2751,7 @@ pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) {
     }
 
     let gc_metadata_name = ~"_gc_module_metadata_" + llmod_id;
-    let gc_metadata = do str::as_c_str(gc_metadata_name) |buf| {
+    let gc_metadata = do gc_metadata_name.as_c_str |buf| {
         unsafe {
             llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
         }
@@ -2813,11 +2814,11 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
     let sym_name = ~"_rust_crate_map_" + mapname;
     let arrtype = Type::array(&int_type, n_subcrates as u64);
     let maptype = Type::struct_([Type::i32(), Type::i8p(), int_type, arrtype], false);
-    let map = str::as_c_str(sym_name, |buf| {
+    let map = do sym_name.as_c_str |buf| {
         unsafe {
             llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
         }
-    });
+    };
     lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
     return map;
 }
@@ -2832,11 +2833,11 @@ pub fn fill_crate_map(ccx: @mut CrateContext, map: ValueRef) {
                       cdata.name,
                       cstore::get_crate_vers(cstore, i),
                       cstore::get_crate_hash(cstore, i));
-        let cr = str::as_c_str(nm, |buf| {
+        let cr = do nm.as_c_str |buf| {
             unsafe {
                 llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
             }
-        });
+        };
         subcrates.push(p2i(ccx, cr));
         i += 1;
     }
@@ -2895,16 +2896,16 @@ pub fn write_metadata(cx: &mut CrateContext, crate: &ast::Crate) {
     let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
     let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
     let llconst = C_struct([llmeta]);
-    let mut llglobal = str::as_c_str("rust_metadata", |buf| {
+    let mut llglobal = do "rust_metadata".as_c_str |buf| {
         unsafe {
             llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst).to_ref(), buf)
         }
-    });
+    };
     unsafe {
         llvm::LLVMSetInitializer(llglobal, llconst);
-        str::as_c_str(cx.sess.targ_cfg.target_strs.meta_sect_name, |buf| {
+        do cx.sess.targ_cfg.target_strs.meta_sect_name.as_c_str |buf| {
             llvm::LLVMSetSection(llglobal, buf)
-        });
+        };
         lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
 
         let t_ptr_i8 = Type::i8p();
@@ -2923,7 +2924,7 @@ fn mk_global(ccx: &CrateContext,
              internal: bool)
           -> ValueRef {
     unsafe {
-        let llglobal = do str::as_c_str(name) |buf| {
+        let llglobal = do name.as_c_str |buf| {
             llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval).to_ref(), buf)
         };
         llvm::LLVMSetInitializer(llglobal, llval);
index a4a976145b9a5c7eba237813209eea6f97a4ee87..1c9161163cc5b71eda17ea3f9bbec3a7bffb6b8a 100644 (file)
@@ -20,7 +20,6 @@
 use std::cast;
 use std::hashmap::HashMap;
 use std::libc::{c_uint, c_ulonglong, c_char};
-use std::str;
 use std::vec;
 use syntax::codemap::span;
 
@@ -424,9 +423,9 @@ pub fn alloca(&self, ty: Type, name: &str) -> ValueRef {
             if name.is_empty() {
                 llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), noname())
             } else {
-                str::as_c_str(
-                    name,
-                    |c| llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), c))
+                do name.as_c_str |c| {
+                    llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), c)
+                }
             }
         }
     }
@@ -896,9 +895,9 @@ pub fn trap(&self) {
             let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(self.llbuilder);
             let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
             let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
-            let T: ValueRef = str::as_c_str("llvm.trap", |buf| {
+            let T: ValueRef = do "llvm.trap".as_c_str |buf| {
                 llvm::LLVMGetNamedFunction(M, buf)
-            });
+            };
             assert!((T as int != 0));
             let args: &[ValueRef] = [];
             self.count_insn("trap");
index 9246ca1f6410b430b40353c1ebcd8fec4a301865..15793ea747f3fd5d8ebdf7f512f554b9e363b9eb 100644 (file)
@@ -31,7 +31,6 @@
 use middle::trans::type_::Type;
 
 use std::libc::c_uint;
-use std::str;
 use syntax::{ast, ast_util, ast_map};
 
 pub fn const_lit(cx: &mut CrateContext, e: &ast::expr, lit: ast::lit)
@@ -513,7 +512,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
               ast::expr_vec(ref es, ast::m_imm) => {
                 let (cv, sz, llunitty) = const_vec(cx, e, *es);
                 let llty = val_ty(cv);
-                let gv = do str::as_c_str("const") |name| {
+                let gv = do "const".as_c_str |name| {
                     llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name)
                 };
                 llvm::LLVMSetInitializer(gv, cv);
index 2879e4babbceb91249ee54fcb83c1612f54e3eec..78544c1c6c4fc1c6c9d2f986d8ad512cd7f163ad 100644 (file)
@@ -28,7 +28,6 @@
 
 use std::hash;
 use std::hashmap::{HashMap, HashSet};
-use std::str;
 use std::local_data;
 use syntax::ast;
 
@@ -125,13 +124,11 @@ pub fn new(sess: session::Session,
         unsafe {
             let llcx = llvm::LLVMContextCreate();
             set_task_llcx(llcx);
-            let llmod = str::as_c_str(name, |buf| {
-                llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
-            });
+            let llmod = name.as_c_str(|buf| llvm::LLVMModuleCreateWithNameInContext(buf, llcx));
             let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
             let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
-            str::as_c_str(data_layout, |buf| llvm::LLVMSetDataLayout(llmod, buf));
-            str::as_c_str(targ_triple, |buf| llvm::LLVMSetTarget(llmod, buf));
+            data_layout.as_c_str(|buf| llvm::LLVMSetDataLayout(llmod, buf));
+            targ_triple.as_c_str(|buf| llvm::LLVMSetTarget(llmod, buf));
             let targ_cfg = sess.targ_cfg;
 
             let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
index 9ffe3c9f25cedef6fcac6bd16e15288cf1166f62..1c967131b0ac778d4d09d519570bfb761598d32c 100644 (file)
@@ -27,7 +27,6 @@
 
 use middle::trans::type_::Type;
 
-use std::str;
 use syntax::ast;
 use syntax::ast::ident;
 use syntax::ast_map::path_mod;
@@ -251,9 +250,9 @@ pub fn trans_log(log_ex: &ast::expr,
             ccx, modpath, "loglevel");
         let global;
         unsafe {
-            global = str::as_c_str(s, |buf| {
+            global = do s.as_c_str |buf| {
                 llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
-            });
+            };
             llvm::LLVMSetGlobalConstant(global, False);
             llvm::LLVMSetInitializer(global, C_null(Type::i32()));
             lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
index 7518d4eb8247446c447732a10aeb3f64198abd30..4249e47d1478521a9338ab24083ba4db0019f3ac 100644 (file)
@@ -65,7 +65,6 @@
 use std::hashmap::HashMap;
 use std::libc::{c_uint, c_ulonglong, c_longlong};
 use std::ptr;
-use std::str::as_c_str;
 use std::vec;
 use syntax::codemap::span;
 use syntax::{ast, codemap, ast_util, ast_map};
@@ -159,7 +158,7 @@ pub fn create_local_var_metadata(bcx: block, local: @ast::Local) -> DIVariable {
         Some(_) => lexical_block_metadata(bcx)
     };
 
-    let var_metadata = do as_c_str(name) |name| {
+    let var_metadata = do name.as_c_str |name| {
         unsafe {
             llvm::LLVMDIBuilderCreateLocalVariable(
                 DIB(cx),
@@ -225,7 +224,7 @@ pub fn create_argument_metadata(bcx: block, arg: &ast::arg, span: span) -> Optio
             // XXX: This is wrong; it should work for multiple bindings.
             let ident = path.idents.last();
             let name: &str = cx.sess.str_of(*ident);
-            let var_metadata = do as_c_str(name) |name| {
+            let var_metadata = do name.as_c_str |name| {
                 unsafe {
                     llvm::LLVMDIBuilderCreateLocalVariable(
                         DIB(cx),
@@ -354,8 +353,8 @@ pub fn create_function_metadata(fcx: fn_ctxt) -> DISubprogram {
     };
 
     let fn_metadata =
-        do as_c_str(cx.sess.str_of(ident)) |name| {
-        do as_c_str(cx.sess.str_of(ident)) |linkage| {
+        do cx.sess.str_of(ident).as_c_str |name| {
+        do cx.sess.str_of(ident).as_c_str |linkage| {
             unsafe {
                 llvm::LLVMDIBuilderCreateFunction(
                     DIB(cx),
@@ -402,11 +401,11 @@ fn compile_unit_metadata(cx: @mut CrateContext) {
     let work_dir = cx.sess.working_dir.to_str();
     let producer = fmt!("rustc version %s", env!("CFG_VERSION"));
 
-    do as_c_str(crate_name) |crate_name| {
-    do as_c_str(work_dir) |work_dir| {
-    do as_c_str(producer) |producer| {
-    do as_c_str("") |flags| {
-    do as_c_str("") |split_name| {
+    do crate_name.as_c_str |crate_name| {
+    do work_dir.as_c_str |work_dir| {
+    do producer.as_c_str |producer| {
+    do "".as_c_str |flags| {
+    do "".as_c_str |split_name| {
         unsafe {
             llvm::LLVMDIBuilderCreateCompileUnit(dcx.builder,
                 DW_LANG_RUST as c_uint, crate_name, work_dir, producer,
@@ -433,8 +432,8 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile {
         };
 
     let file_metadata =
-        do as_c_str(file_name) |file_name| {
-        do as_c_str(work_dir) |work_dir| {
+        do file_name.as_c_str |file_name| {
+        do work_dir.as_c_str |work_dir| {
             unsafe {
                 llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name, work_dir)
             }
@@ -522,7 +521,7 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
 
     let llvm_type = type_of::type_of(cx, t);
     let (size, align) = size_and_align_of(cx, llvm_type);
-    let ty_metadata = do as_c_str(name) |name| {
+    let ty_metadata = do name.as_c_str |name| {
         unsafe {
             llvm::LLVMDIBuilderCreateBasicType(
                 DIB(cx),
@@ -543,7 +542,7 @@ fn pointer_type_metadata(cx: &mut CrateContext,
     let pointer_llvm_type = type_of::type_of(cx, pointer_type);
     let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
     let name = ty_to_str(cx.tcx, pointer_type);
-    let ptr_metadata = do as_c_str(name) |name| {
+    let ptr_metadata = do name.as_c_str |name| {
         unsafe {
             llvm::LLVMDIBuilderCreatePointerType(
                 DIB(cx),
@@ -1038,7 +1037,7 @@ fn unimplemented_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
     debug!("unimplemented_type_metadata: %?", ty::get(t));
 
     let name = ty_to_str(cx.tcx, t);
-    let metadata = do as_c_str(fmt!("NYI<%s>", name)) |name| {
+    let metadata = do fmt!("NYI<%s>", name).as_c_str |name| {
         unsafe {
             llvm::LLVMDIBuilderCreateBasicType(
                 DIB(cx),
index d3f5b9844c930f6c1607c2637a976e063ad973da..d66b43167cec110d194b587c50625fd2e51c01e8 100644 (file)
@@ -39,7 +39,6 @@
 
 use std::io;
 use std::libc::c_uint;
-use std::str;
 use syntax::ast;
 
 pub fn trans_free(cx: block, v: ValueRef) -> block {
@@ -658,11 +657,11 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
     let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
     note_unique_llvm_symbol(ccx, name);
     debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
-    let gvar = str::as_c_str(name, |buf| {
+    let gvar = do name.as_c_str |buf| {
         unsafe {
             llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
         }
-    });
+    };
     let inf = @mut tydesc_info {
         ty: t,
         tydesc: gvar,
index 349c41b13a98c6de8952a0122556001290d8a587..dddf494856e9a01f2eeb3fe02c0b69f903354d59 100644 (file)
@@ -382,8 +382,8 @@ pub fn link_exe(_src: &Path, _dest: &Path) -> bool {
 pub fn link_exe(src: &Path, dest: &Path) -> bool {
     use std::{libc, str};
     unsafe {
-        do str::as_c_str(src.to_str()) |src_buf| {
-            do str::as_c_str(dest.to_str()) |dest_buf| {
+        do src.to_str().as_c_str |src_buf| {
+            do dest.to_str().as_c_str |dest_buf| {
                 libc::link(src_buf, dest_buf) == 0 as libc::c_int &&
                     libc::chmod(dest_buf, 755) == 0 as libc::c_int
             }
index 6335588db503c8eebce57e0ccf5bb860292b933e..fed4eb26dbed1636927f22ce191596829e059ae9 100644 (file)
@@ -63,7 +63,7 @@
 use ptr;
 use result;
 use str;
-use str::{StrSlice, OwnedStr, StrUtil};
+use str::{StrSlice, OwnedStr};
 use to_str::ToStr;
 use uint;
 use vec;
index 2c3ce86ef78c448c1649a8c9186b15fc7a004edc..8c118d0be763f76b72f9f22fd2d030d201361af3 100644 (file)
@@ -243,12 +243,11 @@ fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] {
 pub fn getenv(n: &str) -> Option<~str> {
     unsafe {
         do with_env_lock {
-            let s = str::as_c_str(n, |s| libc::getenv(s));
+            let s = n.as_c_str(|s| libc::getenv(s as *libc::c_char));
             if ptr::null::<u8>() == cast::transmute(s) {
-                None::<~str>
+                None
             } else {
-                let s = cast::transmute(s);
-                Some::<~str>(str::raw::from_buf(s))
+                Some(str::raw::from_buf(cast::transmute(s)))
             }
         }
     }
@@ -277,8 +276,8 @@ pub fn getenv(n: &str) -> Option<~str> {
 pub fn setenv(n: &str, v: &str) {
     unsafe {
         do with_env_lock {
-            do str::as_c_str(n) |nbuf| {
-                do str::as_c_str(v) |vbuf| {
+            do n.to_str().as_c_str |nbuf| {
+                do v.to_str().as_c_str |vbuf| {
                     libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1);
                 }
             }
@@ -309,7 +308,7 @@ pub fn unsetenv(n: &str) {
     fn _unsetenv(n: &str) {
         unsafe {
             do with_env_lock {
-                do str::as_c_str(n) |nbuf| {
+                do n.to_str().as_c_str |nbuf| {
                     libc::funcs::posix01::unistd::unsetenv(nbuf);
                 }
             }
@@ -465,7 +464,7 @@ fn load_self() -> Option<~str> {
             use libc::funcs::posix01::unistd::readlink;
 
             let mut path_str = str::with_capacity(TMPBUF_SZ);
-            let len = do str::as_c_str(path_str) |buf| {
+            let len = do path_str.as_c_str |buf| {
                 let buf = buf as *mut c_char;
                 do "/proc/self/exe".as_c_str |proc_self_buf| {
                     readlink(proc_self_buf, buf, TMPBUF_SZ as size_t)
@@ -598,7 +597,7 @@ pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool {
 /// Indicates whether a path represents a directory
 pub fn path_is_dir(p: &Path) -> bool {
     unsafe {
-        do str::as_c_str(p.to_str()) |buf| {
+        do p.to_str().as_c_str |buf| {
             rustrt::rust_path_is_dir(buf) != 0 as c_int
         }
     }
@@ -607,7 +606,7 @@ pub fn path_is_dir(p: &Path) -> bool {
 /// Indicates whether a path exists
 pub fn path_exists(p: &Path) -> bool {
     unsafe {
-        do str::as_c_str(p.to_str()) |buf| {
+        do p.to_str().as_c_str |buf| {
             rustrt::rust_path_exists(buf) != 0 as c_int
         }
     }
@@ -924,7 +923,7 @@ fn do_copy_file(from: &Path, to: &Path) -> bool {
             fclose(ostream);
 
             // Give the new file the old file's permissions
-            if do str::as_c_str(to.to_str()) |to_buf| {
+            if do to.to_str().as_c_str |to_buf| {
                 libc::chmod(to_buf, from_mode as libc::mode_t)
             } != 0 {
                 return false; // should be a condition...
@@ -1290,7 +1289,7 @@ fn default_glob_t () -> libc::glob_t {
     }
 
     let mut g = default_glob_t();
-    do str::as_c_str(pattern) |c_pattern| {
+    do pattern.as_c_str |c_pattern| {
         unsafe { libc::glob(c_pattern, 0, ptr::null(), &mut g) }
     };
     do(|| {
index 3ec3407b1cc55c2bd88261fafe945eb58eba5051..ef7a055b0e790652b0a61b59d5352564813fe743 100644 (file)
@@ -23,7 +23,6 @@
 use libc;
 use option::{None, Option, Some};
 use str::{OwnedStr, Str, StrSlice, StrVector};
-use str;
 use to_str::ToStr;
 use ascii::{AsciiCast, AsciiStr};
 use vec::{OwnedVector, ImmutableVector};
@@ -342,13 +341,11 @@ pub fn default_stat() -> libc::stat {
 #[cfg(target_os = "win32")]
 impl WindowsPath {
     pub fn stat(&self) -> Option<libc::stat> {
-        unsafe {
-             do str::as_c_str(self.to_str()) |buf| {
-                let mut st = stat::arch::default_stat();
-                match libc::stat(buf, &mut st) {
-                    0 => Some(st),
-                    _ => None,
-                }
+        do self.to_str().as_c_str |buf| {
+            let mut st = stat::arch::default_stat();
+            match unsafe { libc::stat(buf, &mut st) } {
+                0 => Some(st),
+                _ => None,
             }
         }
     }
@@ -378,13 +375,11 @@ pub fn get_mode(&self) -> Option<uint> {
 #[cfg(not(target_os = "win32"))]
 impl PosixPath {
     pub fn stat(&self) -> Option<libc::stat> {
-        unsafe {
-             do str::as_c_str(self.to_str()) |buf| {
-                let mut st = stat::arch::default_stat();
-                match libc::stat(buf, &mut st) {
-                    0 => Some(st),
-                    _ => None,
-                }
+        do self.to_str().as_c_str |buf| {
+            let mut st = stat::arch::default_stat();
+            match unsafe { libc::stat(buf as *libc::c_char, &mut st) } {
+                0 => Some(st),
+                _ => None,
             }
         }
     }
@@ -458,13 +453,11 @@ pub fn get_ctime(&self) -> Option<(i64, int)> {
 #[cfg(unix)]
 impl PosixPath {
     pub fn lstat(&self) -> Option<libc::stat> {
-        unsafe {
-            do str::as_c_str(self.to_str()) |buf| {
-                let mut st = stat::arch::default_stat();
-                match libc::lstat(buf, &mut st) {
-                    0 => Some(st),
-                    _ => None,
-                }
+        do self.to_str().as_c_str |buf| {
+            let mut st = stat::arch::default_stat();
+            match unsafe { libc::lstat(buf, &mut st) } {
+                0 => Some(st),
+                _ => None,
             }
         }
     }
index e3e042a4947240033faab4367a948f422b743948..0d9446bcfca7d476d669bab39fea7fb3b4bd731e 100644 (file)
@@ -62,7 +62,7 @@
 pub use path::WindowsPath;
 pub use ptr::RawPtr;
 pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
-pub use str::{Str, StrVector, StrSlice, OwnedStr, StrUtil, NullTerminatedStr};
+pub use str::{Str, StrVector, StrSlice, OwnedStr, NullTerminatedStr};
 pub use from_str::{FromStr};
 pub use to_bytes::IterBytes;
 pub use to_str::{ToStr, ToStrConsume};
index c2b59d51347869b3e7fbcf038f4569c6159e1ab7..29564bd9728d7b8ee2641c444848824ffb50f33a 100644 (file)
@@ -461,17 +461,13 @@ struct Pair {
 
     #[test]
     fn test_position() {
-        use str::as_c_str;
         use libc::c_char;
 
         let s = ~"hello";
         unsafe {
-            assert!(2u == as_c_str(s, |p| position(p,
-                                                   |c| *c == 'l' as c_char)));
-            assert!(4u == as_c_str(s, |p| position(p,
-                                                   |c| *c == 'o' as c_char)));
-            assert!(5u == as_c_str(s, |p| position(p,
-                                                   |c| *c == 0 as c_char)));
+            assert!(2u == s.as_c_str(|p| position(p, |c| *c == 'l' as c_char)));
+            assert!(4u == s.as_c_str(|p| position(p, |c| *c == 'o' as c_char)));
+            assert!(5u == s.as_c_str(|p| position(p, |c| *c == 0 as c_char)));
         }
     }
 
@@ -480,9 +476,9 @@ fn test_buf_len() {
         let s0 = ~"hello";
         let s1 = ~"there";
         let s2 = ~"thing";
-        do str::as_c_str(s0) |p0| {
-            do str::as_c_str(s1) |p1| {
-                do str::as_c_str(s2) |p2| {
+        do s0.as_c_str |p0| {
+            do s1.as_c_str |p1| {
+                do s2.as_c_str |p2| {
                     let v = ~[p0, p1, p2, null()];
                     do v.as_imm_buf |vp, len| {
                         assert_eq!(unsafe { buf_len(vp) }, 3u);
index 84186180aa6500d8dcb4ac6d30b06c4d3b07be95..11d11daebc254be912a0b2a25048db789b12874a 100644 (file)
@@ -46,17 +46,15 @@ fn log(&mut self, msg: Either<~str, &'static str>) {
 /// per-module global logging flags based on the logging spec
 pub fn init(crate_map: *u8) {
     use os;
-    use str;
+    use str::StrSlice;
     use ptr;
     use option::{Some, None};
 
     let log_spec = os::getenv("RUST_LOG");
     match log_spec {
         Some(spec) => {
-            do str::as_c_str(spec) |s| {
-                unsafe {
-                    rust_update_log_settings(crate_map, s);
-                }
+            do spec.as_c_str |buf| {
+                unsafe { rust_update_log_settings(crate_map, buf) }
             }
         }
         None => {
index 62bf8f27af93de00b3f4838719a8096dd01598e9..1f27a5776842abb08fd096c5ea42ca78770fe8f6 100644 (file)
@@ -382,12 +382,12 @@ pub unsafe fn as_sockaddr_in6(addr: *sockaddr) -> *sockaddr_in6 {
 }
 
 pub unsafe fn malloc_ip4_addr(ip: &str, port: int) -> *sockaddr_in {
-    do str::as_c_str(ip) |ip_buf| {
+    do ip.as_c_str |ip_buf| {
         rust_uv_ip4_addrp(ip_buf as *u8, port as libc::c_int)
     }
 }
 pub unsafe fn malloc_ip6_addr(ip: &str, port: int) -> *sockaddr_in6 {
-    do str::as_c_str(ip) |ip_buf| {
+    do ip.as_c_str |ip_buf| {
         rust_uv_ip6_addrp(ip_buf as *u8, port as libc::c_int)
     }
 }
index c0b46ba273d29dfd12005d67ec3661863445b71b..d8fc68d64225019f7117419761272a3ac83d7d09 100644 (file)
@@ -507,7 +507,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
 
         do with_envp(env) |envp| {
             do with_dirp(dir) |dirp| {
-                do str::as_c_str(cmd) |cmdp| {
+                do cmd.as_c_str |cmdp| {
                     let created = CreateProcessA(ptr::null(), cast::transmute(cmdp),
                                                  ptr::mut_null(), ptr::mut_null(), TRUE,
                                                  0, envp, dirp, &mut si, &mut pi);
@@ -696,12 +696,12 @@ mod rustrt {
 #[cfg(unix)]
 fn with_argv<T>(prog: &str, args: &[~str],
                 cb: &fn(**libc::c_char) -> T) -> T {
-    let mut argptrs = ~[str::as_c_str(prog, |b| b)];
+    let mut argptrs = ~[prog.as_c_str(|b| b)];
     let mut tmps = ~[];
     for args.iter().advance |arg| {
         let t = @(*arg).clone();
         tmps.push(t);
-        argptrs.push(str::as_c_str(*t, |b| b));
+        argptrs.push(t.as_c_str(|b| b));
     }
     argptrs.push(ptr::null());
     argptrs.as_imm_buf(|buf, _len| cb(buf))
@@ -723,7 +723,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
                 &(ref k, ref v) => {
                     let kv = @fmt!("%s=%s", *k, *v);
                     tmps.push(kv);
-                    ptrs.push(str::as_c_str(*kv, |b| b));
+                    ptrs.push(kv.as_c_str(|b| b));
                 }
             }
         }
@@ -761,7 +761,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
 fn with_dirp<T>(d: Option<&Path>,
                 cb: &fn(*libc::c_char) -> T) -> T {
     match d {
-      Some(dir) => str::as_c_str(dir.to_str(), cb),
+      Some(dir) => dir.to_str().as_c_str(cb),
       None => cb(ptr::null())
     }
 }
index c16e87000f5152d588e7fb38446f6b7a6b25189a..ab3d362ba792a5d7f5cc79da6bec5dfc7c51e599 100644 (file)
@@ -773,51 +773,6 @@ pub struct CharRange {
 static MAX_THREE_B: uint = 65536u;
 static TAG_FOUR_B: uint = 240u;
 
-/**
- * A dummy trait to hold all the utility methods that we implement on strings.
- */
-pub trait StrUtil {
-    /**
-     * Work with the byte buffer of a string as a null-terminated C string.
-     *
-     * Allows for unsafe manipulation of strings, which is useful for foreign
-     * interop. This is similar to `str::as_buf`, but guarantees null-termination.
-     * If the given slice is not already null-terminated, this function will
-     * allocate a temporary, copy the slice, null terminate it, and pass
-     * that instead.
-     *
-     * # Example
-     *
-     * ~~~ {.rust}
-     * let s = "PATH".as_c_str(|path| libc::getenv(path));
-     * ~~~
-     */
-    fn as_c_str<T>(self, f: &fn(*libc::c_char) -> T) -> T;
-}
-
-impl<'self> StrUtil for &'self str {
-    #[inline]
-    fn as_c_str<T>(self, f: &fn(*libc::c_char) -> T) -> T {
-        do self.as_buf |buf, len| {
-            // NB: len includes the trailing null.
-            assert!(len > 0);
-            if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
-                to_owned(self).as_c_str(|s| f(s))
-            } else {
-                f(buf as *libc::c_char)
-            }
-        }
-    }
-}
-
-/**
- * Deprecated. Use the `as_c_str` method on strings instead.
- */
-#[inline]
-pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
-    s.as_c_str(f)
-}
-
 /// Unsafe operations
 pub mod raw {
     use cast;
@@ -1271,6 +1226,7 @@ fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_
     fn subslice_offset(&self, inner: &str) -> uint;
 
     fn as_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
+    fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T;
 }
 
 /// Extension methods for strings
@@ -2027,6 +1983,34 @@ fn as_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
             f(buf, len)
         }
     }
+
+    /**
+     * Work with the byte buffer of a string as a null-terminated C string.
+     *
+     * Allows for unsafe manipulation of strings, which is useful for foreign
+     * interop. This is similar to `str::as_buf`, but guarantees null-termination.
+     * If the given slice is not already null-terminated, this function will
+     * allocate a temporary, copy the slice, null terminate it, and pass
+     * that instead.
+     *
+     * # Example
+     *
+     * ~~~ {.rust}
+     * let s = "PATH".as_c_str(|path| libc::getenv(path));
+     * ~~~
+     */
+    #[inline]
+    fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
+        do self.as_buf |buf, len| {
+            // NB: len includes the trailing null.
+            assert!(len > 0);
+            if unsafe { *(ptr::offset(buf, len - 1)) != 0 } {
+                self.to_owned().as_c_str(|s| f(s))
+            } else {
+                f(buf as *libc::c_char)
+            }
+        }
+    }
 }
 
 #[allow(missing_doc)]