@@ -27,7 +27,7 @@ reset once it has been finished, so attempting to iterate on `[None,
27
27
None]` will only take input once unless `io::stdin().seek(0, SeekSet)`
28
28
is called between.
29
29
30
- The `pathify ` function handles converting a list of file paths as
30
+ The `make_path_option_vec ` function handles converting a list of file paths as
31
31
strings to the appropriate format, including the (optional) conversion
32
32
of `"-"` to `stdin`.
33
33
@@ -42,7 +42,7 @@ to handle any `FileInput` structs. E.g. a simple `cat` program
42
42
43
43
or a program that numbers lines after concatenating two files
44
44
45
- for input_vec_state(pathify ([~"a.txt", ~"b.txt"])) |line, state| {
45
+ for input_vec_state(make_path_option_vec ([~"a.txt", ~"b.txt"])) |line, state| {
46
46
io::println(fmt!("%u: %s", state.line_num,
47
47
line));
48
48
}
@@ -145,8 +145,14 @@ struct FileInput_ {
145
145
previous_was_newline : bool
146
146
}
147
147
148
- // XXX: remove this when Reader has &mut self. Should be removable via
149
- // "self.fi." -> "self." and renaming FileInput_. Documentation above
148
+
149
+ // FIXME #5723: remove this when Reader has &mut self.
150
+ // Removing it would mean giving read_byte in the Reader impl for
151
+ // FileInput &mut self, which in turn means giving most of the
152
+ // io::Reader trait methods &mut self. That can't be done right now
153
+ // because of io::with_bytes_reader and #5723.
154
+ // Should be removable via
155
+ // "self.fi" -> "self." and renaming FileInput_. Documentation above
150
156
// will likely have to be updated to use `let mut in = ...`.
151
157
pub struct FileInput {
152
158
fi : @mut FileInput_
@@ -194,7 +200,7 @@ impl FileInput {
194
200
*/
195
201
pub fn from_args ( ) -> FileInput {
196
202
let args = os:: args ( ) ;
197
- let pathed = pathify ( args. tail ( ) , true ) ;
203
+ let pathed = make_path_option_vec ( args. tail ( ) , true ) ;
198
204
FileInput :: from_vec ( pathed)
199
205
}
200
206
@@ -351,8 +357,7 @@ Convert a list of strings to an appropriate form for a `FileInput`
351
357
instance. `stdin_hyphen` controls whether `-` represents `stdin` or
352
358
a literal `-`.
353
359
*/
354
- // XXX: stupid, unclear name
355
- pub fn pathify ( vec : & [ ~str ] , stdin_hyphen : bool ) -> ~[ Option < Path > ] {
360
+ pub fn make_path_option_vec ( vec : & [ ~str ] , stdin_hyphen : bool ) -> ~[ Option < Path > ] {
356
361
vec. iter ( ) . map ( |str| {
357
362
if stdin_hyphen && "-" == * str {
358
363
None
@@ -410,7 +415,7 @@ pub fn input_vec_state(files: ~[Option<Path>],
410
415
#[ cfg( test) ]
411
416
mod test {
412
417
413
- use super :: { FileInput , pathify , input_vec, input_vec_state} ;
418
+ use super :: { FileInput , make_path_option_vec , input_vec, input_vec_state} ;
414
419
415
420
use std:: io;
416
421
use std:: uint;
@@ -426,22 +431,22 @@ mod test {
426
431
}
427
432
428
433
#[ test]
429
- fn test_pathify ( ) {
434
+ fn test_make_path_option_vec ( ) {
430
435
let strs = [ ~"some/path",
431
436
~"some/other/path"] ;
432
437
let paths = ~[ Some ( Path ( "some/path" ) ) ,
433
438
Some ( Path ( "some/other/path" ) ) ] ;
434
439
435
- assert_eq ! ( pathify ( strs, true ) , paths. clone( ) ) ;
436
- assert_eq ! ( pathify ( strs, false ) , paths) ;
440
+ assert_eq ! ( make_path_option_vec ( strs, true ) , paths. clone( ) ) ;
441
+ assert_eq ! ( make_path_option_vec ( strs, false ) , paths) ;
437
442
438
- assert_eq!( pathify ( [ ~"-"], true), ~[None]);
439
- assert_eq!(pathify ([~" -"], false), ~[Some(Path(" -"))]);
443
+ assert_eq!( make_path_option_vec ( [ ~"-"], true), ~[None]);
444
+ assert_eq!(make_path_option_vec ([~" -"], false), ~[Some(Path(" -"))]);
440
445
}
441
446
442
447
#[test]
443
448
fn test_fileinput_read_byte() {
444
- let filenames = pathify (vec::from_fn(
449
+ let filenames = make_path_option_vec (vec::from_fn(
445
450
3,
446
451
|i| fmt!(" tmp/lib-fileinput-test-fileinput-read-byte-%u. tmp", i)), true);
447
452
@@ -471,7 +476,7 @@ mod test {
471
476
472
477
#[test]
473
478
fn test_fileinput_read() {
474
- let filenames = pathify (vec::from_fn(
479
+ let filenames = make_path_option_vec (vec::from_fn(
475
480
3,
476
481
|i| fmt!(" tmp/lib-fileinput-test-fileinput-read-%u. tmp", i)), true);
477
482
@@ -492,7 +497,7 @@ mod test {
492
497
#[ test]
493
498
fn test_input_vec( ) {
494
499
let mut all_lines = ~[ ] ;
495
- let filenames = pathify ( vec:: from_fn(
500
+ let filenames = make_path_option_vec ( vec:: from_fn(
496
501
3 ,
497
502
|i| fmt!( "tmp/lib-fileinput-test-input-vec-%u.tmp" , i) ) , true ) ;
498
503
@@ -514,7 +519,7 @@ mod test {
514
519
515
520
#[ test]
516
521
fn test_input_vec_state( ) {
517
- let filenames = pathify ( vec:: from_fn(
522
+ let filenames = make_path_option_vec ( vec:: from_fn(
518
523
3 ,
519
524
|i| fmt!( "tmp/lib-fileinput-test-input-vec-state-%u.tmp" , i) ) , true ) ;
520
525
@@ -536,7 +541,7 @@ mod test {
536
541
537
542
#[ test]
538
543
fn test_empty_files( ) {
539
- let filenames = pathify ( vec:: from_fn(
544
+ let filenames = make_path_option_vec ( vec:: from_fn(
540
545
3 ,
541
546
|i| fmt!( "tmp/lib-fileinput-test-empty-files-%u.tmp" , i) ) , true ) ;
542
547
@@ -583,7 +588,7 @@ mod test {
583
588
584
589
#[test]
585
590
fn test_next_file() {
586
- let filenames = pathify (vec::from_fn(
591
+ let filenames = make_path_option_vec (vec::from_fn(
587
592
3,
588
593
|i| fmt!(" tmp/lib-fileinput-test-next-file-%u. tmp", i)),true);
589
594
@@ -614,7 +619,7 @@ mod test {
614
619
#[test]
615
620
#[should_fail]
616
621
fn test_input_vec_missing_file() {
617
- do input_vec(pathify ([~" this/file/doesnt/exist" ] , true ) ) |line| {
622
+ do input_vec(make_path_option_vec ([~" this/file/doesnt/exist" ] , true ) ) |line| {
618
623
println( line) ;
619
624
true
620
625
} ;
0 commit comments