Exemplo n.º 1
0
 //在GetLegalKeyWords结果的基础上,检查
 //1.是否有-c -w之一
 //2.是否-c -w都有
 //设置相应的flag,出现其一就把commandLegal = false
 public void CheckCommandCombinationLegal()
 {
     //check combination
     if (!(LegalKeyWordCommands.Contains("-c") || LegalKeyWordCommands.Contains("-w")))
     {
         try
         {
             throw new MissingMustContainedKeyWord();
         }
         catch (MissingMustContainedKeyWord e) {
             Console.WriteLine(e.Message + "--> Should at least contain one of -c or -w command");
             CommandLegal = false;
             MissingMustContainedKeyWord = true;
         }
     }
     else
     {
         if (LegalKeyWordCommands.Contains("-c") && LegalKeyWordCommands.Contains("-w"))
         {
             try
             {
                 throw new IllegalKeyWordCombination();
             }
             catch (IllegalKeyWordCombination e)
             {
                 Console.WriteLine(e.Message + "--> Should not contain both -c and -w command");
                 CommandLegal = false;
                 IllegalKeyWordCombination = true;
             }
         }
     }
 }
Exemplo n.º 2
0
        //将不合法的关键词去掉,结果存入LegalKeyWordCommands
        //例 "-c -w -x -t [ a -r" --> "-c -w -t a -r",若有不合法关键字,CommandLegal = false
        public void GetLegalKeyWords()
        {
            string ExtraExceptionMessage = "-->";

            foreach (string Word in InitialCommands)
            {
                if (Command.LegalCommands.Contains(Word))
                {
                    LegalKeyWordCommands.Add(Word);
                }
                else
                {
                    bool IllegalKeywordException = false;
                    if (Word.Length == 1)
                    {
                        char CharWord = Char.Parse(Word);
                        //rule out start or end char setting
                        if (!((CharWord >= 'a' && CharWord <= 'z') || (CharWord >= 'A' && CharWord <= 'Z')))
                        {
                            IllegalKeywordException = true;
                            ExtraExceptionMessage  += CharWord.ToString() + " ";
                        }
                        else
                        {
                            LegalKeyWordCommands.Add(CharWord.ToString());
                        }
                    }
                    else
                    {
                        IllegalKeywordException = true;
                        ExtraExceptionMessage  += Word + " ";
                    }
                    if (IllegalKeywordException)
                    {
                        try
                        {
                            throw new IllegalCommandKeyWord();
                        }
                        catch (IllegalCommandKeyWord e)
                        {
                            Console.WriteLine(e.Message + ExtraExceptionMessage);
                            CommandLegal          = false;
                            IllegalCommandKeyWord = true;
                        }
                    }
                }
            }
        }