diff options
| author | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
| commit | cea8def62068b405495ecd1810124ebc88b4f90b (patch) | |
| tree | 65d5755bd532a9213799c52572db6d6683d5e942 /src/libsyntax/print | |
| parent | 0156af156d70efd5a3c96d0c5b8fc9bec39a7ae5 (diff) | |
| parent | def90f43e2df9968cda730a2a30cb7ccb9513002 (diff) | |
| download | rust-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/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pp.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 9 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 7b64d0293cc..6cd72cb58f1 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -62,6 +62,7 @@ */ use std::io; +use std::strbuf::StrBuf; #[deriving(Clone, Eq)] pub enum Breaks { @@ -118,13 +119,17 @@ pub fn tok_str(t: Token) -> ~str { } } -pub fn buf_str(toks: Vec<Token> , szs: Vec<int> , left: uint, right: uint, - lim: uint) -> ~str { +pub fn buf_str(toks: Vec<Token>, + szs: Vec<int>, + left: uint, + right: uint, + lim: uint) + -> ~str { let n = toks.len(); assert_eq!(n, szs.len()); let mut i = left; let mut l = lim; - let mut s = ~"["; + let mut s = StrBuf::from_str("["); while i != right && l != 0u { l -= 1u; if i != left { @@ -135,7 +140,7 @@ pub fn buf_str(toks: Vec<Token> , szs: Vec<int> , left: uint, right: uint, i %= n; } s.push_char(']'); - return s; + return s.into_owned(); } pub enum PrintStackBreak { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b33f76a6047..3e2509f4f6e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -27,10 +27,11 @@ use print::pp; use std::cast; use std::char; -use std::str; -use std::io; use std::io::{IoResult, MemWriter}; +use std::io; use std::rc::Rc; +use std::str; +use std::strbuf::StrBuf; pub enum AnnNode<'a> { NodeBlock(&'a ast::Block), @@ -2156,10 +2157,10 @@ impl<'a> State<'a> { match lit.node { ast::LitStr(ref st, style) => self.print_string(st.get(), style), ast::LitChar(ch) => { - let mut res = ~"'"; + let mut res = StrBuf::from_str("'"); char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); res.push_char('\''); - word(&mut self.s, res) + word(&mut self.s, res.into_owned()) } ast::LitInt(i, t) => { word(&mut self.s, format!("{}{}", i, ast_util::int_ty_to_str(t))) |
