Skip to content

Commit 4c85174

Browse files
committed
---
yaml --- r: 46687 b: refs/heads/auto c: 162c816 h: refs/heads/master i: 46685: b839de9 46683: 1ecf8d4 46679: 6abc048 46671: 6d24817 46655: 3653215 v: v3
1 parent d0145fd commit 4c85174

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
@@ -14,4 +14,4 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: a7de81ac3e559dcddfa9652d83457341a534a74d
17+
refs/heads/auto: 162c816e3434b9368313acc8ef000bad3ccbc218

branches/auto/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)