Skip to content

Commit 32e0ea8

Browse files
committed
---
yaml --- r: 44904 b: refs/heads/master c: 162c816 h: refs/heads/master v: v3
1 parent 1927b58 commit 32e0ea8

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a7de81ac3e559dcddfa9652d83457341a534a74d
2+
refs/heads/master: 162c816e3434b9368313acc8ef000bad3ccbc218
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/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)