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/parse/token.rs | |
| 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/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index ff1509fe23a..baade21d942 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -23,6 +23,7 @@ use std::fmt; use std::local_data; use std::path::BytesContainer; use std::rc::Rc; +use std::strbuf::StrBuf; #[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, Eq, TotalEq, Hash, Show)] @@ -193,12 +194,12 @@ pub fn to_str(t: &Token) -> ~str { /* Literals */ LIT_CHAR(c) => { - let mut res = ~"'"; + let mut res = StrBuf::from_str("'"); char::from_u32(c).unwrap().escape_default(|c| { res.push_char(c); }); res.push_char('\''); - res + res.into_owned() } LIT_INT(i, t) => { i.to_str() + ast_util::int_ty_to_str(t) @@ -208,18 +209,19 @@ pub fn to_str(t: &Token) -> ~str { } LIT_INT_UNSUFFIXED(i) => { i.to_str() } LIT_FLOAT(s, t) => { - let mut body = get_ident(s).get().to_str(); - if body.ends_with(".") { + let mut body = StrBuf::from_str(get_ident(s).get()); + if body.as_slice().ends_with(".") { body.push_char('0'); // `10.f` is not a float literal } - body + ast_util::float_ty_to_str(t) + body.push_str(ast_util::float_ty_to_str(t)); + body.into_owned() } LIT_FLOAT_UNSUFFIXED(s) => { - let mut body = get_ident(s).get().to_str(); - if body.ends_with(".") { + let mut body = StrBuf::from_str(get_ident(s).get()); + if body.as_slice().ends_with(".") { body.push_char('0'); // `10.f` is not a float literal } - body + body.into_owned() } LIT_STR(s) => { format!("\"{}\"", get_ident(s).get().escape_default()) |
