zelenski/stanford-cpp-library

Inconsistency between `readEntireFile` overloads and `readEntireStream` overloads.

htiek opened this issue · 3 comments

htiek commented

Currently, there are two versions of the readEntireFile function. One takes in the name of a file and returns a std::string with the contents. The other takes in a filename and a Vector<string>&, then populates the Vector<string>.

There's also a readEntireStream function. It has two overloads. One returns a string containing the contents of the file. The other takes in a string by reference and overwrites it with the contents of the stream.

We should consider making these functions more consistent with one another. Perhaps all versions should work with Vector<string>? Or, alternatively, maybe we should remove the ones that take reference parameters and have them just return strings? From there the client could stringSplit them apart if that's what they want.

Agreed! All of filelib/strlib API could use a thorough pass to cleanup and curate. Also could use a readBinaryFile (for huffman) that doesn't open in text mode and get unwanted newline conversion

b8afba3
The API is now
Vector<string> readLines(ifstream)
string readEntire(ifstream)
These two cover majority of the common use cases.