Skip to content

Commit 760a45c

Browse files
committed
---
yaml --- r: 89886 b: refs/heads/master c: b4197ae h: refs/heads/master v: v3
1 parent c86fb63 commit 760a45c

File tree

3 files changed

+74
-49
lines changed

3 files changed

+74
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ed34cd1e3cc85252b398f33e6b9a90f9bd462b4d
2+
refs/heads/master: b4197aeed670acd855c21c0b66c87eed0919c219
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8

trunk/src/libextra/url.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ fn query_from_str(rawquery: &str) -> Query {
364364
return query;
365365
}
366366

367+
/**
368+
* Converts an instance of a URI `Query` type to a string.
369+
*
370+
* # Example
371+
*
372+
* ```rust
373+
* let query = ~[(~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")];
374+
* println(query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
375+
* ```
376+
*/
367377
pub fn query_to_str(query: &Query) -> ~str {
368378
let mut strvec = ~[];
369379
for kv in query.iter() {
Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,79 @@
1-
// xfail-test reading from os::args()[1] - bogus!
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
210

3-
use std::cast::transmute;
4-
use std::from_str::FromStr;
5-
use std::libc::{STDOUT_FILENO, c_int, fdopen, fputc};
6-
use std::os;
11+
use std::io::buffered::BufferedWriter;
712

8-
static ITER: uint = 50;
13+
struct DummyWriter;
14+
impl Writer for DummyWriter {
15+
fn write(&mut self, _: &[u8]) {}
16+
}
17+
18+
static ITER: int = 50;
919
static LIMIT: f64 = 2.0;
1020

1121
fn main() {
12-
unsafe {
13-
let w: i32 = FromStr::from_str(os::args()[1]).unwrap();
14-
let h = w;
15-
let mut byte_acc: i8 = 0;
16-
let mut bit_num: i32 = 0;
17-
18-
println!("P4\n{} {}", w, h);
22+
let args = std::os::args();
23+
let (w, mut out) = if args.len() < 2 {
24+
println("Test mode: do not dump the image because it's not utf8, \
25+
which interferes with the test runner.");
26+
(1000, ~DummyWriter as ~Writer)
27+
} else {
28+
(from_str(args[1]).unwrap(),
29+
~BufferedWriter::new(std::io::stdout()) as ~Writer)
30+
};
31+
let h = w;
32+
let mut byte_acc = 0u8;
33+
let mut bit_num = 0;
1934

20-
let mode = "w";
21-
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));
35+
writeln!(out, "P4\n{} {}", w, h);
2236

23-
for y in range(0i32, h) {
24-
let y = y as f64;
25-
for x in range(0i32, w) {
26-
let mut Zr = 0f64;
27-
let mut Zi = 0f64;
28-
let mut Tr = 0f64;
29-
let mut Ti = 0f64;
30-
let Cr = 2.0 * (x as f64) / (w as f64) - 1.5;
31-
let Ci = 2.0 * (y as f64) / (h as f64) - 1.0;
37+
for y in range(0, h) {
38+
let y = y as f64;
39+
for x in range(0, w) {
40+
let mut z_r = 0f64;
41+
let mut z_i = 0f64;
42+
let mut t_r = 0f64;
43+
let mut t_i = 0f64;
44+
let c_r = 2.0 * (x as f64) / (w as f64) - 1.5;
45+
let c_i = 2.0 * (y as f64) / (h as f64) - 1.0;
3246

33-
for _ in range(0i32, ITER as i32) {
34-
if Tr + Ti > LIMIT * LIMIT {
35-
break;
36-
}
37-
38-
Zi = 2.0*Zr*Zi + Ci;
39-
Zr = Tr - Ti + Cr;
40-
Tr = Zr * Zr;
41-
Ti = Zi * Zi;
47+
for _ in range(0, ITER) {
48+
if t_r + t_i > LIMIT * LIMIT {
49+
break;
4250
}
4351

44-
byte_acc <<= 1;
45-
if Tr + Ti <= LIMIT * LIMIT {
46-
byte_acc |= 1;
47-
}
52+
z_i = 2.0 * z_r * z_i + c_i;
53+
z_r = t_r - t_i + c_r;
54+
t_r = z_r * z_r;
55+
t_i = z_i * z_i;
56+
}
4857

49-
bit_num += 1;
58+
byte_acc <<= 1;
59+
if t_r + t_i <= LIMIT * LIMIT {
60+
byte_acc |= 1;
61+
}
5062

51-
if bit_num == 8 {
52-
fputc(byte_acc as c_int, stdout);
53-
byte_acc = 0;
54-
bit_num = 0;
55-
} else if x == w - 1 {
56-
byte_acc <<= 8 - w%8;
57-
fputc(byte_acc as c_int, stdout);
58-
byte_acc = 0;
59-
bit_num = 0;
60-
}
63+
bit_num += 1;
64+
65+
if bit_num == 8 {
66+
out.write_u8(byte_acc);
67+
byte_acc = 0;
68+
bit_num = 0;
69+
} else if x == w - 1 {
70+
byte_acc <<= 8 - w % 8;
71+
out.write_u8(byte_acc);
72+
byte_acc = 0;
73+
bit_num = 0;
6174
}
6275
}
6376
}
77+
78+
out.flush();
6479
}

0 commit comments

Comments
 (0)