CStreamLineReader::EEOLStyle CStreamLineReader::x_AdvanceEOLCRLF(void) { if (m_AutoEOL) { EEOLStyle style = x_AdvanceEOLSimple('\n', '\r'); if (style == eEOL_mixed) { // found an embedded CR m_EOLStyle = eEOL_cr; } else if (style != eEOL_crlf) { m_EOLStyle = eEOL_lf; } } else { string extra; NcbiGetline(*m_Stream, m_Line, '\n', &m_LastReadSize); while ( !AtEOF() && !NStr::EndsWith(m_Line, "\r") ) { SIZE_TYPE extra_count; m_Line += '\n'; NcbiGetline(*m_Stream, extra, '\n', &extra_count); m_Line += extra; m_LastReadSize += extra_count + 1; } if (NStr::EndsWith(m_Line, "\r")) { m_Line.resize(m_Line.size() - 1); } } return m_EOLStyle; }
String Stream::ReadLine(void) { String strRet; char c; do { // read 1 character Read(&c, sizeof(char)); // if at EOF if(AtEOF()) { // we're done here break; } // skip \r if(c == '\r') { //WARNING: This can potentially cause problems on certain operating systems // that work with \r _only_ as a newline character. We should incorporate // strm_nlmNewLineMode with this in a future version. continue; } // if it's not the terminator if(c != '\n') { // he'll be back strRet += c; } } while(c != '\n'); // done, return return strRet; }
// throws char * void CTStream::GetLine_t(char *strBuffer, SLONG slBufferSize, char cDelimiter /*='\n'*/ ) { // check parameters ASSERT(strBuffer!=NULL && slBufferSize>0); // check that the stream can be read ASSERT(IsReadable()); // letters slider INDEX iLetters = 0; // test if EOF reached if(AtEOF()) { ThrowF_t(TRANS("EOF reached, file %s"), (const char *) strm_strStreamDescription); } // get line from istream FOREVER { char c; Read_t(&c, 1); if(AtEOF()) { // cut off strBuffer[ iLetters] = 0; break; } // don't read "\r" characters but rather act like they don't exist if( c != '\r') { strBuffer[ iLetters] = c; // stop reading when delimiter loaded if( strBuffer[ iLetters] == cDelimiter) { // convert delimiter to zero strBuffer[ iLetters] = 0; // jump over delimiter //Seek_t(1, SD_CUR); break; } // jump to next destination letter iLetters++; } // test if maximum buffer lenght reached if( iLetters==slBufferSize) { return; } } }
char Stream::ReadUntil(String &strOut, const String &strCharacters) { String ret; char ccc = '\0'; while(!AtEOF()) { char cc = ReadChar(); if(strCharacters.Contains(cc)) { ccc = cc; break; } ret += cc; } strOut = ret; return ccc; }