예제 #1
0
        public EncodingConfig(EngineConfig config, Encoding encoding)
        {
            _variableKeys          = new List <byte[]>();
            Encoding               = encoding;
            LineEndings            = new SimpleTrie();
            Whitespace             = new SimpleTrie();
            WhitespaceOrLineEnding = new SimpleTrie();
            Variables              = new SimpleTrie();

            foreach (string token in config.LineEndings)
            {
                byte[] tokenBytes = encoding.GetBytes(token);
                LineEndings.AddToken(tokenBytes);
                WhitespaceOrLineEnding.AddToken(tokenBytes);
            }

            foreach (string token in config.Whitespaces)
            {
                byte[] tokenBytes = encoding.GetBytes(token);
                Whitespace.AddToken(tokenBytes);
                WhitespaceOrLineEnding.AddToken(tokenBytes);
            }

            _values = new Func <object> [config.Variables.Count];
            ExpandVariables(config, encoding);
        }
        public IOperation GetOperation(Encoding encoding, IProcessorState processorState)
        {
            byte[] ifToken  = encoding.GetBytes(_ifToken);
            byte[] endToken = encoding.GetBytes(_endIfToken);

            List <byte[]> tokens = new List <byte[]>
            {
                ifToken,
                endToken
            };

            SimpleTrie trie = new SimpleTrie();

            trie.AddToken(ifToken, 0);
            trie.AddToken(endToken, 1);

            int elseIfTokenIndex = -1;

            if (!string.IsNullOrEmpty(_elseToken))
            {
                byte[] elseToken = encoding.GetBytes(_elseToken);
                trie.AddToken(elseToken, tokens.Count);
                tokens.Add(elseToken);
            }

            if (!string.IsNullOrEmpty(_elseIfToken))
            {
                byte[] elseIfToken = encoding.GetBytes(_elseIfToken);
                elseIfTokenIndex = tokens.Count;
                trie.AddToken(elseIfToken, elseIfTokenIndex);
                tokens.Add(elseIfToken);
            }

            return(new Impl(this, tokens, elseIfTokenIndex, trie));
        }
        public IOperation GetOperation(Encoding encoding, IProcessorState processorState)
        {
            byte[]     tokenBytes      = encoding.GetBytes(StartToken);
            byte[]     endTokenBytes   = encoding.GetBytes(EndToken);
            SimpleTrie endTokenMatcher = new SimpleTrie();

            endTokenMatcher.AddToken(endTokenBytes);
            return(new Impl(tokenBytes, endTokenMatcher, this));
        }