diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-04-02 16:54:22 -0700 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-10 22:10:10 +1000 |
| commit | d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260 (patch) | |
| tree | 3ff220512aeae37710c8b1c783e1229e685bfce3 /src/libsyntax/ext | |
| parent | 7fbcb400f0697621ece9f9773b0f0bf1ec73e9c1 (diff) | |
| download | rust-d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260.tar.gz rust-d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260.zip | |
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and
port all code over to use it.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/concat.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/show.rs | 6 |
3 files changed, 14 insertions, 9 deletions
diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index e638291ecfa..1db65e3b9e4 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::char; - use ast; use codemap; use ext::base; use ext::build::AstBuilder; use parse::token; +use std::char; +use std::strbuf::StrBuf; + pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) -> base::MacResult { @@ -23,7 +24,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, Some(e) => e, None => return base::MacResult::dummy_expr(sp) }; - let mut accumulator = ~""; + let mut accumulator = StrBuf::new(); for e in es.move_iter() { match e.node { ast::ExprLit(lit) => { @@ -56,5 +57,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, } } } - base::MRExpr(cx.expr_str(sp, token::intern_and_get_ident(accumulator))) + base::MRExpr(cx.expr_str( + sp, + token::intern_and_get_ident(accumulator.into_owned()))) } diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 8441fa719ea..a5faa693982 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,9 +16,11 @@ use owned_slice::OwnedSlice; use parse::token; use parse::token::{str_to_ident}; +use std::strbuf::StrBuf; + pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { - let mut res_str = ~""; + let mut res_str = StrBuf::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { match *e { @@ -40,7 +42,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } } - let res = str_to_ident(res_str); + let res = str_to_ident(res_str.into_owned()); let e = @ast::Expr { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 1c80fb9ced2..067958e4bde 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -15,10 +15,10 @@ use ext::format; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; - use parse::token; use collections::HashMap; +use std::strbuf::StrBuf; pub fn expand_deriving_show(cx: &mut ExtCtxt, span: Span, @@ -68,7 +68,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, } }; - let mut format_string = token::get_ident(name).get().to_owned(); + let mut format_string = StrBuf::from_str(token::get_ident(name).get()); // the internal fields we're actually formatting let mut exprs = Vec::new(); @@ -129,7 +129,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, let write_call = cx.expr_call_global(span, std_write, vec!(buf, cx.expr_ident(span, args))); let format_closure = cx.lambda_expr(span, vec!(args), write_call); - let s = token::intern_and_get_ident(format_string); + let s = token::intern_and_get_ident(format_string.as_slice()); let format_string = cx.expr_str(span, s); // phew, not our responsibility any more! |
