コード例 #1
0
        private static string ProcessBoolExpression(string expression, bool debugMode)
        {
            if (debugMode)
            {
                TextProc.WriteProcess("preprocessing");
            }

            expression = ConstantsValidator.ValidateBoolExpression(expression);

            if (expression.Length == 0)
            {
                return("error (length)");
            }
            if (!CharValidator.Validate(CharValidator.ExpressionType.Bool, expression, debugMode))
            {
                return("error (chars)");
            }
            if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Round, expression, debugMode))
            {
                return("error (brackets)");
            }
            if (!SequenceValidator.ValidateBoolExpression(expression, debugMode))
            {
                return("error (sequence)");
            }

            if (debugMode)
            {
                TextProc.WriteProcess("processing");
            }

            return("" + BoolProcessor.GetBoolExpressionResolve(
                       BoolProcessor.ProcessBoolExpression(expression, debugMode), debugMode));
        }
コード例 #2
0
        public static void TestCharCalculator()
        {
            Console.Clear();
            ICalculator <char>      calc = new CharCalculator();
            INumberValidator <char> validator = new CharValidator();
            char value1, value2, result;

            while (true)
            {
                try
                {
                    Console.Write("Введите операцию (+ - * /): ");
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        return;
                    }
                    char operation = key.KeyChar;
                    if (operations.IndexOf(operation) == -1)
                    {
                        Console.WriteLine("\r\nА вот и не правильно");
                        continue;
                    }
                    Console.Write("\r\nВведите 2 символа разделенных пробелом: ");
                    if (!validator.ValidateTwoNumbers(Console.ReadLine(), out value1, out value2))
                    {
                        Console.WriteLine("Неверный ввод. Придется повторить");
                        continue;
                    }
                    switch (operation)
                    {
                    case '+':
                        result = calc.Add(value1, value2);
                        break;

                    case '-':
                        result = calc.Add(value1, value2);
                        break;

                    case '*':
                        result = calc.Multiply(value1, value2);
                        break;

                    case '/':
                        result = calc.Divide(value1, value2);
                        break;

                    default:
                        continue;
                    }
                    Console.WriteLine($"{ value1}{ operation}{ value2}={ result}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception {e.GetType().Name}: {e.Message}");
                }
            }
        }
コード例 #3
0
ファイル: TextInput.cs プロジェクト: bokhanhanna/PhonebookApp
 private void Insert(char newChar)
 {
     if (CharValidator.ValidateCharType(newChar, charType))
     {
         value.Insert(Cursor.X, newChar);
         Cursor.MoveRight();
     }
     else
     {
         ShowValidationHint(GetValidCharsMessage(charType));
     }
 }
コード例 #4
0
        private static string ProcessMatrixExpression(string expression, bool debugMode)
        {
            if (debugMode)
            {
                TextProc.WriteProcess("preprocessing");
            }

            expression = ConstantsValidator.ValidateMatrixExpression(expression);

            if (expression.Length == 0)
            {
                return("error (length)");
            }
            if (!CharValidator.Validate(CharValidator.ExpressionType.Matrix, expression, debugMode))
            {
                return("error (chars)");
            }
            if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Round, expression, debugMode))
            {
                return("error (brackets)");
            }
            if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Square, expression, debugMode))
            {
                return("error (brackets)");
            }
            if (!PointersValidator.Validate('.', expression, debugMode))
            {
                return("error (pointers)");
            }
            if (!SequenceValidator.ValidateMatrixExpression(expression, debugMode))
            {
                return("error (sequence)");
            }

            if (debugMode)
            {
                TextProc.WriteProcess("processing");
            }
            var separatedExpression = MatrixProcessor.GetExpressionSeparated(expression, debugMode);

            if (!MatrixValidator.Validate(separatedExpression, debugMode))
            {
                return("error (matrix)");
            }

            if (debugMode)
            {
                TextProc.WriteProcess("calculating");
            }
            return(MatrixProcessor.ResolveExpression(separatedExpression));
        }
コード例 #5
0
        private static string ProcessRegularExpression(string expression, bool debugMode)
        {
            if (debugMode)
            {
                TextProc.WriteProcess("preprocessing");
            }
            expression = ConstantsValidator.ValidateRegExpression(expression);

            if (expression.Length == 0)
            {
                return("error (length)");
            }
            if (!CharValidator.Validate(CharValidator.ExpressionType.Reg, expression, debugMode))
            {
                return("error (chars)");
            }
            if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Round, expression, debugMode))
            {
                return("error (brackets)");
            }
            if (!SequenceValidator.ValidateRegExpression(expression, debugMode))
            {
                return("error (sequence)");
            }
            if (!PointersValidator.Validate(',', expression, debugMode))
            {
                return("error (pointers)");
            }

            if (debugMode)
            {
                TextProc.WriteProcess("processing");
            }
            return("" + Processor.ResolveExpression(
                       Processor.GetExpressionSeparated(expression, debugMode)));
        }