Просмотр исходного кода

Upgrade to Rust 25951b2 2014-05-30

Simon Sapin 12 лет назад
Родитель
Сommit
c36aac6abd
5 измененных файлов с 100 добавлено и 95 удалено
  1. 6 6
      form_urlencoded.rs
  2. 31 31
      parser.rs
  3. 16 11
      punycode.rs
  4. 26 26
      tests.rs
  5. 21 21
      url.rs

+ 6 - 6
form_urlencoded.rs

@@ -21,13 +21,13 @@ use encoding::label::encoding_from_whatwg_label;
 use super::{percent_encode_byte, percent_decode};
 use super::{percent_encode_byte, percent_decode};
 
 
 
 
-pub fn parse_str(input: &str) -> Vec<(StrBuf, StrBuf)> {
+pub fn parse_str(input: &str) -> Vec<(String, String)> {
     parse_bytes(input.as_bytes(), None, false, false).unwrap()
     parse_bytes(input.as_bytes(), None, false, false).unwrap()
 }
 }
 
 
 
 
 pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
 pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
-                   mut use_charset: bool, mut isindex: bool) -> Option<Vec<(StrBuf, StrBuf)>> {
+                   mut use_charset: bool, mut isindex: bool) -> Option<Vec<(String, String)>> {
     let mut encoding_override = encoding_override.unwrap_or(UTF_8 as EncodingRef);
     let mut encoding_override = encoding_override.unwrap_or(UTF_8 as EncodingRef);
     let mut pairs = Vec::new();
     let mut pairs = Vec::new();
     for piece in input.split(|&b| b == '&' as u8) {
     for piece in input.split(|&b| b == '&' as u8) {
@@ -64,7 +64,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
     }
     }
 
 
     #[inline]
     #[inline]
-    fn decode(input: Vec<u8>, encoding_override: EncodingRef) -> StrBuf {
+    fn decode(input: Vec<u8>, encoding_override: EncodingRef) -> String {
         let bytes = percent_decode(input.as_slice());
         let bytes = percent_decode(input.as_slice());
         encoding_override.decode(bytes.as_slice(), encoding::DecodeReplace).unwrap()
         encoding_override.decode(bytes.as_slice(), encoding::DecodeReplace).unwrap()
     }
     }
@@ -75,9 +75,9 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
 }
 }
 
 
 
 
-pub fn serialize(pairs: Vec<(StrBuf, StrBuf)>, encoding_override: Option<EncodingRef>) -> StrBuf {
+pub fn serialize(pairs: Vec<(String, String)>, encoding_override: Option<EncodingRef>) -> String {
     #[inline]
     #[inline]
-    fn byte_serialize(input: &str, output: &mut StrBuf,
+    fn byte_serialize(input: &str, output: &mut String,
                      encoding_override: Option<EncodingRef>) {
                      encoding_override: Option<EncodingRef>) {
         let keep_alive;
         let keep_alive;
         let input = match encoding_override {
         let input = match encoding_override {
@@ -98,7 +98,7 @@ pub fn serialize(pairs: Vec<(StrBuf, StrBuf)>, encoding_override: Option<Encodin
         }
         }
     }
     }
 
 
-    let mut output = StrBuf::new();
+    let mut output = String::new();
     for &(ref name, ref value) in pairs.iter() {
     for &(ref name, ref value) in pairs.iter() {
         if output.len() > 0 {
         if output.len() > 0 {
             output.push_str("&");
             output.push_str("&");

+ 31 - 31
parser.rs

@@ -52,10 +52,10 @@ pub fn parse_url(input: &str, base_url: Option<&Url>) -> ParseResult<Url> {
                         parse_relative_url(scheme, remaining, base)
                         parse_relative_url(scheme, remaining, base)
                     },
                     },
                     _ => parse_relative_url(scheme, remaining, &Url {
                     _ => parse_relative_url(scheme, remaining, &Url {
-                        scheme: StrBuf::new(), query: None, fragment: None,
+                        scheme: String::new(), query: None, fragment: None,
                         scheme_data: RelativeSchemeData(SchemeRelativeUrl {
                         scheme_data: RelativeSchemeData(SchemeRelativeUrl {
                             userinfo: None, host: Domain(Vec::new()),
                             userinfo: None, host: Domain(Vec::new()),
-                            port: StrBuf::new(), path: Vec::new()
+                            port: String::new(), path: Vec::new()
                         })
                         })
                     }),
                     }),
                 }
                 }
@@ -89,7 +89,7 @@ pub fn parse_url(input: &str, base_url: Option<&Url>) -> ParseResult<Url> {
 }
 }
 
 
 
 
-fn parse_scheme<'a>(input: &'a str) -> (Option<StrBuf>, &'a str) {
+fn parse_scheme<'a>(input: &'a str) -> (Option<String>, &'a str) {
     if input.is_empty() || !is_ascii_alpha(input[0]) {
     if input.is_empty() || !is_ascii_alpha(input[0]) {
         return (None, input)
         return (None, input)
     }
     }
@@ -98,7 +98,7 @@ fn parse_scheme<'a>(input: &'a str) -> (Option<StrBuf>, &'a str) {
         match input[i] as char {
         match input[i] as char {
             'a'..'z' | 'A'..'Z' | '0'..'9' | '+' | '-' | '.' => (),
             'a'..'z' | 'A'..'Z' | '0'..'9' | '+' | '-' | '.' => (),
             ':' => return (
             ':' => return (
-                Some(input.slice_to(i).to_ascii_lower().into_strbuf()),
+                Some(input.slice_to(i).to_ascii_lower()),
                 input.slice_from(i + 1),
                 input.slice_from(i + 1),
             ),
             ),
             _ => return (None, input),
             _ => return (None, input),
@@ -109,7 +109,7 @@ fn parse_scheme<'a>(input: &'a str) -> (Option<StrBuf>, &'a str) {
 }
 }
 
 
 
 
-fn parse_absolute_url<'a>(scheme: StrBuf, input: &'a str) -> ParseResult<Url> {
+fn parse_absolute_url<'a>(scheme: String, input: &'a str) -> ParseResult<Url> {
     // Authority first slash state
     // Authority first slash state
     let remaining = skip_slashes(input);
     let remaining = skip_slashes(input);
     // Authority state
     // Authority state
@@ -129,7 +129,7 @@ fn parse_absolute_url<'a>(scheme: StrBuf, input: &'a str) -> ParseResult<Url> {
 }
 }
 
 
 
 
-fn parse_relative_url<'a>(scheme: StrBuf, input: &'a str, base: &Url) -> ParseResult<Url> {
+fn parse_relative_url<'a>(scheme: String, input: &'a str, base: &Url) -> ParseResult<Url> {
     match base.scheme_data {
     match base.scheme_data {
         OtherSchemeData(_) => Err("Relative URL with a non-relative-scheme base"),
         OtherSchemeData(_) => Err("Relative URL with a non-relative-scheme base"),
         RelativeSchemeData(ref base_scheme_data) => if input.is_empty() {
         RelativeSchemeData(ref base_scheme_data) => if input.is_empty() {
@@ -161,7 +161,7 @@ fn parse_relative_url<'a>(scheme: StrBuf, input: &'a str, base: &Url) -> ParseRe
                             let (path, remaining) = parse_path_start(
                             let (path, remaining) = parse_path_start(
                                 remaining, /* full_url= */ true, in_file_scheme);
                                 remaining, /* full_url= */ true, in_file_scheme);
                             let scheme_data = RelativeSchemeData(SchemeRelativeUrl {
                             let scheme_data = RelativeSchemeData(SchemeRelativeUrl {
-                                userinfo: None, host: host, port: StrBuf::new(), path: path });
+                                userinfo: None, host: host, port: String::new(), path: path });
                             let (query, fragment) = parse_query_and_fragment(remaining);
                             let (query, fragment) = parse_query_and_fragment(remaining);
                             Ok(Url { scheme: scheme, scheme_data: scheme_data,
                             Ok(Url { scheme: scheme, scheme_data: scheme_data,
                                      query: query, fragment: fragment })
                                      query: query, fragment: fragment })
@@ -175,7 +175,7 @@ fn parse_relative_url<'a>(scheme: StrBuf, input: &'a str, base: &Url) -> ParseRe
                         let scheme_data = RelativeSchemeData(if in_file_scheme {
                         let scheme_data = RelativeSchemeData(if in_file_scheme {
                             SchemeRelativeUrl {
                             SchemeRelativeUrl {
                                 userinfo: None, host: Domain(Vec::new()),
                                 userinfo: None, host: Domain(Vec::new()),
-                                port: StrBuf::new(), path: path
+                                port: String::new(), path: path
                             }
                             }
                         } else {
                         } else {
                             SchemeRelativeUrl {
                             SchemeRelativeUrl {
@@ -214,7 +214,7 @@ fn parse_relative_url<'a>(scheme: StrBuf, input: &'a str, base: &Url) -> ParseRe
                          (RelativeSchemeData(SchemeRelativeUrl {
                          (RelativeSchemeData(SchemeRelativeUrl {
                             userinfo: None,
                             userinfo: None,
                             host: Domain(Vec::new()),
                             host: Domain(Vec::new()),
-                            port: StrBuf::new(),
+                            port: String::new(),
                             path: path
                             path: path
                         }), remaining)
                         }), remaining)
                     } else {
                     } else {
@@ -280,7 +280,7 @@ fn parse_userinfo<'a>(input: &'a str) -> (Option<UserInfo>, &'a str) {
 
 
 
 
 fn parse_userinfo_inner<'a>(input: &'a str) -> UserInfo {
 fn parse_userinfo_inner<'a>(input: &'a str) -> UserInfo {
-    let mut username = StrBuf::new();
+    let mut username = String::new();
     let mut i = 0;
     let mut i = 0;
     loop {
     loop {
         if i >= input.len() {
         if i >= input.len() {
@@ -310,7 +310,7 @@ fn parse_userinfo_inner<'a>(input: &'a str) -> UserInfo {
             }
             }
         }
         }
     }
     }
-    let mut password = StrBuf::new();
+    let mut password = String::new();
     while i < input.len() {
     while i < input.len() {
         match input[i] as char {
         match input[i] as char {
             '\t' | '\n' | '\r' => {
             '\t' | '\n' | '\r' => {
@@ -336,10 +336,10 @@ fn parse_userinfo_inner<'a>(input: &'a str) -> UserInfo {
 }
 }
 
 
 
 
-fn parse_hostname<'a>(input: &'a str, scheme: &str) -> ParseResult<(Host, StrBuf, &'a str)> {
+fn parse_hostname<'a>(input: &'a str, scheme: &str) -> ParseResult<(Host, String, &'a str)> {
     let mut i = 0;
     let mut i = 0;
     let mut inside_square_brackets = false;
     let mut inside_square_brackets = false;
-    let mut host_input = StrBuf::new();
+    let mut host_input = String::new();
     while i < input.len() {
     while i < input.len() {
         match input[i] as char {
         match input[i] as char {
             ':' if !inside_square_brackets => return match Host::parse(host_input.as_slice()) {
             ':' if !inside_square_brackets => return match Host::parse(host_input.as_slice()) {
@@ -366,13 +366,13 @@ fn parse_hostname<'a>(input: &'a str, scheme: &str) -> ParseResult<(Host, StrBuf
     }
     }
     match Host::parse(host_input.as_slice()) {
     match Host::parse(host_input.as_slice()) {
         Err(message) => Err(message),
         Err(message) => Err(message),
-        Ok(host) => Ok((host, StrBuf::new(), input.slice_from(i))),
+        Ok(host) => Ok((host, String::new(), input.slice_from(i))),
     }
     }
 }
 }
 
 
 
 
-fn parse_port<'a>(input: &'a str, scheme: &str) -> ParseResult<(StrBuf, &'a str)> {
-    let mut port = StrBuf::new();
+fn parse_port<'a>(input: &'a str, scheme: &str) -> ParseResult<(String, &'a str)> {
+    let mut port = String::new();
     let mut has_initial_zero = false;
     let mut has_initial_zero = false;
     let mut i = 0;
     let mut i = 0;
     while i < input.len() {
     while i < input.len() {
@@ -406,7 +406,7 @@ fn parse_port<'a>(input: &'a str, scheme: &str) -> ParseResult<(StrBuf, &'a str)
 
 
 fn parse_file_host<'a>(input: &'a str) -> ParseResult<(Host, &'a str)> {
 fn parse_file_host<'a>(input: &'a str) -> ParseResult<(Host, &'a str)> {
     let mut i = 0;
     let mut i = 0;
-    let mut host_input = StrBuf::new();
+    let mut host_input = String::new();
     while i < input.len() {
     while i < input.len() {
         match input[i] as char {
         match input[i] as char {
             '/' | '\\' | '?' | '#' => break,
             '/' | '\\' | '?' | '#' => break,
@@ -428,7 +428,7 @@ fn parse_file_host<'a>(input: &'a str) -> ParseResult<(Host, &'a str)> {
 
 
 
 
 fn parse_path_start<'a>(input: &'a str, full_url: bool, in_file_scheme: bool)
 fn parse_path_start<'a>(input: &'a str, full_url: bool, in_file_scheme: bool)
-           -> (Vec<StrBuf>, &'a str) {
+           -> (Vec<String>, &'a str) {
     let mut i = 0;
     let mut i = 0;
     // Relative path start state
     // Relative path start state
     if !input.is_empty() {
     if !input.is_empty() {
@@ -445,13 +445,13 @@ fn parse_path_start<'a>(input: &'a str, full_url: bool, in_file_scheme: bool)
 }
 }
 
 
 
 
-fn parse_path<'a>(base_path: Vec<StrBuf>, input: &'a str, full_url: bool, in_file_scheme: bool)
-           -> (Vec<StrBuf>, &'a str) {
+fn parse_path<'a>(base_path: Vec<String>, input: &'a str, full_url: bool, in_file_scheme: bool)
+           -> (Vec<String>, &'a str) {
     // Relative path state
     // Relative path state
     let mut path = base_path;
     let mut path = base_path;
     let mut i = 0;
     let mut i = 0;
     loop {
     loop {
-        let mut path_part = StrBuf::new();
+        let mut path_part = String::new();
         let mut ends_with_slash = false;
         let mut ends_with_slash = false;
         while i < input.len() {
         while i < input.len() {
             match input[i] as char {
             match input[i] as char {
@@ -491,12 +491,12 @@ fn parse_path<'a>(base_path: Vec<StrBuf>, input: &'a str, full_url: bool, in_fil
             ".." | ".%2e" | "%2e." | "%2e%2e" => {
             ".." | ".%2e" | "%2e." | "%2e%2e" => {
                 path.pop();
                 path.pop();
                 if !ends_with_slash {
                 if !ends_with_slash {
-                    path.push(StrBuf::new());
+                    path.push(String::new());
                 }
                 }
             },
             },
             "." | "%2e" => {
             "." | "%2e" => {
                 if !ends_with_slash {
                 if !ends_with_slash {
-                    path.push(StrBuf::new());
+                    path.push(String::new());
                 }
                 }
             },
             },
             _ => {
             _ => {
@@ -521,8 +521,8 @@ fn parse_path<'a>(base_path: Vec<StrBuf>, input: &'a str, full_url: bool, in_fil
 }
 }
 
 
 
 
-fn parse_scheme_data<'a>(input: &'a str) -> (StrBuf, &'a str) {
-    let mut scheme_data = StrBuf::new();
+fn parse_scheme_data<'a>(input: &'a str) -> (String, &'a str) {
+    let mut scheme_data = String::new();
     let mut i = 0;
     let mut i = 0;
     while i < input.len() {
     while i < input.len() {
         match input[i] as char {
         match input[i] as char {
@@ -550,7 +550,7 @@ fn parse_scheme_data<'a>(input: &'a str) -> (StrBuf, &'a str) {
 }
 }
 
 
 
 
-fn parse_query_and_fragment(input: &str) -> (Option<StrBuf>, Option<StrBuf>) {
+fn parse_query_and_fragment(input: &str) -> (Option<String>, Option<String>) {
     if input.is_empty() {
     if input.is_empty() {
         (None, None)
         (None, None)
     } else {
     } else {
@@ -570,8 +570,8 @@ fn parse_query_and_fragment(input: &str) -> (Option<StrBuf>, Option<StrBuf>) {
 
 
 
 
 fn parse_query<'a>(input: &'a str, encoding_override: EncodingRef, full_url: bool)
 fn parse_query<'a>(input: &'a str, encoding_override: EncodingRef, full_url: bool)
-               -> (StrBuf, Option<&'a str>) {
-    let mut query = StrBuf::new();
+               -> (String, Option<&'a str>) {
+    let mut query = String::new();
     let mut i = 0;
     let mut i = 0;
     let mut remaining = None;
     let mut remaining = None;
     while i < input.len() {
     while i < input.len() {
@@ -600,7 +600,7 @@ fn parse_query<'a>(input: &'a str, encoding_override: EncodingRef, full_url: boo
         }
         }
     }
     }
     let query_bytes = encoding_override.encode(query.as_slice(), encoding::EncodeReplace).unwrap();
     let query_bytes = encoding_override.encode(query.as_slice(), encoding::EncodeReplace).unwrap();
-    let mut query_encoded = StrBuf::new();
+    let mut query_encoded = String::new();
     for &byte in query_bytes.iter() {
     for &byte in query_bytes.iter() {
         match byte {
         match byte {
             0x00 .. 0x20 | 0x22 | 0x23 | 0x3C | 0x3E | 0x60 | 0x7E .. 0xFF
             0x00 .. 0x20 | 0x22 | 0x23 | 0x3C | 0x3E | 0x60 | 0x7E .. 0xFF
@@ -613,8 +613,8 @@ fn parse_query<'a>(input: &'a str, encoding_override: EncodingRef, full_url: boo
 }
 }
 
 
 
 
-fn parse_fragment<'a>(input: &'a str) -> StrBuf {
-    let mut fragment = StrBuf::new();
+fn parse_fragment<'a>(input: &'a str) -> String {
+    let mut fragment = String::new();
     let mut i = 0;
     let mut i = 0;
     while i < input.len() {
     while i < input.len() {
         match input[i] as char {
         match input[i] as char {

+ 16 - 11
punycode.rs

@@ -109,15 +109,20 @@ pub fn decode(input: &str) -> Option<Vec<char>> {
 }
 }
 
 
 
 
+pub fn encode_str(input: &str) -> Option<String> {
+    encode(input.chars().collect::<Vec<char>>().as_slice())
+}
+
+
 /// Convert Unicode to Punycode.
 /// Convert Unicode to Punycode.
 /// Return None on overflow, which can only happen on inputs that would take more than
 /// Return None on overflow, which can only happen on inputs that would take more than
 /// 63 encoded bytes, the DNS limit on domain name labels.
 /// 63 encoded bytes, the DNS limit on domain name labels.
-pub fn encode(input: &[char]) -> Option<StrBuf> {
+pub fn encode(input: &[char]) -> Option<String> {
     // Handle "basic" (ASCII) code points. They are encoded as-is.
     // Handle "basic" (ASCII) code points. They are encoded as-is.
     let output_bytes = input.iter().filter_map(|&c|
     let output_bytes = input.iter().filter_map(|&c|
         if c.is_ascii() { Some(c as u8) } else { None }
         if c.is_ascii() { Some(c as u8) } else { None }
     ).collect();
     ).collect();
-    let mut output = unsafe { str::raw::from_utf8_owned(output_bytes) }.into_strbuf();
+    let mut output = unsafe { str::raw::from_utf8_owned(output_bytes) };
     let basic_length = output.len() as u32;
     let basic_length = output.len() as u32;
     if basic_length > 0 {
     if basic_length > 0 {
         output.push_str("-")
         output.push_str("-")
@@ -176,7 +181,7 @@ pub fn encode(input: &[char]) -> Option<StrBuf> {
 
 
 
 
 #[inline]
 #[inline]
-fn value_to_digit(value: u32, output: &mut StrBuf) {
+fn value_to_digit(value: u32, output: &mut String) {
     let code_point = match value {
     let code_point = match value {
         0 .. 25 => value + 0x61,  // a..z
         0 .. 25 => value + 0x61,  // a..z
         26 .. 35 => value - 26 + 0x30,  // 0..9
         26 .. 35 => value - 26 + 0x30,  // 0..9
@@ -188,33 +193,33 @@ fn value_to_digit(value: u32, output: &mut StrBuf) {
 
 
 #[cfg(test)]
 #[cfg(test)]
 mod tests {
 mod tests {
-    use super::{decode, encode};
+    use super::{decode, encode_str};
     use std::str::from_chars;
     use std::str::from_chars;
     use serialize::json::{from_str, List, Object, String};
     use serialize::json::{from_str, List, Object, String};
 
 
     fn one_test(description: &str, decoded: &str, encoded: &str) {
     fn one_test(description: &str, decoded: &str, encoded: &str) {
         match decode(encoded) {
         match decode(encoded) {
-            None => fail!("Decoding {:?} failed.", encoded),
+            None => fail!("Decoding {} failed.", encoded),
             Some(result) => {
             Some(result) => {
                 let result = from_chars(result.as_slice());
                 let result = from_chars(result.as_slice());
                 assert!(result.as_slice() == decoded,
                 assert!(result.as_slice() == decoded,
-                        format!("Incorrect decoding of {:?}:\n   {:?}\n!= {:?}\n{}",
+                        format!("Incorrect decoding of {}:\n   {}\n!= {}\n{}",
                                 encoded, result.as_slice(), decoded, description))
                                 encoded, result.as_slice(), decoded, description))
             }
             }
         }
         }
 
 
-        match encode(decoded.chars().collect::<~[char]>()) {
-            None => fail!("Encoding {:?} failed.", decoded),
+        match encode_str(decoded) {
+            None => fail!("Encoding {} failed.", decoded),
             Some(result) => {
             Some(result) => {
                 assert!(result.as_slice() == encoded,
                 assert!(result.as_slice() == encoded,
-                        format!("Incorrect encoding of {:?}:\n   {:?}\n!= {:?}\n{}",
+                        format!("Incorrect encoding of {}:\n   {}\n!= {}\n{}",
                                 decoded, result.as_slice(), encoded, description))
                                 decoded, result.as_slice(), encoded, description))
             }
             }
         }
         }
     }
     }
 
 
     fn get_string<'a>(map: &'a Box<Object>, key: &str) -> &'a str {
     fn get_string<'a>(map: &'a Box<Object>, key: &str) -> &'a str {
-        match map.find(&key.to_owned()) {
+        match map.find(&key.to_string()) {
             Some(&String(ref s)) => s.as_slice(),
             Some(&String(ref s)) => s.as_slice(),
             None => "",
             None => "",
             _ => fail!(),
             _ => fail!(),
@@ -235,7 +240,7 @@ mod tests {
                     _ => fail!(),
                     _ => fail!(),
                 }
                 }
             },
             },
-            other => fail!("{:?}", other)
+            other => fail!("{}", other)
         }
         }
     }
     }
 }
 }

+ 26 - 26
tests.rs

@@ -29,23 +29,23 @@ fn test_url_parsing() {
         } = test;
         } = test;
         let base = match Url::parse(base.as_slice(), None) {
         let base = match Url::parse(base.as_slice(), None) {
             Ok(base) => base,
             Ok(base) => base,
-            Err(message) => fail!("Error parsing base {:?}: {}", base, message)
+            Err(message) => fail!("Error parsing base {}: {}", base, message)
         };
         };
         let url = Url::parse(input.as_slice(), Some(&base));
         let url = Url::parse(input.as_slice(), Some(&base));
         if expected_scheme.is_none() {
         if expected_scheme.is_none() {
-            assert!(url.is_err(), "Expected a parse error for URL {:?}", input);
+            assert!(url.is_err(), "Expected a parse error for URL {}", input);
             continue
             continue
         }
         }
         let Url { scheme, scheme_data, query, fragment } = match url {
         let Url { scheme, scheme_data, query, fragment } = match url {
             Ok(url) => url,
             Ok(url) => url,
-            Err(message) => fail!("Error parsing URL {:?}: {}", input, message)
+            Err(message) => fail!("Error parsing URL {}: {}", input, message)
         };
         };
 
 
         assert_eq!(Some(scheme), expected_scheme);
         assert_eq!(Some(scheme), expected_scheme);
         match scheme_data {
         match scheme_data {
             RelativeSchemeData(SchemeRelativeUrl { userinfo, host, port, path }) => {
             RelativeSchemeData(SchemeRelativeUrl { userinfo, host, port, path }) => {
                 let (username, password) = match userinfo {
                 let (username, password) = match userinfo {
-                    None => (StrBuf::new(), None),
+                    None => (String::new(), None),
                     Some(UserInfo { username, password }) => (username, password),
                     Some(UserInfo { username, password }) => (username, password),
                 };
                 };
                 assert_eq!(username, expected_username);
                 assert_eq!(username, expected_username);
@@ -53,19 +53,19 @@ fn test_url_parsing() {
                 let host = host.serialize();
                 let host = host.serialize();
                 assert_eq!(host, expected_host)
                 assert_eq!(host, expected_host)
                 assert_eq!(port, expected_port);
                 assert_eq!(port, expected_port);
-                assert_eq!(Some("/".to_strbuf().append(path.connect("/"))),
+                assert_eq!(Some("/".to_string().append(path.connect("/").as_slice())),
                            expected_path);
                            expected_path);
             },
             },
             OtherSchemeData(scheme_data) => {
             OtherSchemeData(scheme_data) => {
                 assert_eq!(Some(scheme_data), expected_path);
                 assert_eq!(Some(scheme_data), expected_path);
-                assert_eq!(StrBuf::new(), expected_username);
+                assert_eq!(String::new(), expected_username);
                 assert_eq!(None, expected_password);
                 assert_eq!(None, expected_password);
-                assert_eq!(StrBuf::new(), expected_host);
-                assert_eq!(StrBuf::new(), expected_port);
+                assert_eq!(String::new(), expected_host);
+                assert_eq!(String::new(), expected_port);
             },
             },
         }
         }
-        fn opt_prepend(prefix: &str, opt_s: Option<StrBuf>) -> Option<StrBuf> {
-            opt_s.map(|s| prefix.to_strbuf().append(s.as_slice()))
+        fn opt_prepend(prefix: &str, opt_s: Option<String>) -> Option<String> {
+            opt_s.map(|s| prefix.to_string().append(s.as_slice()))
         }
         }
         assert_eq!(opt_prepend("?", query), expected_query);
         assert_eq!(opt_prepend("?", query), expected_query);
         assert_eq!(opt_prepend("#", fragment), expected_fragment);
         assert_eq!(opt_prepend("#", fragment), expected_fragment);
@@ -73,16 +73,16 @@ fn test_url_parsing() {
 }
 }
 
 
 struct Test {
 struct Test {
-    input: StrBuf,
-    base: StrBuf,
-    scheme: Option<StrBuf>,
-    username: StrBuf,
-    password: Option<StrBuf>,
-    host: StrBuf,
-    port: StrBuf,
-    path: Option<StrBuf>,
-    query: Option<StrBuf>,
-    fragment: Option<StrBuf>,
+    input: String,
+    base: String,
+    scheme: Option<String>,
+    username: String,
+    password: Option<String>,
+    host: String,
+    port: String,
+    path: Option<String>,
+    query: Option<String>,
+    fragment: Option<String>,
 }
 }
 
 
 fn parse_test_data(input: &str) -> Vec<Test> {
 fn parse_test_data(input: &str) -> Vec<Test> {
@@ -101,10 +101,10 @@ fn parse_test_data(input: &str) -> Vec<Test> {
                 unescape(pieces.shift().unwrap())
                 unescape(pieces.shift().unwrap())
             },
             },
             scheme: None,
             scheme: None,
-            username: StrBuf::new(),
+            username: String::new(),
             password: None,
             password: None,
-            host: StrBuf::new(),
-            port: StrBuf::new(),
+            host: String::new(),
+            port: String::new(),
             path: None,
             path: None,
             query: None,
             query: None,
             fragment: None,
             fragment: None,
@@ -132,8 +132,8 @@ fn parse_test_data(input: &str) -> Vec<Test> {
     tests
     tests
 }
 }
 
 
-fn unescape(input: &str) -> StrBuf {
-    let mut output = StrBuf::new();
+fn unescape(input: &str) -> String {
+    let mut output = String::new();
     let mut chars = input.chars();
     let mut chars = input.chars();
     loop {
     loop {
         match chars.next() {
         match chars.next() {
@@ -148,7 +148,7 @@ fn unescape(input: &str) -> StrBuf {
                         't' => '\t',
                         't' => '\t',
                         'f' => '\x0C',
                         'f' => '\x0C',
                         'u' => {
                         'u' => {
-                            let mut hex = StrBuf::new();
+                            let mut hex = String::new();
                             hex.push_char(chars.next().unwrap());
                             hex.push_char(chars.next().unwrap());
                             hex.push_char(chars.next().unwrap());
                             hex.push_char(chars.next().unwrap());
                             hex.push_char(chars.next().unwrap());
                             hex.push_char(chars.next().unwrap());

+ 21 - 21
url.rs

@@ -32,35 +32,35 @@ mod tests;
 
 
 #[deriving(Clone, Show)]
 #[deriving(Clone, Show)]
 pub struct Url {
 pub struct Url {
-    scheme: StrBuf,
+    scheme: String,
     scheme_data: SchemeData,
     scheme_data: SchemeData,
-    query: Option<StrBuf>,  // See form_urlencoded::parse_str() to get name/value pairs.
-    fragment: Option<StrBuf>,
+    query: Option<String>,  // See form_urlencoded::parse_str() to get name/value pairs.
+    fragment: Option<String>,
 }
 }
 
 
 #[deriving(Clone, Show)]
 #[deriving(Clone, Show)]
 pub enum SchemeData {
 pub enum SchemeData {
     RelativeSchemeData(SchemeRelativeUrl),
     RelativeSchemeData(SchemeRelativeUrl),
-    OtherSchemeData(StrBuf),  // data: URLs, mailto: URLs, etc.
+    OtherSchemeData(String),  // data: URLs, mailto: URLs, etc.
 }
 }
 
 
 #[deriving(Clone, Show)]
 #[deriving(Clone, Show)]
 pub struct SchemeRelativeUrl {
 pub struct SchemeRelativeUrl {
     userinfo: Option<UserInfo>,
     userinfo: Option<UserInfo>,
     host: Host,
     host: Host,
-    port: StrBuf,
-    path: Vec<StrBuf>,
+    port: String,
+    path: Vec<String>,
 }
 }
 
 
 #[deriving(Clone, Show)]
 #[deriving(Clone, Show)]
 pub struct UserInfo {
 pub struct UserInfo {
-    username: StrBuf,
-    password: Option<StrBuf>,
+    username: String,
+    password: Option<String>,
 }
 }
 
 
 #[deriving(Clone, Show)]
 #[deriving(Clone, Show)]
 pub enum Host {
 pub enum Host {
-    Domain(Vec<StrBuf>),  // Can only be empty in the file scheme
+    Domain(Vec<String>),  // Can only be empty in the file scheme
     Ipv6(Ipv6Address)
     Ipv6(Ipv6Address)
 }
 }
 
 
@@ -96,7 +96,7 @@ impl Url {
         parser::parse_url(input, base_url)
         parser::parse_url(input, base_url)
     }
     }
 
 
-    pub fn serialize(&self) -> StrBuf {
+    pub fn serialize(&self) -> String {
         let mut result = self.serialize_no_fragment();
         let mut result = self.serialize_no_fragment();
         match self.fragment {
         match self.fragment {
             None => (),
             None => (),
@@ -108,7 +108,7 @@ impl Url {
         result
         result
     }
     }
 
 
-    pub fn serialize_no_fragment(&self) -> StrBuf {
+    pub fn serialize_no_fragment(&self) -> String {
         let mut result = self.scheme.clone();
         let mut result = self.scheme.clone();
         result.push_str(":");
         result.push_str(":");
         match self.scheme_data {
         match self.scheme_data {
@@ -170,7 +170,7 @@ impl Host {
                 Err("Invalid Ipv6 address")
                 Err("Invalid Ipv6 address")
             }
             }
         } else {
         } else {
-            let mut percent_encoded = StrBuf::new();
+            let mut percent_encoded = String::new();
             utf8_percent_encode(input, SimpleEncodeSet, &mut percent_encoded);
             utf8_percent_encode(input, SimpleEncodeSet, &mut percent_encoded);
             let bytes = percent_decode(percent_encoded.as_bytes());
             let bytes = percent_decode(percent_encoded.as_bytes());
             let decoded = UTF_8.decode(bytes.as_slice(), encoding::DecodeReplace).unwrap();
             let decoded = UTF_8.decode(bytes.as_slice(), encoding::DecodeReplace).unwrap();
@@ -180,7 +180,7 @@ impl Host {
                 // TODO: Remove this check and use IDNA "domain to ASCII"
                 // TODO: Remove this check and use IDNA "domain to ASCII"
                 // TODO: switch to .map(domain_label_to_ascii).collect() then.
                 // TODO: switch to .map(domain_label_to_ascii).collect() then.
                 if label.is_ascii() {
                 if label.is_ascii() {
-                    labels.push(label.to_strbuf())
+                    labels.push(label.to_string())
                 } else {
                 } else {
                     return Err("Non-ASCII domains (IDNA) are not supported yet.")
                     return Err("Non-ASCII domains (IDNA) are not supported yet.")
                 }
                 }
@@ -189,11 +189,11 @@ impl Host {
         }
         }
     }
     }
 
 
-    pub fn serialize(&self) -> StrBuf {
+    pub fn serialize(&self) -> String {
         match *self {
         match *self {
-            Domain(ref labels) => labels.connect(".").into_strbuf(),
+            Domain(ref labels) => labels.connect("."),
             Ipv6(ref address) => {
             Ipv6(ref address) => {
-                let mut result = StrBuf::from_str("[");
+                let mut result = String::from_str("[");
                 result.push_str(address.serialize().as_slice());
                 result.push_str(address.serialize().as_slice());
                 result.push_str("]");
                 result.push_str("]");
                 result
                 result
@@ -320,8 +320,8 @@ impl Ipv6Address {
         Ok(Ipv6Address { pieces: pieces })
         Ok(Ipv6Address { pieces: pieces })
     }
     }
 
 
-    pub fn serialize(&self) -> StrBuf {
-        let mut output = StrBuf::new();
+    pub fn serialize(&self) -> String {
+        let mut output = String::new();
         let (compress_start, compress_end) = longest_zero_sequence(&self.pieces);
         let (compress_start, compress_end) = longest_zero_sequence(&self.pieces);
         let mut i = 0;
         let mut i = 0;
         while i < 8 {
         while i < 8 {
@@ -336,7 +336,7 @@ impl Ipv6Address {
                     break;
                     break;
                 }
                 }
             }
             }
-            output.push_str(self.pieces[i as uint].to_str_radix(16));
+            output.push_str(self.pieces[i as uint].to_str_radix(16).as_slice());
             if i < 7 {
             if i < 7 {
                 output.push_str(":");
                 output.push_str(":");
             }
             }
@@ -407,7 +407,7 @@ enum EncodeSet {
 
 
 
 
 #[inline]
 #[inline]
-fn utf8_percent_encode(input: &str, encode_set: EncodeSet, output: &mut StrBuf) {
+fn utf8_percent_encode(input: &str, encode_set: EncodeSet, output: &mut String) {
     use Default = self::DefaultEncodeSet;
     use Default = self::DefaultEncodeSet;
     use UserInfo = self::UserInfoEncodeSet;
     use UserInfo = self::UserInfoEncodeSet;
     use Password = self::PasswordEncodeSet;
     use Password = self::PasswordEncodeSet;
@@ -433,7 +433,7 @@ fn utf8_percent_encode(input: &str, encode_set: EncodeSet, output: &mut StrBuf)
 
 
 
 
 #[inline]
 #[inline]
-fn percent_encode_byte(byte: u8, output: &mut StrBuf) {
+fn percent_encode_byte(byte: u8, output: &mut String) {
     unsafe {
     unsafe {
         output.push_bytes([
         output.push_bytes([
             '%' as u8, to_hex_upper(byte >> 4), to_hex_upper(byte & 0x0F)
             '%' as u8, to_hex_upper(byte >> 4), to_hex_upper(byte & 0x0F)