public IEnumerator <object> ProcessInput(string text)
        {
            string[] words = text.Split(' ');
            if (words.Length < 1)
            {
                return(null);
            }
            string firstWord = words[0].ToLower();

            _LastPrompt = false;

            var cmdGenerator = _Commands.FindByKeyStart(firstWord);
            KeyValueReference <string, CommandHandler> cmd;

            try {
                cmd = cmdGenerator.First();
            }
            catch (InvalidOperationException) {
                SendMessage("Hmm... that doesn't make any sense. Do you need some <help>?");
                SendPrompt();
                return(null);
            }
            // Populate the first word with the real name of the command.
            words[0] = cmd.Key;

            return(cmd.Value.Execute(this, words));
        }
Exemple #2
0
        public void GetStartKeys()
        {
            var AT = new AlphaTrie <string>();

            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 0);

            AT.Insert("a", "word");
            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 1);

            AT.Insert("ab", "word");
            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 2);

            AT.Insert("aba", "word");
            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 3);

            AT.Insert("abb", "word");
            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 4);

            AT.Insert("abab", "word");
            Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 5);


            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 0);

            AT.Insert("bbbb", "word");
            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 1);

            AT.Insert("bbba", "word");
            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 2);

            AT.Insert("bbb", "word");
            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 3);

            AT.Insert("bb", "word");
            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 4);

            AT.Insert("b", "word");
            Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 5);
        }