Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wc: streaming --files0-from and other improvements
My original focus was on --files0-from, which should be processed as a stream rather than consumed into a list of files before processing. I accomplished this by separating most of the runtime configuration from arguments from definition of which files should be processed. A `Settings` now tracks which of `-[clLmw]` are specified. An `Inputs` describes whether stdin is implied by no arguments, if --files0-from is specified, or if there is a list of one or more files provided. `Inputs::try_iter` will create an `Iterator` that will handle any of those cases. Each `Input` (singular!) yielded is either stdin or a file name. --files0-from will now support non-UTF-8 filenames on Unix. Secondarily, I have attempted to reduce the number of String allocations that occur while printing the results. Now, unless a file name needs escaping, or an error occurs, no additional allocations should be necessary to print results. `print_stats` was the biggest abuser, allocating a `String` for each column before before being `join`'d into a `String` for the whole line. The `TitledWordCount` type is not necessary at all, which was another source of `String` allocation. I've made some effort to make more cases match GNU wc's output. Errors encountered processing `--files0-from` as well as any encountered processing files listed on the command line will be escaped more consistently like GNU wc. File names printed to the right of their stats will be less aggressively quoted, to match GNU wc, now only if they are not UTF-8 or if they contain a newline.
- Loading branch information