From 197368d9e7890cf4bcb36d40cb15413a8209aaca Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Mon, 7 Jul 2003 17:45:51 -0400 Subject: [PATCH] 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 --- Source/kwsys/SystemTools.cxx | 11 ++++++++++- Source/kwsys/SystemTools.hxx.in | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 038d2fafb..04009a3ec 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -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 // need this very carefully written version of getline. Returns true // 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; char buffer[bufferSize]; line = ""; bool haveData = false; + if ( has_newline ) + { + *has_newline = false; + } // If no characters are read from the stream, the end of file has // been reached. @@ -1635,6 +1640,10 @@ bool SystemTools::GetLineFromStream(kwsys_std::istream& is, kwsys_std::string& l // reached. if(strlen(buffer) < static_cast(is.gcount())) { + if ( has_newline ) + { + *has_newline = true; + } break; } diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index c59529f6a..a0c0d3162 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -245,9 +245,11 @@ public: * 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 * 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: // these two functions can be called from ConvertToOutputPath