about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-11 21:37:43 -0700
committerbors <bors@rust-lang.org>2013-06-11 21:37:43 -0700
commitcc80652e4a627378a36b50fab9e72349129cb56a (patch)
treeada1e23e714b7dc587d86aeddb54a954dded8f3a /src/libsyntax
parent7033dfcf917ccef44fbc3e33d31814455c13b4c6 (diff)
parent9f0c85acc967110c85f9a8bdcb32df4606a6dff5 (diff)
downloadrust-cc80652e4a627378a36b50fab9e72349129cb56a.tar.gz
rust-cc80652e4a627378a36b50fab9e72349129cb56a.zip
auto merge of #7060 : huonw/rust/more-str, r=thestinger
There are now only half-a-dozen or so functions left `std::str` that should be methods.

Highlights:
- `.substr` was removed, since most of the uses of it in the code base were actually incorrect (it had a weird mixing of a byte index and a unicode character count), adding `.slice_chars` if one wants to handle characters, and the normal `.slice` method to handle bytes.
- Code duplication between the two impls for `connect` and `concat` was removed via a new `Str` trait, that is purely designed to allow an explicit -> `&str` conversion (`.as_slice()`)
- Deconfuse the 5 different functions for converting to `[u8]` (3 of which had actually incorrect documentation: implying that they didn't have the null terminator), into 3: `as_bytes` (all strings), `as_bytes_with_null` (`&'static str`, `@str` and `~str`) and `as_bytes_with_null_consume` (`~str`). None of these allocate, unlike the old versions.

(cc @thestinger)
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr.rs2
-rw-r--r--src/libsyntax/ext/asm.rs4
-rw-r--r--src/libsyntax/ext/base.rs3
-rw-r--r--src/libsyntax/ext/log_syntax.rs3
-rw-r--r--src/libsyntax/ext/quote.rs8
-rw-r--r--src/libsyntax/ext/trace_macros.rs4
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs5
-rw-r--r--src/libsyntax/parse/token.rs2
-rw-r--r--src/libsyntax/print/pprust.rs3
9 files changed, 11 insertions, 23 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 51334772c84..da5874f7b05 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -259,7 +259,7 @@ pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: &str)
 
 pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] {
     // This is sort of stupid here, converting to a vec of mutables and back
-    let mut v = vec::to_owned(items);
+    let mut v = items.to_owned();
     do extra::sort::quick_sort(v) |ma, mb| {
         get_meta_item_name(*ma) <= get_meta_item_name(*mb)
     }
diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs
index d3efd07aa04..f9f9f7216a4 100644
--- a/src/libsyntax/ext/asm.rs
+++ b/src/libsyntax/ext/asm.rs
@@ -21,8 +21,6 @@ use ext::base::*;
 use parse;
 use parse::token;
 
-use core::vec;
-
 enum State {
     Asm,
     Outputs,
@@ -45,7 +43,7 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
                -> base::MacResult {
     let p = parse::new_parser_from_tts(cx.parse_sess(),
                                        cx.cfg(),
-                                       vec::to_owned(tts));
+                                       tts.to_owned());
 
     let mut asm = ~"";
     let mut outputs = ~[];
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index a3432a00edc..73f68735bcd 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -22,7 +22,6 @@ use parse::token;
 use parse::token::{ident_to_str, intern, str_to_ident};
 
 use core::hashmap::HashMap;
-use core::vec;
 
 // new-style macro! tt code:
 //
@@ -367,7 +366,7 @@ pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree])
                        -> ~[@ast::expr] {
     let p = parse::new_parser_from_tts(cx.parse_sess(),
                                        cx.cfg(),
-                                       vec::to_owned(tts));
+                                       tts.to_owned());
     let mut es = ~[];
     while *p.token != token::EOF {
         if es.len() != 0 {
diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs
index 3ad4f87083f..ff8b492c943 100644
--- a/src/libsyntax/ext/log_syntax.rs
+++ b/src/libsyntax/ext/log_syntax.rs
@@ -18,7 +18,6 @@ use print;
 use parse::token::{get_ident_interner};
 
 use core::io;
-use core::vec;
 
 pub fn expand_syntax_ext(cx: @ExtCtxt,
                          sp: codemap::span,
@@ -28,7 +27,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt,
     cx.print_backtrace();
     io::stdout().write_line(
         print::pprust::tt_to_str(
-            ast::tt_delim(vec::to_owned(tt)),
+            ast::tt_delim(tt.to_owned()),
             get_ident_interner()));
 
     //trivial expression
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index 2c6f40091ac..92727c73977 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -19,8 +19,6 @@ use parse::token::*;
 use parse::token;
 use parse;
 
-use core::vec;
-
 /**
 *
 * Quasiquoting works via token trees.
@@ -40,8 +38,6 @@ pub mod rt {
     use parse;
     use print::pprust;
 
-    use core::str;
-
     pub use ast::*;
     pub use parse::token::*;
     pub use parse::new_parser_from_tts;
@@ -128,7 +124,7 @@ pub mod rt {
 
     impl<'self> ToSource for &'self str {
         fn to_source(&self) -> ~str {
-            let lit = dummy_spanned(ast::lit_str(@str::to_owned(*self)));
+            let lit = dummy_spanned(ast::lit_str(@self.to_owned()));
             pprust::lit_to_str(@lit)
         }
     }
@@ -661,7 +657,7 @@ fn expand_tts(cx: @ExtCtxt,
     let p = parse::new_parser_from_tts(
         cx.parse_sess(),
         cx.cfg(),
-        vec::to_owned(tts)
+        tts.to_owned()
     );
     *p.quote_depth += 1u;
     let tts = p.parse_all_token_trees();
diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs
index 3baf432f24d..09b3fd23434 100644
--- a/src/libsyntax/ext/trace_macros.rs
+++ b/src/libsyntax/ext/trace_macros.rs
@@ -18,8 +18,6 @@ use parse::lexer::{new_tt_reader, reader};
 use parse::parser::Parser;
 use parse::token::keywords;
 
-use core::vec;
-
 pub fn expand_trace_macros(cx: @ExtCtxt,
                            sp: span,
                            tt: &[ast::token_tree])
@@ -29,7 +27,7 @@ pub fn expand_trace_macros(cx: @ExtCtxt,
     let tt_rdr = new_tt_reader(
         copy cx.parse_sess().span_diagnostic,
         None,
-        vec::to_owned(tt)
+        tt.to_owned()
     );
     let rdr = tt_rdr as @reader;
     let rust_parser = Parser(
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 1822117507d..7805e736467 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -26,7 +26,6 @@ use parse::token::{FAT_ARROW, SEMI, nt_matchers, nt_tt};
 use print;
 
 use core::io;
-use core::vec;
 
 pub fn add_new_extension(cx: @ExtCtxt,
                          sp: span,
@@ -84,7 +83,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
             io::println(fmt!("%s! { %s }",
                              cx.str_of(name),
                              print::pprust::tt_to_str(
-                                 ast::tt_delim(vec::to_owned(arg)),
+                                 ast::tt_delim(arg.to_owned()),
                                  get_ident_interner())));
         }
 
@@ -101,7 +100,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
                 let arg_rdr = new_tt_reader(
                     s_d,
                     None,
-                    vec::to_owned(arg)
+                    arg.to_owned()
                 ) as @reader;
                 match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) {
                   success(named_matches) => {
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 7359448a8f2..91605db77b5 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -193,7 +193,7 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
         }
         body
       }
-      LIT_STR(ref s) => { ~"\"" + str::escape_default(*ident_to_str(s)) + "\"" }
+      LIT_STR(ref s) => { ~"\"" + ident_to_str(s).escape_default() + "\"" }
 
       /* Name components */
       IDENT(s, _) => copy *in.get(s.name),
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index b6459fe30a3..ea33c04dbb5 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -31,7 +31,6 @@ use print::pprust;
 
 use core::char;
 use core::io;
-use core::str;
 use core::u64;
 use core::uint;
 use core::iterator::IteratorUtil;
@@ -2113,7 +2112,7 @@ pub fn print_comment(s: @ps, cmnt: &comments::cmnt) {
 
 pub fn print_string(s: @ps, st: &str) {
     word(s.s, "\"");
-    word(s.s, str::escape_default(st));
+    word(s.s, st.escape_default());
     word(s.s, "\"");
 }