bool CUtlInplaceBuffer::InplaceGetLinePtr( char **ppszInBufferPtr, int *pnLineLength ) { Assert( IsText() && !ContainsCRLF() ); int nLineLen = PeekLineLength(); if ( nLineLen <= 1 ) { SeekGet( SEEK_TAIL, 0 ); return false; } -- nLineLen; // because it accounts for putting a terminating null-character char *pszLine = ( char * ) const_cast< void * >( PeekGet() ); SeekGet( SEEK_CURRENT, nLineLen ); // Set the out args if ( ppszInBufferPtr ) *ppszInBufferPtr = pszLine; if ( pnLineLength ) *pnLineLength = nLineLen; return true; }
//----------------------------------------------------------------------------- // Reads up to and including the first \n //----------------------------------------------------------------------------- void CUtlBufferEditor::GetLine( char* pLine, int nMaxChars ) { Assert( IsText() && !ContainsCRLF() ); if ( !IsValid() ) { *pLine = 0; return; } if ( nMaxChars == 0 ) { nMaxChars = INT_MAX; } // Remember, this *includes* the null character // It will be 0, however, if the buffer is empty. int nLen = PeekLineLength(); if ( nLen == 0 ) { *pLine = 0; m_Error |= GET_OVERFLOW; return; } // Strip off the terminating NULL if ( nLen <= nMaxChars ) { Get( pLine, nLen - 1 ); pLine[ nLen - 1 ] = 0; } else { Get( pLine, nMaxChars - 1 ); pLine[ nMaxChars - 1 ] = 0; SeekGet( SEEK_CURRENT, nLen - 1 - nMaxChars ); } }