// The line is a continuation of a previous one if:
// 1. it starts with space or horizontal tab;
// 2. it contains at least one token.
void CPatternsFileProcessor::ReadPattern( CTokens& patternTokens )
{
	patternTokens.clear();

	check_logic( file.is_open() );
	check_logic( !tokenizer.empty() );
	check_logic( !errorProcessor.HasCriticalErrors() );

	if( lineStartsWithSpace() ) {
		errorProcessor.AddError( CError(
			CLineSegment( 0, tokenizer.front()->Offset + 1 ),
			CSharedFileLine( line, lineNumber ),
			"a pattern definition is required to be"
			" written from the first character of the line" ) );
	}
	line.clear();

	// read rest lines of pattern
	while( file.good() ) {
		readLine();
		if( !lineStartsWithSpace() ) {
			break;
		}
		if( !tokenizeLine() ) {
			line.clear();
			break;
		}
	}

	patternTokens = move( tokenizer );
	skipEmptyLines();
}
void CPatternsFileProcessor::Open( const string& filename )
{
	check_logic( !errorProcessor.HasCriticalErrors() );
	reset();
	file.open( filename, ios::in | ios::binary );
	if( !file.is_open() ) {
		errorProcessor.AddError( CError( "the file not found", ES_CriticalError ) );
	} else if( !skipEmptyLines() && !errorProcessor.HasCriticalErrors() ) {
		errorProcessor.AddError( CError( "the file is empty", ES_CriticalError ) );
	}
}
示例#3
0
文件: buffer.cpp 项目: karelklic/wikt
void Buffer::skipEmptyLines()
{
  // Nothing to be skipped when we reached the end.
  if (endOfFile()) return;

  QString line = nextLine();
  if (line.trimmed().length() == 0)
  {
    skip(line.length() + 1);
    skipEmptyLines();
  }
}