Utilities used by tsv-utils applications. InputFieldReordering, BufferedOututRange, and a several others.

Utilities in this file:

  • InputFieldReordering - A class that creates a reordered subset of fields from an input line. Fields in the subset are accessed by array indicies. This is especially useful when processing the subset in a specific order, such as the order listed on the command-line at run-time.
  • BufferedOutputRange - An OutputRange with an internal buffer used to buffer output. Intended for use with stdout, it is a significant performance benefit.
  • bufferedByLine - An input range that reads from a File handle line by line. It is similar to the standard library method std.stdio.File.byLine, but quite a bit faster. This is achieved by reading in larger blocks and buffering.
  • joinAppend - A function that performs a join, but appending the join output to an output stream. It is a performance improvement over using join or joiner with writeln.
  • getTsvFieldValue - A convenience function when only a single value is needed from an input line.
  • Field-lists: parseFieldList, makeFieldListOptionHandler - Helper functions for parsing field-lists entered on the command line.
  • throwIfWindowsNewlineOnUnix - A utility for Unix platform builds to detecting Windows newlines in input.

Copyright (c) 2015-2019, eBay Software Foundation Initially written by Jon Degenhardt



alias AllowFieldNumZero = Flag!"allowFieldNumZero"

No.allowFieldNumZero parameter controls whether zero is a valid field. This is used by makeFieldListOptionHander and parseFieldList.

alias ConvertToZeroBasedIndex = Flag!"convertToZeroBasedIndex"

No.convertToZeroBasedIndex parameter controls whether field numbers are converted to zero-based indices by makeFieldListOptionHander and parseFieldList.

alias EnablePartialLines = Flag!"enablePartialLines"

Flag used by the InputFieldReordering template.

alias NewlineWasRemoved = Flag!"newlineWasRemoved"

No.newlineWasRemoved is a template parameter to throwIfWindowsNewlineOnUnix. A Yes value indicates the Unix newline was already removed, as might be done via std.File.byLine or similar mechanism.


class InputFieldReordering(C, EnablePartialLines partialLinesOk = EnablePartialLines.no)

InputFieldReordering - Move select fields from an input line to an output array, reordering along the way.


auto bufferedByLine(File file)

bufferedByLine is a performance enhancement over std.stdio.File.byLine. It works by reading a large buffer from the input stream rather than just a single line.

T getTsvFieldValue(const C[] line, size_t fieldIndex, C delim)

getTsvFieldValue extracts the value of a single field from a delimited text string.

OutputRange joinAppend(InputRange inputRange, ref OutputRange outputRange, E delimiter)

joinAppend performs a join operation on an input range, appending the results to an output range.

OptionHandlerDelegate makeFieldListOptionHandler(ref T[] fieldsArray)

makeFieldListOptionHandler creates a std.getopt option hander for processing field lists entered on the command line. A field list is as defined by parseFieldList.

auto parseFieldList(string fieldList, char delim = ',')

parseFieldList lazily generates a range of fields numbers from a 'field-list' string.

void throwIfWindowsNewlineOnUnix(const char[] line, const char[] filename, size_t lineNum)

throwIfWindowsLineNewlineOnUnix is used to throw an exception if a Windows/DOS line ending is found on a build compiled for a Unix platform. This is used by the TSV Utilities to detect Window/DOS line endings and terminate processing with an error message to the user.


struct BufferedOutputRange(OutputTarget)

BufferedOutputRange is a performance enhancement over writing directly to an output stream. It holds a File open for write or an OutputRange. Ouput is accumulated in an internal buffer and written to the output stream as a block.