X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=blobdiff_plain;f=src%2Fgromacs%2Futility%2Fstringstream.cpp;fp=src%2Fgromacs%2Futility%2Fstringstream.cpp;h=77e2388ea2487cb7067790e9d13cf1e1c3b49687;hb=daf67f84ef938f01eb9b08133b32337200b25511;hp=7a93d3472c8d752fcc2c462f6d5ce04575d4d65e;hpb=96da5ad95b303ed9b1b1e7df0ad4fbdf2c160ee2;p=alexxy%2Fgromacs.git diff --git a/src/gromacs/utility/stringstream.cpp b/src/gromacs/utility/stringstream.cpp index 7a93d3472c..77e2388ea2 100644 --- a/src/gromacs/utility/stringstream.cpp +++ b/src/gromacs/utility/stringstream.cpp @@ -45,6 +45,9 @@ #include +#include "gromacs/utility/arrayref.h" +#include "gromacs/utility/stringutil.h" + namespace gmx { @@ -57,4 +60,40 @@ void StringOutputStream::close() { } +StringInputStream::StringInputStream(const std::string &input) + : input_(input), pos_(0) +{ +} + +StringInputStream::StringInputStream(ConstArrayRef const &input) + : input_(joinStrings(input.begin(), input.end(), "\n")), pos_(0) +{ + input_.append("\n"); +} + +bool StringInputStream::readLine(std::string *line) +{ + if (pos_ == input_.size()) + { + line->clear(); + return false; + } + else + { + size_t newpos = input_.find("\n", pos_); + if (newpos == std::string::npos) + { + newpos = input_.size(); + } + else + { + // To include the newline as well! + newpos += 1; + } + line->assign(input_.substr(pos_, newpos-pos_)); + pos_ = newpos; + return true; + } +} + } // namespace gmx