public void askForInput()
        {
            Console.WriteLine("Please enter the path of dictionary file: ");
            string dictionaryFile = Console.ReadLine();

            Console.WriteLine("Please enter the start word: ");
            string startWord = Console.ReadLine();

            Console.WriteLine("Please enter the end word: ");
            string endWord = Console.ReadLine();

            Console.WriteLine("Please enter the path of the output file: ");
            string outputFile = Console.ReadLine();

            DictionaryFile = dictionaryFile;
            StartWord      = startWord;
            EndWord        = endWord;
            OutputFile     = outputFile;

            IsValid();

            if (IsValid() != true)
            {
                DictionaryFile.Remove(0);
                StartWord.Remove(0);
                EndWord.Remove(0);
                OutputFile.Remove(0);
                Console.WriteLine("False entries, please try again!");
            }
        }
示例#2
0
        public void CrossBoardPreprocessTest()
        {
            ICrossBoard cb = new CrossBoard(5, 5);

            for (int i = 0; i < 5; i++)
            {
                var sw = new StartWord();
                sw.StartX = i;
                sw.StartY = 0;
                cb.AddStartWord(sw);
                if (i > 0)
                {
                    sw.StartX = 0;
                    sw.StartY = i;
                    cb.AddStartWord(sw);
                }
                else
                {
                    sw.StartX = 2;
                    sw.StartY = 2;
                    cb.AddStartWord(sw);
                }
            }

            cb.Preprocess(new Dictionary(cb.MaxWordLength));
            Assert.Equal(8, cb.GetPatternCount());
        }
示例#3
0
        private static StartWord GetCharsToLeftOfCursor(TextArea textArea)
        {
            var doc         = textArea.Document;
            var caret       = textArea.Caret;
            var lineSegment = doc.GetLineSegment(caret.Line);

            var emptyWord = new StartWord("", caret.Line, caret.Column, 0, caret.Offset);

            // Caret is at the beginning of the line
            if (caret.Column == 0)
            {
                return(emptyWord);
            }

            var curWord = lineSegment.GetWord(caret.Column);

            // Caret is at the end of the line
            if (curWord == null)
            {
                return(emptyWord);
            }

            if (curWord.IsWhiteSpace)
            {
                curWord = GetPrevWord(caret, lineSegment, curWord);
            }

            Console.WriteLine("Cur word: \"{0}\"", curWord.Word);

            var prevWord = GetPrevWord(caret, lineSegment, curWord);

            // Caret is at the start of the current word - get the previous word
            if (caret.Offset == curWord.Offset)
            {
                // This should never happen
                if (prevWord == null)
                {
                    return(emptyWord);
                }

                var isSameSyntax = AreEqual(prevWord.SyntaxColor, curWord.SyntaxColor);

                // Caret is between two different syntax highlights
                if (!isSameSyntax)
                {
                    return(emptyWord);
                }

                curWord  = prevWord;
                prevWord = GetPrevWord(caret, lineSegment, curWord);
            }

            // Caret is in whitespace
            if (curWord.IsWhiteSpace)
            {
                return(emptyWord);
            }

            var selectionOffsetStart = curWord.Offset;
            var selectionLength      = caret.Offset - curWord.Offset;

            var startText = doc.GetText(selectionOffsetStart, selectionLength);

            if (prevWord != null)
            {
                var prevText = prevWord.Word;

                const string envVar      = "%";
                const string placeholder = "{";

                if (prevText.EndsWith(envVar))
                {
                    startText             = envVar + startText;
                    selectionOffsetStart -= envVar.Length;
                    selectionLength      += envVar.Length;
                }
                else if (prevText.EndsWith(placeholder))
                {
                    startText             = placeholder + startText;
                    selectionOffsetStart -= placeholder.Length;
                    selectionLength      += placeholder.Length;
                }
            }

            // Caret is in whitespace
            if (new Regex(@"\s+$").IsMatch(startText))
            {
                return(emptyWord);
            }

            Console.WriteLine("Starting text: \"{0}\"", startText);

            var selectionColumn = caret.Column - selectionLength;

            var startWord = new StartWord(startText, caret.Line, selectionColumn, selectionLength, selectionOffsetStart);

            return(startWord);
        }
示例#4
0
 public void AddStartWord(StartWord aStartWord)
 {
     _startWords.Add(aStartWord);
 }