Exemple #1
0
        /// <summary>
        /// Read token
        /// </summary>
        /// <returns>token read</returns>
        public Token ReadToken()
        {
            _firstTokenInGroup = false;
            LastToken          = CurrentToken;

            if (LastToken != null && LastToken.Type == RtfTokenType.GroupStart)
            {
                _firstTokenInGroup = true;
            }

            CurrentToken = _lex.NextToken();
            if (CurrentToken == null || CurrentToken.Type == RtfTokenType.Eof)
            {
                CurrentToken = null;
                return(null);
            }

            TokenCount++;

            if (CurrentToken.Type == RtfTokenType.GroupStart)
            {
                if (_layerStack.Count == 0)
                {
                    _layerStack.Push(new LayerInfo());
                }
                else
                {
                    var info = _layerStack.Peek();
                    _layerStack.Push(info.Clone());
                }
                Level++;
            }
            else if (CurrentToken.Type == RtfTokenType.GroupEnd)
            {
                if (_layerStack.Count > 0)
                {
                    _layerStack.Pop();
                }
                Level--;
            }

            if (EnableDefaultProcess)
            {
                DefaultProcess();
            }

            return(CurrentToken);
        }
Exemple #2
0
        /// <summary>
        /// Read token
        /// </summary>
        /// <returns>token read</returns>
        public Token ReadToken()
        {
            LastToken = CurrentToken;

            CurrentToken = _lex.NextToken();
            if (CurrentToken == null || CurrentToken.Type == RtfTokenType.Eof)
            {
                CurrentToken = null;
                return(null);
            }

            switch (CurrentToken.Type)
            {
            case RtfTokenType.GroupStart when _layerStack.Count == 0:
                _layerStack.Push(new LayerInfo());
                break;

            case RtfTokenType.GroupStart:
            {
                var info = _layerStack.Peek();
                _layerStack.Push(info.Clone());
                break;
            }

            case RtfTokenType.GroupEnd:
            {
                if (_layerStack.Count > 0)
                {
                    _layerStack.Pop();
                }
                break;
            }
            }

            DefaultProcess();

            return(CurrentToken);
        }