private bool SkipWhiteSpaces() { var start = _position; //move to next real character for (; _position < _text.Length && char.IsWhiteSpace(_text, _position); _position++) { } //end of file if (_position >= _text.Length) { return(true); } //if the header has already started and we're not in an open region, check if there was more than one NewLine if (!_started || _regionStarts.Count != 0) { return(false); } var firstNewLine = NewLineManager.NextLineEndPositionInformation(_text, start, _position - start); if (firstNewLine == null) { return(false); } var afterFirstNewLine = firstNewLine.Index + firstNewLine.LineEndLength; var nextNewLine = NewLineManager.NextLineEndPosition(_text, afterFirstNewLine, _position - afterFirstNewLine); //more than one NewLine (= at least one empty line) return(nextNewLine > 0); }
private bool HandleToken(string token) { if (token == null) { return(false); } if (_lineComment != null && token.StartsWith(_lineComment)) { SetStarted(); //proceed to end of line _position = NewLineManager.NextLineEndPosition(_text, _position - token.Length + _lineComment.Length); UpdatePositionIfEndOfFile(); return(true); } if (_beginComment != null && token.StartsWith(_beginComment)) { SetStarted(); _position = _text.IndexOf(_endComment, _position - token.Length + _beginComment.Length, StringComparison.Ordinal); if (_position < 0) { throw new ParseException(); } _position += _endComment.Length; return(true); } if (_beginRegion != null && token == _beginRegion) { SetStarted(); _regionStarts.Push(_position - _beginRegion.Length); _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } if (_endRegion != null && token == _endRegion) { SetStarted(); if (_regionStarts.Count == 0) { throw new ParseException(); } _regionStarts.Pop(); _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } if (_endRegion != null && _endRegion.Contains(token)) { SetStarted(); var firstPart = token; token = GetToken(); if (firstPart + " " + token == _endRegion) { if (_regionStarts.Count == 0) { throw new ParseException(); } _regionStarts.Pop(); } _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } _position -= token.Length; return(false); }