Skip to content

Commit 23f4a92

Browse files
committed
---
yaml --- r: 50877 b: refs/heads/try c: 429b8a9 h: refs/heads/master i: 50875: f7ec38e v: v3
1 parent 6d26b26 commit 23f4a92

File tree

83 files changed

+394
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+394
-330
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: f7a2371c176663d59062ec5158f39faecba45768
5-
refs/heads/try: 059764779c7389bcea118d4c43cc243d185ec243
5+
refs/heads/try: 429b8a9b9e48925fa34b02b05568e630d78c855b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/compiletest/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use core::prelude::*;
1212

13-
#[deriving(Eq)]
13+
#[deriving_eq]
1414
pub enum mode {
1515
mode_compile_fail,
1616
mode_run_fail,

branches/try/src/libcore/cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait Eq {
3737
pure fn ne(&self, other: &Self) -> bool;
3838
}
3939

40-
#[deriving(Eq)]
40+
#[deriving_eq]
4141
pub enum Ordering { Less, Equal, Greater }
4242

4343
/// Trait for types that form a total order

branches/try/src/libcore/either.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use result;
1717
use vec;
1818

1919
/// The either type
20-
#[deriving(Eq)]
20+
#[deriving_eq]
2121
pub enum Either<T, U> {
2222
Left(T),
2323
Right(U)

branches/try/src/libcore/io.rs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub trait ReaderUtil {
9999
/// Read len bytes into a new vec.
100100
fn read_bytes(&self, len: uint) -> ~[u8];
101101

102-
/// Read up until a specified character (which is not returned) or EOF.
103-
fn read_until(&self, c: char) -> ~str;
102+
/// Read up until a specified character (which is optionally included) or EOF.
103+
fn read_until(&self, c: char, include: bool) -> ~str;
104104

105105
/// Read up until the first '\n' char (which is not returned), or EOF.
106106
fn read_line(&self) -> ~str;
@@ -126,6 +126,9 @@ pub trait ReaderUtil {
126126
/// Iterate over every line until the iterator breaks or EOF.
127127
fn each_line(&self, it: &fn(&str) -> bool);
128128

129+
/// Read all the lines of the file into a vector.
130+
fn read_lines(&self) -> ~[~str];
131+
129132
/// Read n (between 1 and 8) little-endian unsigned integer bytes.
130133
fn read_le_uint_n(&self, nbytes: uint) -> u64;
131134

@@ -219,11 +222,14 @@ impl<T:Reader> ReaderUtil for T {
219222
bytes
220223
}
221224

222-
fn read_until(&self, c: char) -> ~str {
225+
fn read_until(&self, c: char, include: bool) -> ~str {
223226
let mut bytes = ~[];
224227
loop {
225228
let ch = self.read_byte();
226229
if ch == -1 || ch == c as int {
230+
if include && ch == c as int {
231+
bytes.push(ch as u8);
232+
}
227233
break;
228234
}
229235
bytes.push(ch as u8);
@@ -232,7 +238,7 @@ impl<T:Reader> ReaderUtil for T {
232238
}
233239

234240
fn read_line(&self) -> ~str {
235-
self.read_until('\n')
241+
self.read_until('\n', false)
236242
}
237243

238244
fn read_chars(&self, n: uint) -> ~[char] {
@@ -306,7 +312,7 @@ impl<T:Reader> ReaderUtil for T {
306312
}
307313

308314
fn read_c_str(&self) -> ~str {
309-
self.read_until(0 as char)
315+
self.read_until(0 as char, false)
310316
}
311317

312318
fn read_whole_stream(&self) -> ~[u8] {
@@ -329,7 +335,29 @@ impl<T:Reader> ReaderUtil for T {
329335

330336
fn each_line(&self, it: &fn(s: &str) -> bool) {
331337
while !self.eof() {
332-
if !it(self.read_line()) { break; }
338+
// include the \n, so that we can distinguish an entirely empty
339+
// line read after "...\n", and the trailing empty line in
340+
// "...\n\n".
341+
let mut line = self.read_until('\n', true);
342+
343+
// blank line at the end of the reader is ignored
344+
if self.eof() && line.is_empty() { break; }
345+
346+
// trim the \n, so that each_line is consistent with read_line
347+
let n = str::len(line);
348+
if line[n-1] == '\n' as u8 {
349+
unsafe { str::raw::set_len(&mut line, n-1); }
350+
}
351+
352+
if !it(line) { break; }
353+
}
354+
}
355+
356+
fn read_lines(&self) -> ~[~str] {
357+
do vec::build |push| {
358+
for self.each_line |line| {
359+
push(str::from_slice(line));
360+
}
333361
}
334362
}
335363

@@ -630,7 +658,7 @@ pub pure fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
630658
pub enum FileFlag { Append, Create, Truncate, NoFlag, }
631659
632660
// What type of writer are we?
633-
#[deriving(Eq)]
661+
#[deriving_eq]
634662
pub enum WriterType { Screen, File }
635663
636664
// FIXME (#2004): Seekable really should be orthogonal.
@@ -1335,6 +1363,21 @@ mod tests {
13351363
}
13361364
}
13371365
1366+
#[test]
1367+
fn test_read_lines() {
1368+
do io::with_str_reader(~"a\nb\nc\n") |inp| {
1369+
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
1370+
}
1371+
1372+
do io::with_str_reader(~"a\nb\nc") |inp| {
1373+
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
1374+
}
1375+
1376+
do io::with_str_reader(~"") |inp| {
1377+
fail_unless!(inp.read_lines().is_empty());
1378+
}
1379+
}
1380+
13381381
#[test]
13391382
fn test_readchars_wide() {
13401383
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";

branches/try/src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use iter::{BaseIter, MutableIter};
5252
#[cfg(test)] use str;
5353

5454
/// The option type
55-
#[deriving(Eq)]
55+
#[deriving_eq]
5656
pub enum Option<T> {
5757
None,
5858
Some(T),

branches/try/src/libcore/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use option::{None, Option, Some};
2020
use str;
2121
use to_str::ToStr;
2222

23-
#[deriving(Eq)]
23+
#[deriving_eq]
2424
pub struct WindowsPath {
2525
host: Option<~str>,
2626
device: Option<~str>,
@@ -32,7 +32,7 @@ pub pure fn WindowsPath(s: &str) -> WindowsPath {
3232
GenericPath::from_str(s)
3333
}
3434

35-
#[deriving(Eq)]
35+
#[deriving_eq]
3636
pub struct PosixPath {
3737
is_absolute: bool,
3838
components: ~[~str],

branches/try/src/libcore/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use option::{None, Option, Some};
2020
use vec;
2121

2222
/// The result type
23-
#[deriving(Eq)]
23+
#[deriving_eq]
2424
pub enum Result<T, U> {
2525
/// Contains the successful result value
2626
Ok(T),

0 commit comments

Comments
 (0)