Skip to content

Commit 178fedb

Browse files
committed
---
yaml --- r: 48096 b: refs/heads/incoming c: 162c816 h: refs/heads/master v: v3
1 parent e79e589 commit 178fedb

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 2a8fb58d79e685d5ca07b039badcf2ae3ef077ea
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: a7de81ac3e559dcddfa9652d83457341a534a74d
9+
refs/heads/incoming: 162c816e3434b9368313acc8ef000bad3ccbc218
1010
refs/heads/dist-snap: 8b98e5a296d95c5e832db0756828e5bec31c6f50
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/io.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ pub trait ReaderUtil {
7878
/// Read len bytes into a new vec.
7979
fn read_bytes(&self, len: uint) -> ~[u8];
8080

81+
/// Read up until a specified character (which is not returned) or EOF.
82+
fn read_until(&self, c: char) -> ~str;
83+
8184
/// Read up until the first '\n' char (which is not returned), or EOF.
8285
fn read_line(&self) -> ~str;
8386

@@ -181,16 +184,22 @@ impl<T:Reader> ReaderUtil for T {
181184
bytes
182185
}
183186

184-
fn read_line(&self) -> ~str {
187+
fn read_until(&self, c: char) -> ~str {
185188
let mut bytes = ~[];
186189
loop {
187190
let ch = self.read_byte();
188-
if ch == -1 || ch == 10 { break; }
191+
if ch == -1 || ch == c as int {
192+
break;
193+
}
189194
bytes.push(ch as u8);
190195
}
191196
str::from_bytes(bytes)
192197
}
193198

199+
fn read_line(&self) -> ~str {
200+
self.read_until('\n')
201+
}
202+
194203
fn read_chars(&self, n: uint) -> ~[char] {
195204
// returns the (consumed offset, n_req), appends characters to &chars
196205
fn chars_from_bytes<T:Reader>(bytes: &~[u8], chars: &mut ~[char])
@@ -262,12 +271,7 @@ impl<T:Reader> ReaderUtil for T {
262271
}
263272

264273
fn read_c_str(&self) -> ~str {
265-
let mut bytes: ~[u8] = ~[];
266-
loop {
267-
let ch = self.read_byte();
268-
if ch < 1 { break; } else { bytes.push(ch as u8); }
269-
}
270-
str::from_bytes(bytes)
274+
self.read_until(0 as char)
271275
}
272276

273277
fn read_whole_stream(&self) -> ~[u8] {

0 commit comments

Comments
 (0)