Răsfoiți Sursa

Made rust-url compile with rust master

Dmitry Promsky 12 ani în urmă
părinte
comite
491c1667e3
5 a modificat fișierele cu 26 adăugiri și 25 ștergeri
  1. 2 2
      form_urlencoded.rs
  2. 1 1
      parser.rs
  3. 11 11
      punycode.rs
  4. 3 3
      tests.rs
  5. 9 8
      url.rs

+ 2 - 2
form_urlencoded.rs

@@ -60,7 +60,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
 
     #[inline]
     fn replace_plus(input: &[u8]) -> ~[u8] {
-        input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).to_owned_vec()
+        input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).collect()
     }
 
     #[inline]
@@ -71,7 +71,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
 
     Some(pairs.move_iter().map(
         |(name, value)| (decode(name, encoding_override), decode(value, encoding_override))
-    ).to_owned_vec())
+    ).collect())
 }
 
 

+ 1 - 1
parser.rs

@@ -487,7 +487,7 @@ fn parse_path<'a>(base_path: ~[~str], input: &'a str, full_url: bool, in_file_sc
         let lower = path_part.to_ascii_lower();
         match lower.as_slice() {
             ".." | ".%2e" | "%2e." | "%2e%2e" => {
-                path.pop_opt();
+                path.pop();
                 if !ends_with_slash {
                     path.push(~"");
                 }

+ 11 - 11
punycode.rs

@@ -6,12 +6,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
 use std::u32;
 use std::char;
 use std::str;
 
-
 // Bootstring parameters for Punycode
 static BASE: u32 = 36;
 static T_MIN: u32 = 1;
@@ -46,7 +44,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
     let (mut output, input) = match input.rfind(DELIMITER) {
         None => (~[], input),
         Some(position) => (
-            input.slice_to(position).chars().to_owned_vec(),
+            input.slice_to(position).chars().collect(),
             if position > 0 { input.slice_from(position + 1) } else { input }
         )
     };
@@ -71,7 +69,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
                 byte @ 0x61 .. 0x7A => byte - 0x61,  // a..z
                 _ => return None
             } as u32;
-            if digit > (u32::max_value - i) / weight {
+            if digit > (u32::MAX - i) / weight {
                 return None  // Overflow
             }
             i += digit * weight;
@@ -81,7 +79,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
             if digit < t {
                 break
             }
-            if weight > u32::max_value / (BASE - t) {
+            if weight > u32::MAX / (BASE - t) {
                 return None  // Overflow
             }
             weight *= BASE - t;
@@ -93,7 +91,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
         }
         let length = output.len() as u32;
         bias = adapt(i - previous_i, length + 1, previous_i == 0);
-        if i / (length + 1) > u32::max_value - code_point {
+        if i / (length + 1) > u32::MAX - code_point {
             return None  // Overflow
         }
         // i was supposed to wrap around from length+1 to 0,
@@ -118,7 +116,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
     // Handle "basic" (ASCII) code points. They are encoded as-is.
     let output_bytes = input.iter().filter_map(|&c|
         if c.is_ascii() { Some(c as u8) } else { None }
-    ).to_owned_vec();
+    ).collect();
     let mut output = unsafe { str::raw::from_utf8_owned(output_bytes) };
     let basic_length = output.len() as u32;
     if basic_length > 0 {
@@ -134,7 +132,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
         // Find the next larger one.
         let min_code_point = input.iter().map(|&c| c as u32)
                                   .filter(|&c| c >= code_point).min().unwrap();
-        if min_code_point - code_point > (u32::max_value - delta) / (processed + 1) {
+        if min_code_point - code_point > (u32::MAX - delta) / (processed + 1) {
             return None  // Overflow
         }
         // Increase delta to advance the decoder’s <code_point,i> state to <min_code_point,0>
@@ -192,7 +190,7 @@ fn value_to_digit(value: u32, output: &mut ~str) {
 mod tests {
     use super::{decode, encode};
     use std::str::from_chars;
-    use extra::json::{from_str, List, Object, String};
+    use serialize::json::{from_str, List, Object, String};
 
     fn one_test(description: &str, decoded: &str, encoded: &str) {
         match decode(encoded) {
@@ -203,9 +201,11 @@ mod tests {
                         format!("Incorrect decoding of {:?}:\n   {:?}\n!= {:?}\n{}",
                                 encoded, result.as_slice(), decoded, description))
             }
-        }
+        }        
+
+        let dec_chars: ~[char] = decoded.chars().collect();
 
-        match encode(decoded.chars().to_owned_vec()) {
+        match encode(dec_chars) {
             None => fail!("Encoding {:?} failed.", decoded),
             Some(result) => {
                 assert!(result.as_slice() == encoded,

+ 3 - 3
tests.rs

@@ -88,14 +88,14 @@ fn parse_test_data(input: &str) -> ~[Test] {
         if line == "" || line[0] == ('#' as u8) {
             continue
         }
-        let mut pieces = line.split(' ').to_owned_vec();
-        let input = unescape(pieces.shift());
+        let mut pieces: ~[&str] = line.split(' ').collect();
+        let input = unescape(pieces.shift().unwrap());
         let mut test = Test {
             input: input,
             base: if pieces.is_empty() || pieces[0] == "" {
                 tests[tests.len() - 1].base.to_owned()
             } else {
-                unescape(pieces.shift())
+                unescape(pieces.shift().unwrap())
             },
             scheme: None,
             username: ~"",

+ 9 - 8
url.rs

@@ -6,18 +6,19 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![crate_id = "url#0.1"]
+#![crate_type = "lib"]
+#![feature(macro_rules)]
 
-#[crate_id = "url#0.1"];
-#[crate_type = "lib"];
-#[feature(macro_rules)];
-
-
-extern mod encoding;
+extern crate encoding;
 
 #[cfg(test)]
-extern mod extra;
+extern crate serialize;
 
 use std::str;
+use std::cmp;
+
+use std::num::ToStrRadix;
 
 use encoding::Encoding;
 use encoding::all::UTF_8;
@@ -228,7 +229,7 @@ impl Ipv6Address {
                 continue
             }
             let start = i;
-            let end = len.min(&(start + 4));
+            let end = cmp::min(len, start + 4);
             let mut value = 0u16;
             while i < end {
                 match from_hex(input[i]) {