コード例 #1
0
        public static bool InputValid(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentNullException(paramName: nameof(input));
            }

            if (input.Length <= 2)
            {
                return(false);
            }

            if (!RegValidExpressChar.IsMatch(input))
            {
                return(false);
            }

            if (!BracketHelper.IsBracketComplete(input))
            {
                return(false);
            }

            // If the input ends with a binary operator then it is not a valid input to mages and the Interpret function would throw an exception.
            string trimmedInput = input.TrimEnd();

            if (trimmedInput.EndsWith('+') || trimmedInput.EndsWith('-') || trimmedInput.EndsWith('*') || trimmedInput.EndsWith('|') || trimmedInput.EndsWith('\\') || trimmedInput.EndsWith('^') || trimmedInput.EndsWith('=') || trimmedInput.EndsWith('&'))
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: CalculateHelper.cs プロジェクト: zhiles/PowerToys
        public static bool InputValid(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentNullException(paramName: nameof(input));
            }

            if (input.Length <= 2)
            {
                return(false);
            }

            if (!RegValidExpressChar.IsMatch(input))
            {
                return(false);
            }

            if (!BracketHelper.IsBracketComplete(input))
            {
                return(false);
            }

            return(true);
        }