Commit 197368d9 authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

ENH: Add optional argument to GetLineFromStream which can let the caller know...

ENH: Add optional argument to GetLineFromStream which can let the caller know whether there was a new line character at the end of the line that was just read
parent 42731475
...@@ -1616,12 +1616,17 @@ kwsys_std::string SystemTools::MakeCindentifier(const char* s) ...@@ -1616,12 +1616,17 @@ kwsys_std::string SystemTools::MakeCindentifier(const char* s)
// Due to a buggy stream library on the HP and another on Mac OSX, we // Due to a buggy stream library on the HP and another on Mac OSX, we
// need this very carefully written version of getline. Returns true // need this very carefully written version of getline. Returns true
// if any data were read before the end-of-file was reached. // if any data were read before the end-of-file was reached.
bool SystemTools::GetLineFromStream(kwsys_std::istream& is, kwsys_std::string& line) bool SystemTools::GetLineFromStream(kwsys_std::istream& is, kwsys_std::string& line,
bool *has_newline /* = 0 */)
{ {
const int bufferSize = 1024; const int bufferSize = 1024;
char buffer[bufferSize]; char buffer[bufferSize];
line = ""; line = "";
bool haveData = false; bool haveData = false;
if ( has_newline )
{
*has_newline = false;
}
// If no characters are read from the stream, the end of file has // If no characters are read from the stream, the end of file has
// been reached. // been reached.
...@@ -1635,6 +1640,10 @@ bool SystemTools::GetLineFromStream(kwsys_std::istream& is, kwsys_std::string& l ...@@ -1635,6 +1640,10 @@ bool SystemTools::GetLineFromStream(kwsys_std::istream& is, kwsys_std::string& l
// reached. // reached.
if(strlen(buffer) < static_cast<size_t>(is.gcount())) if(strlen(buffer) < static_cast<size_t>(is.gcount()))
{ {
if ( has_newline )
{
*has_newline = true;
}
break; break;
} }
......
...@@ -245,9 +245,11 @@ public: ...@@ -245,9 +245,11 @@ public:
* Read line from file. Make sure to get everything. Due to a buggy stream * Read line from file. Make sure to get everything. Due to a buggy stream
* library on the HP and another on Mac OSX, we need this very carefully * library on the HP and another on Mac OSX, we need this very carefully
* written version of getline. Returns true if any data were read before the * written version of getline. Returns true if any data were read before the
* end-of-file was reached. * end-of-file was reached. If the has_newline argument is specified, it will
* be true when the line read had a newline character.
*/ */
static bool GetLineFromStream(kwsys_std::istream& istr, kwsys_std::string& line); static bool GetLineFromStream(kwsys_std::istream& istr, kwsys_std::string& line,
bool* has_newline=0);
protected: protected:
// these two functions can be called from ConvertToOutputPath // these two functions can be called from ConvertToOutputPath
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment