Skip to content

Commit 350bd6b

Browse files
committed
Merge pull request #1 from dmski/master
Made rust-url compile with rust master
2 parents 7592e78 + 491c166 commit 350bd6b

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

form_urlencoded.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
6060

6161
#[inline]
6262
fn replace_plus(input: &[u8]) -> ~[u8] {
63-
input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).to_owned_vec()
63+
input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).collect()
6464
}
6565

6666
#[inline]
@@ -71,7 +71,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,
7171

7272
Some(pairs.move_iter().map(
7373
|(name, value)| (decode(name, encoding_override), decode(value, encoding_override))
74-
).to_owned_vec())
74+
).collect())
7575
}
7676

7777

parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn parse_path<'a>(base_path: ~[~str], input: &'a str, full_url: bool, in_file_sc
487487
let lower = path_part.to_ascii_lower();
488488
match lower.as_slice() {
489489
".." | ".%2e" | "%2e." | "%2e%2e" => {
490-
path.pop_opt();
490+
path.pop();
491491
if !ends_with_slash {
492492
path.push(~"");
493493
}

punycode.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
109
use std::u32;
1110
use std::char;
1211
use std::str;
1312

14-
1513
// Bootstring parameters for Punycode
1614
static BASE: u32 = 36;
1715
static T_MIN: u32 = 1;
@@ -46,7 +44,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
4644
let (mut output, input) = match input.rfind(DELIMITER) {
4745
None => (~[], input),
4846
Some(position) => (
49-
input.slice_to(position).chars().to_owned_vec(),
47+
input.slice_to(position).chars().collect(),
5048
if position > 0 { input.slice_from(position + 1) } else { input }
5149
)
5250
};
@@ -71,7 +69,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
7169
byte @ 0x61 .. 0x7A => byte - 0x61, // a..z
7270
_ => return None
7371
} as u32;
74-
if digit > (u32::max_value - i) / weight {
72+
if digit > (u32::MAX - i) / weight {
7573
return None // Overflow
7674
}
7775
i += digit * weight;
@@ -81,7 +79,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
8179
if digit < t {
8280
break
8381
}
84-
if weight > u32::max_value / (BASE - t) {
82+
if weight > u32::MAX / (BASE - t) {
8583
return None // Overflow
8684
}
8785
weight *= BASE - t;
@@ -93,7 +91,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
9391
}
9492
let length = output.len() as u32;
9593
bias = adapt(i - previous_i, length + 1, previous_i == 0);
96-
if i / (length + 1) > u32::max_value - code_point {
94+
if i / (length + 1) > u32::MAX - code_point {
9795
return None // Overflow
9896
}
9997
// i was supposed to wrap around from length+1 to 0,
@@ -118,7 +116,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
118116
// Handle "basic" (ASCII) code points. They are encoded as-is.
119117
let output_bytes = input.iter().filter_map(|&c|
120118
if c.is_ascii() { Some(c as u8) } else { None }
121-
).to_owned_vec();
119+
).collect();
122120
let mut output = unsafe { str::raw::from_utf8_owned(output_bytes) };
123121
let basic_length = output.len() as u32;
124122
if basic_length > 0 {
@@ -134,7 +132,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
134132
// Find the next larger one.
135133
let min_code_point = input.iter().map(|&c| c as u32)
136134
.filter(|&c| c >= code_point).min().unwrap();
137-
if min_code_point - code_point > (u32::max_value - delta) / (processed + 1) {
135+
if min_code_point - code_point > (u32::MAX - delta) / (processed + 1) {
138136
return None // Overflow
139137
}
140138
// 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) {
192190
mod tests {
193191
use super::{decode, encode};
194192
use std::str::from_chars;
195-
use extra::json::{from_str, List, Object, String};
193+
use serialize::json::{from_str, List, Object, String};
196194

197195
fn one_test(description: &str, decoded: &str, encoded: &str) {
198196
match decode(encoded) {
@@ -203,9 +201,11 @@ mod tests {
203201
format!("Incorrect decoding of {:?}:\n {:?}\n!= {:?}\n{}",
204202
encoded, result.as_slice(), decoded, description))
205203
}
206-
}
204+
}
205+
206+
let dec_chars: ~[char] = decoded.chars().collect();
207207

208-
match encode(decoded.chars().to_owned_vec()) {
208+
match encode(dec_chars) {
209209
None => fail!("Encoding {:?} failed.", decoded),
210210
Some(result) => {
211211
assert!(result.as_slice() == encoded,

tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ fn parse_test_data(input: &str) -> ~[Test] {
8888
if line == "" || line[0] == ('#' as u8) {
8989
continue
9090
}
91-
let mut pieces = line.split(' ').to_owned_vec();
92-
let input = unescape(pieces.shift());
91+
let mut pieces: ~[&str] = line.split(' ').collect();
92+
let input = unescape(pieces.shift().unwrap());
9393
let mut test = Test {
9494
input: input,
9595
base: if pieces.is_empty() || pieces[0] == "" {
9696
tests[tests.len() - 1].base.to_owned()
9797
} else {
98-
unescape(pieces.shift())
98+
unescape(pieces.shift().unwrap())
9999
},
100100
scheme: None,
101101
username: ~"",

url.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
#![crate_id = "url#0.1"]
10+
#![crate_type = "lib"]
11+
#![feature(macro_rules)]
912

10-
#[crate_id = "url#0.1"];
11-
#[crate_type = "lib"];
12-
#[feature(macro_rules)];
13-
14-
15-
extern mod encoding;
13+
extern crate encoding;
1614

1715
#[cfg(test)]
18-
extern mod extra;
16+
extern crate serialize;
1917

2018
use std::str;
19+
use std::cmp;
20+
21+
use std::num::ToStrRadix;
2122

2223
use encoding::Encoding;
2324
use encoding::all::UTF_8;
@@ -228,7 +229,7 @@ impl Ipv6Address {
228229
continue
229230
}
230231
let start = i;
231-
let end = len.min(&(start + 4));
232+
let end = cmp::min(len, start + 4);
232233
let mut value = 0u16;
233234
while i < end {
234235
match from_hex(input[i]) {

0 commit comments

Comments
 (0)