Add readStream helper in libsolutil

This commit is contained in:
Alex Beregszaszi 2021-05-13 19:24:44 +01:00
parent b24f2e0215
commit 1a3feff9ec
2 changed files with 7 additions and 4 deletions

View File

@ -68,14 +68,14 @@ string solidity::util::readFileAsString(string const& _file)
return readFile<string>(_file);
}
string solidity::util::readStandardInput()
string solidity::util::readStream(istream& _stream)
{
string ret;
while (!cin.eof())
while (!_stream.eof())
{
string tmp;
// NOTE: this will read until EOF or NL
getline(cin, tmp);
getline(_stream, tmp);
ret.append(tmp);
ret.append("\n");
}

View File

@ -36,8 +36,11 @@ namespace solidity::util
/// If the file is empty, returns an empty string.
std::string readFileAsString(std::string const& _file);
/// Returns the contents of the stream (until EOF).
std::string readStream(std::istream& _stream);
/// Retrieve and returns the contents of standard input (until EOF).
std::string readStandardInput();
inline std::string readStandardInput() { return readStream(std::cin); }
/// Retrieve and returns a character from standard input (without waiting for EOL).
int readStandardInputChar();