diff options
| author | Richo Healey <richo@psych0tik.net> | 2014-05-22 16:57:53 -0700 |
|---|---|---|
| committer | Richo Healey <richo@psych0tik.net> | 2014-05-24 21:48:10 -0700 |
| commit | 553074506ecd139eb961fb91eb33ad9fd0183acb (patch) | |
| tree | 01682cf8147183250713acf5e8a77265aab7153c /src/libserialize | |
| parent | bbb70cdd9cd982922cf7390459d53bde409699ae (diff) | |
| download | rust-553074506ecd139eb961fb91eb33ad9fd0183acb.tar.gz rust-553074506ecd139eb961fb91eb33ad9fd0183acb.zip | |
core: rename strbuf::StrBuf to string::String
[breaking-change]
Diffstat (limited to 'src/libserialize')
| -rw-r--r-- | src/libserialize/base64.rs | 8 | ||||
| -rw-r--r-- | src/libserialize/ebml.rs | 6 | ||||
| -rw-r--r-- | src/libserialize/hex.rs | 8 | ||||
| -rw-r--r-- | src/libserialize/json.rs | 96 | ||||
| -rw-r--r-- | src/libserialize/serialize.rs | 10 |
5 files changed, 64 insertions, 64 deletions
diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 2d938bc9ae7..61ba36eeb1f 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -54,7 +54,7 @@ static URLSAFE_CHARS: &'static[u8] = bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ", pub trait ToBase64 { /// Converts the value of `self` to a base64 value following the specified /// format configuration, returning the owned string. - fn to_base64(&self, config: Config) -> StrBuf; + fn to_base64(&self, config: Config) -> String; } impl<'a> ToBase64 for &'a [u8] { @@ -73,7 +73,7 @@ impl<'a> ToBase64 for &'a [u8] { * } * ``` */ - fn to_base64(&self, config: Config) -> StrBuf { + fn to_base64(&self, config: Config) -> String { let bytes = match config.char_set { Standard => STANDARD_CHARS, UrlSafe => URLSAFE_CHARS @@ -181,7 +181,7 @@ impl<'a> FromBase64 for &'a str { * Convert any base64 encoded string (literal, `@`, `&`, or `~`) * to the byte values it encodes. * - * You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a + * You can use the `String::from_utf8` function in `std::string` to turn a * `Vec<u8>` into a string with characters corresponding to those values. * * # Example @@ -197,7 +197,7 @@ impl<'a> FromBase64 for &'a str { * println!("base64 output: {}", hello_str); * let res = hello_str.as_slice().from_base64(); * if res.is_ok() { - * let opt_bytes = StrBuf::from_utf8(res.unwrap()); + * let opt_bytes = String::from_utf8(res.unwrap()); * if opt_bytes.is_ok() { * println!("decoded from base64: {}", opt_bytes.unwrap()); * } diff --git a/src/libserialize/ebml.rs b/src/libserialize/ebml.rs index 3a387972ff7..403705017d5 100644 --- a/src/libserialize/ebml.rs +++ b/src/libserialize/ebml.rs @@ -34,7 +34,7 @@ impl<'doc> Doc<'doc> { str::from_utf8(self.data.slice(self.start, self.end)).unwrap() } - pub fn as_str(&self) -> StrBuf { + pub fn as_str(&self) -> String { self.as_str_slice().to_strbuf() } } @@ -80,7 +80,7 @@ pub enum EbmlEncoderTag { #[deriving(Show)] pub enum Error { IntTooBig(uint), - Expected(StrBuf), + Expected(String), IoError(io::IoError) } // -------------------------------------- @@ -443,7 +443,7 @@ pub mod reader { fn read_char(&mut self) -> DecodeResult<char> { Ok(char::from_u32(doc_as_u32(try!(self.next_doc(EsChar)))).unwrap()) } - fn read_str(&mut self) -> DecodeResult<StrBuf> { + fn read_str(&mut self) -> DecodeResult<String> { Ok(try!(self.next_doc(EsStr)).as_str()) } diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 82ab5fd5b04..e1cc8f5f2dc 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -16,7 +16,7 @@ use std::fmt; pub trait ToHex { /// Converts the value of `self` to a hex value, returning the owned /// string. - fn to_hex(&self) -> StrBuf; + fn to_hex(&self) -> String; } static CHARS: &'static[u8] = bytes!("0123456789abcdef"); @@ -37,7 +37,7 @@ impl<'a> ToHex for &'a [u8] { * } * ``` */ - fn to_hex(&self) -> StrBuf { + fn to_hex(&self) -> String { let mut v = Vec::with_capacity(self.len() * 2); for &byte in self.iter() { v.push(CHARS[(byte >> 4) as uint]); @@ -80,7 +80,7 @@ impl<'a> FromHex for &'a str { * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`) * to the byte values it encodes. * - * You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a + * You can use the `String::from_utf8` function in `std::string` to turn a * `Vec<u8>` into a string with characters corresponding to those values. * * # Example @@ -96,7 +96,7 @@ impl<'a> FromHex for &'a str { * println!("{}", hello_str); * let bytes = hello_str.as_slice().from_hex().unwrap(); * println!("{:?}", bytes); - * let result_str = StrBuf::from_utf8(bytes).unwrap(); + * let result_str = String::from_utf8(bytes).unwrap(); * println!("{}", result_str); * } * ``` diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 92e3d5a2688..cf05bf5b641 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -64,7 +64,7 @@ use serialize::{json, Encodable}; #[deriving(Encodable)] pub struct TestStruct { - data_str: StrBuf, + data_str: String, } fn main() { @@ -81,12 +81,12 @@ fn main() { ``` Two wrapper functions are provided to encode a Encodable object -into a string (StrBuf) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`. +into a string (String) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`. ```rust use serialize::json; let to_encode_object = "example of string to encode".to_strbuf(); -let encoded_str: StrBuf = json::Encoder::str_encode(&to_encode_object); +let encoded_str: String = json::Encoder::str_encode(&to_encode_object); ``` JSON API provide an enum `json::Json` and a trait `ToJson` to encode object. @@ -108,7 +108,7 @@ use collections::TreeMap; pub struct MyStruct { attr1: u8, - attr2: StrBuf, + attr2: String, } impl ToJson for MyStruct { @@ -123,7 +123,7 @@ impl ToJson for MyStruct { fn main() { let test2: MyStruct = MyStruct {attr1: 1, attr2:"test".to_strbuf()}; let tjson: json::Json = test2.to_json(); - let json_str: StrBuf = tjson.to_str().into_strbuf(); + let json_str: String = tjson.to_str().into_strbuf(); } ``` @@ -136,11 +136,11 @@ use serialize::{json, Decodable}; #[deriving(Decodable)] pub struct MyStruct { attr1: u8, - attr2: StrBuf, + attr2: String, } fn main() { - let json_str_to_decode: StrBuf = + let json_str_to_decode: String = "{\"attr1\":1,\"attr2\":\"toto\"}".to_strbuf(); let json_object = json::from_str(json_str_to_decode.as_slice()); let mut decoder = json::Decoder::new(json_object.unwrap()); @@ -165,7 +165,7 @@ use serialize::{json, Encodable, Decodable}; #[deriving(Decodable, Encodable)] //generate Decodable, Encodable impl. pub struct TestStruct1 { data_int: u8, - data_str: StrBuf, + data_str: String, data_vector: Vec<u8>, } @@ -174,7 +174,7 @@ use serialize::{json, Encodable, Decodable}; fn main() { let to_encode_object = TestStruct1 {data_int: 1, data_str:"toto".to_strbuf(), data_vector:vec![2,3,4,5]}; - let encoded_str: StrBuf = json::Encoder::str_encode(&to_encode_object); + let encoded_str: String = json::Encoder::str_encode(&to_encode_object); // To deserialize use the `json::from_str` and `json::Decoder` @@ -200,7 +200,7 @@ use collections::TreeMap; #[deriving(Decodable, Encodable)] // generate Decodable, Encodable impl. pub struct TestStruct1 { data_int: u8, - data_str: StrBuf, + data_str: String, data_vector: Vec<u8>, } @@ -220,7 +220,7 @@ fn main() { let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:"toto".to_strbuf(), data_vector:vec![2,3,4,5]}; let tjson: json::Json = test2.to_json(); - let json_str: StrBuf = tjson.to_str().into_strbuf(); + let json_str: String = tjson.to_str().into_strbuf(); // Deserialize like before. @@ -242,7 +242,7 @@ use std::mem::swap; use std::num; use std::str::ScalarValue; use std::str; -use std::strbuf::StrBuf; +use std::string::String; use std::vec::Vec; use Encodable; @@ -252,7 +252,7 @@ use collections::{HashMap, TreeMap}; #[deriving(Clone, Eq)] pub enum Json { Number(f64), - String(StrBuf), + String(String), Boolean(bool), List(List), Object(Box<Object>), @@ -260,7 +260,7 @@ pub enum Json { } pub type List = Vec<Json>; -pub type Object = TreeMap<StrBuf, Json>; +pub type Object = TreeMap<String, Json>; /// The errors that can arise while parsing a JSON stream. #[deriving(Clone, Eq)] @@ -296,9 +296,9 @@ pub type BuilderError = ParserError; #[deriving(Clone, Eq, Show)] pub enum DecoderError { ParseError(ParserError), - ExpectedError(StrBuf, StrBuf), - MissingFieldError(StrBuf), - UnknownVariantError(StrBuf), + ExpectedError(String, String), + MissingFieldError(String), + UnknownVariantError(String), } /// Returns a readable error string for a given error code. @@ -337,8 +337,8 @@ fn io_error_to_error(io: io::IoError) -> ParserError { pub type EncodeResult = io::IoResult<()>; pub type DecodeResult<T> = Result<T, DecoderError>; -fn escape_str(s: &str) -> StrBuf { - let mut escaped = StrBuf::from_str("\""); +fn escape_str(s: &str) -> String { + let mut escaped = String::from_str("\""); for c in s.chars() { match c { '"' => escaped.push_str("\\\""), @@ -355,8 +355,8 @@ fn escape_str(s: &str) -> StrBuf { escaped } -fn spaces(n: uint) -> StrBuf { - let mut ss = StrBuf::new(); +fn spaces(n: uint) -> String { + let mut ss = String::new(); for _ in range(0, n) { ss.push_str(" "); } @@ -391,7 +391,7 @@ impl<'a> Encoder<'a> { pub fn str_encode<T:Encodable<Encoder<'a>, io::IoError>>( to_encode_object: &T) - -> StrBuf { + -> String { let buff = Encoder::buffer_encode(to_encode_object); str::from_utf8(buff.as_slice()).unwrap().to_strbuf() } @@ -836,7 +836,7 @@ impl Json { } /// Encodes a json value into a string - pub fn to_pretty_str(&self) -> StrBuf { + pub fn to_pretty_str(&self) -> String { let mut s = MemWriter::new(); self.to_pretty_writer(&mut s as &mut io::Writer).unwrap(); str::from_utf8(s.unwrap().as_slice()).unwrap().to_strbuf() @@ -844,7 +844,7 @@ impl Json { /// If the Json value is an Object, returns the value associated with the provided key. /// Otherwise, returns None. - pub fn find<'a>(&'a self, key: &StrBuf) -> Option<&'a Json>{ + pub fn find<'a>(&'a self, key: &String) -> Option<&'a Json>{ match self { &Object(ref map) => map.find(key), _ => None @@ -854,7 +854,7 @@ impl Json { /// Attempts to get a nested Json Object for each key in `keys`. /// If any key is found not to exist, find_path will return None. /// Otherwise, it will return the Json value associated with the final key. - pub fn find_path<'a>(&'a self, keys: &[&StrBuf]) -> Option<&'a Json>{ + pub fn find_path<'a>(&'a self, keys: &[&String]) -> Option<&'a Json>{ let mut target = self; for key in keys.iter() { match target.find(*key) { @@ -868,7 +868,7 @@ impl Json { /// If the Json value is an Object, performs a depth-first search until /// a value associated with the provided key is found. If no value is found /// or the Json value is not an Object, returns None. - pub fn search<'a>(&'a self, key: &StrBuf) -> Option<&'a Json> { + pub fn search<'a>(&'a self, key: &String) -> Option<&'a Json> { match self { &Object(ref map) => { match map.find(key) { @@ -983,7 +983,7 @@ pub enum JsonEvent { ListEnd, BooleanValue(bool), NumberValue(f64), - StringValue(StrBuf), + StringValue(String), NullValue, Error(ParserError), } @@ -1101,7 +1101,7 @@ impl Stack { } // Used by Parser to insert Key elements at the top of the stack. - fn push_key(&mut self, key: StrBuf) { + fn push_key(&mut self, key: String) { self.stack.push(InternalKey(self.str_buffer.len() as u16, key.len() as u16)); for c in key.as_bytes().iter() { self.str_buffer.push(*c); @@ -1388,9 +1388,9 @@ impl<T: Iterator<char>> Parser<T> { Ok(n) } - fn parse_str(&mut self) -> Result<StrBuf, ParserError> { + fn parse_str(&mut self) -> Result<String, ParserError> { let mut escape = false; - let mut res = StrBuf::new(); + let mut res = String::new(); loop { self.bump(); @@ -1748,7 +1748,7 @@ impl<T: Iterator<char>> Builder<T> { Some(NumberValue(n)) => { Ok(Number(n)) } Some(BooleanValue(b)) => { Ok(Boolean(b)) } Some(StringValue(ref mut s)) => { - let mut temp = StrBuf::new(); + let mut temp = String::new(); swap(s, &mut temp); Ok(String(temp)) } @@ -1920,7 +1920,7 @@ impl ::Decoder<DecoderError> for Decoder { format_strbuf!("{}", s))) } - fn read_str(&mut self) -> DecodeResult<StrBuf> { + fn read_str(&mut self) -> DecodeResult<String> { debug!("read_str"); Ok(try!(expect!(self.pop(), String))) } @@ -2233,7 +2233,7 @@ impl ToJson for bool { fn to_json(&self) -> Json { Boolean(*self) } } -impl ToJson for StrBuf { +impl ToJson for String { fn to_json(&self) -> Json { String((*self).clone()) } } @@ -2265,7 +2265,7 @@ impl<A:ToJson> ToJson for Vec<A> { fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) } } -impl<A:ToJson> ToJson for TreeMap<StrBuf, A> { +impl<A:ToJson> ToJson for TreeMap<String, A> { fn to_json(&self) -> Json { let mut d = TreeMap::new(); for (key, value) in self.iter() { @@ -2275,7 +2275,7 @@ impl<A:ToJson> ToJson for TreeMap<StrBuf, A> { } } -impl<A:ToJson> ToJson for HashMap<StrBuf, A> { +impl<A:ToJson> ToJson for HashMap<String, A> { fn to_json(&self) -> Json { let mut d = TreeMap::new(); for (key, value) in self.iter() { @@ -2321,14 +2321,14 @@ mod tests { #[deriving(Eq, Encodable, Decodable, Show)] enum Animal { Dog, - Frog(StrBuf, int) + Frog(String, int) } #[deriving(Eq, Encodable, Decodable, Show)] struct Inner { a: (), b: uint, - c: Vec<StrBuf>, + c: Vec<String>, } #[deriving(Eq, Encodable, Decodable, Show)] @@ -2336,7 +2336,7 @@ mod tests { inner: Vec<Inner>, } - fn mk_object(items: &[(StrBuf, Json)]) -> Json { + fn mk_object(items: &[(String, Json)]) -> Json { let mut d = box TreeMap::new(); for item in items.iter() { @@ -2488,7 +2488,7 @@ mod tests { from_str(a.to_pretty_str().as_slice()).unwrap()); } - fn with_str_writer(f: |&mut io::Writer|) -> StrBuf { + fn with_str_writer(f: |&mut io::Writer|) -> String { use std::io::MemWriter; use std::str; @@ -2556,7 +2556,7 @@ mod tests { #[test] fn test_write_none() { - let value: Option<StrBuf> = None; + let value: Option<String> = None; let s = with_str_writer(|wr| { let mut encoder = Encoder::new(wr); value.encode(&mut encoder).unwrap(); @@ -2694,11 +2694,11 @@ mod tests { for &(i, o) in s.iter() { let mut decoder = Decoder::new(from_str(i).unwrap()); - let v: StrBuf = Decodable::decode(&mut decoder).unwrap(); + let v: String = Decodable::decode(&mut decoder).unwrap(); assert_eq!(v.as_slice(), o); let mut decoder = Decoder::new(from_str(i).unwrap()); - let v: StrBuf = Decodable::decode(&mut decoder).unwrap(); + let v: String = Decodable::decode(&mut decoder).unwrap(); assert_eq!(v, o.to_strbuf()); } } @@ -2828,11 +2828,11 @@ mod tests { #[test] fn test_decode_option() { let mut decoder = Decoder::new(from_str("null").unwrap()); - let value: Option<StrBuf> = Decodable::decode(&mut decoder).unwrap(); + let value: Option<String> = Decodable::decode(&mut decoder).unwrap(); assert_eq!(value, None); let mut decoder = Decoder::new(from_str("\"jodhpurs\"").unwrap()); - let value: Option<StrBuf> = Decodable::decode(&mut decoder).unwrap(); + let value: Option<String> = Decodable::decode(&mut decoder).unwrap(); assert_eq!(value, Some("jodhpurs".to_strbuf())); } @@ -2853,7 +2853,7 @@ mod tests { let s = "{\"a\": \"Dog\", \"b\": {\"variant\":\"Frog\",\ \"fields\":[\"Henry\", 349]}}"; let mut decoder = Decoder::new(from_str(s).unwrap()); - let mut map: TreeMap<StrBuf, Animal> = Decodable::decode(&mut decoder).unwrap(); + let mut map: TreeMap<String, Animal> = Decodable::decode(&mut decoder).unwrap(); assert_eq!(map.pop(&"a".to_strbuf()), Some(Dog)); assert_eq!(map.pop(&"b".to_strbuf()), Some(Frog("Henry".to_strbuf(), 349))); @@ -2869,13 +2869,13 @@ mod tests { struct DecodeStruct { x: f64, y: bool, - z: StrBuf, + z: String, w: Vec<DecodeStruct> } #[deriving(Decodable)] enum DecodeEnum { A(f64), - B(StrBuf) + B(String) } fn check_err<T: Decodable<Decoder, DecoderError>>(to_parse: &'static str, expected: DecoderError) { @@ -3399,7 +3399,7 @@ mod tests { }); } - fn big_json() -> StrBuf { + fn big_json() -> String { let mut src = "[\n".to_strbuf(); for _ in range(0, 500) { src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \ diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 11acd8f30d9..9252ac55d24 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -108,7 +108,7 @@ pub trait Decoder<E> { fn read_f64(&mut self) -> Result<f64, E>; fn read_f32(&mut self) -> Result<f32, E>; fn read_char(&mut self) -> Result<char, E>; - fn read_str(&mut self) -> Result<StrBuf, E>; + fn read_str(&mut self) -> Result<String, E>; // Compound types: fn read_enum<T>(&mut self, name: &str, f: |&mut Self| -> Result<T, E>) -> Result<T, E>; @@ -297,15 +297,15 @@ impl<'a, E, S:Encoder<E>> Encodable<S, E> for &'a str { } } -impl<E, S:Encoder<E>> Encodable<S, E> for StrBuf { +impl<E, S:Encoder<E>> Encodable<S, E> for String { fn encode(&self, s: &mut S) -> Result<(), E> { s.emit_str(self.as_slice()) } } -impl<E, D:Decoder<E>> Decodable<D, E> for StrBuf { - fn decode(d: &mut D) -> Result<StrBuf, E> { - Ok(StrBuf::from_str(try!(d.read_str()).as_slice())) +impl<E, D:Decoder<E>> Decodable<D, E> for String { + fn decode(d: &mut D) -> Result<String, E> { + Ok(String::from_str(try!(d.read_str()).as_slice())) } } |
