Exemplo n.º 1
0
        public bool GetOperation(byte[] buffer, int bufferLength, ref int currentBufferPosition, bool mustMatchPosition, out int token)
        {
            int originalPosition = currentBufferPosition;
            TrieEvaluator <Token>        evaluator = new TrieEvaluator <Token>(this);
            TrieEvaluationDriver <Token> driver    = new TrieEvaluationDriver <Token>(evaluator);

            if (mustMatchPosition)
            {
                bufferLength = Math.Min(bufferLength, currentBufferPosition + MaxLength);
            }

            TerminalLocation <Token> location = driver.Evaluate(buffer, bufferLength, true, 0, ref currentBufferPosition);

            if (location != null && (!mustMatchPosition || (currentBufferPosition - location.Terminal.Length == originalPosition)))
            {
                token = location.Terminal.Index;
                currentBufferPosition = location.Location + location.Terminal.End - location.Terminal.Start + 1;
                return(true);
            }

            if (mustMatchPosition)
            {
                currentBufferPosition = originalPosition;
            }
            else
            {
                currentBufferPosition = bufferLength - MaxLength + 1;
            }

            token = -1;
            return(false);
        }
Exemplo n.º 2
0
        public bool GetOperation(byte[] buffer, int bufferLength, ref int currentBufferPosition, out int token)
        {
            int originalPosition = currentBufferPosition;
            TrieEvaluator <Token>        evaluator = new TrieEvaluator <Token>(this);
            TrieEvaluationDriver <Token> driver    = new TrieEvaluationDriver <Token>(evaluator);
            TerminalLocation <Token>     location  = driver.Evaluate(buffer, bufferLength, true, 0, ref currentBufferPosition);

            if (location != null && currentBufferPosition - location.Terminal.Length == originalPosition)
            {
                token = location.Terminal.Index;
                currentBufferPosition = location.Location + location.Terminal.End - location.Terminal.Start + 1;
                return(true);
            }

            currentBufferPosition = originalPosition;
            token = -1;
            return(false);
        }