Пример #1
0
    private string SubContent(string content)
    {
        if (content == errorInfo)
        {
            return(content);
        }

        if (content.Length == 1)
        {
            bufferStr  = num_zero.ToString();
            bufferType = CalculatorData.GetKeyTypeByValue(num_zero);
            return(num_zero.ToString());
        }

        Stack <char> characters = new Stack <char>(content.ToCharArray());

        characters.Pop();

        char Pop_Char = characters.Peek();

        if (Pop_Char == num_zero)
        {
            Pop_Char = magic_value;
        }

        bufferStr  = Pop_Char.ToString();
        bufferType = CalculatorData.GetKeyTypeByValue(Pop_Char);

        var outCharacters = characters.ToArray();

        Array.Reverse(outCharacters);

        return(new string(outCharacters));
    }
Пример #2
0
    private double Execute()
    {
        operatorsStack = new Stack <char>();
        numbersStack   = new Stack <double>();

        var bufferNumString = "";

        var operations = equation.ToCharArray();

        foreach (var operation in operations)
        {
            var type = CalculatorData.GetKeyTypeByValue(operation);
            var name = CalculatorData.GetKeyNameByValue(operation);

            switch (type)
            {
            case KeyType.NumberKey:
            case KeyType.NumberPointKey:
                bufferNumString += operation;
                break;

            case KeyType.OperatorKey:
            case KeyType.BacketLeftKey:
            case KeyType.BacketRightKey:
                if (bufferNumString != "")
                {
                    InputNumberStack(bufferNumString);
                    bufferNumString = "";
                }
                InputOperatorStack(type, name);
                break;
            }
        }

        if (bufferNumString != "")
        {
            InputNumberStack(bufferNumString);
            bufferNumString = "";
        }

        var result = OutputResult();

        return(result);
    }
Пример #3
0
    private bool IsReguler()
    {
        var bufferType = KeyType.None;

        var bracketLeft_Num  = 0;
        var bracketRight_Num = 0;

        var charactors = equation.ToCharArray();

        foreach (var c in charactors)
        {
            var newType = CalculatorData.GetKeyTypeByValue(c);

            Debug.Log("bufferType is " + bufferType);
            Debug.Log("currentType is " + newType);

            if (newType == KeyType.BacketLeftKey)
            {
                bracketLeft_Num++;
            }
            if (newType == KeyType.BacketRightKey)
            {
                bracketRight_Num++;
            }

            switch (bufferType)
            {
            case KeyType.None:
                if (newType != KeyType.NumberKey && newType != KeyType.BacketLeftKey)
                {
                    return(false);
                }
                break;

            case KeyType.NumberKey:
                if (newType == KeyType.BacketLeftKey)
                {
                    return(false);
                }
                break;

            case KeyType.NumberPointKey:
                if (newType != KeyType.NumberKey)
                {
                    return(false);
                }
                break;

            case KeyType.OperatorKey:
                if (newType != KeyType.NumberKey && newType != KeyType.BacketLeftKey)
                {
                    return(false);
                }
                break;

            case KeyType.BacketLeftKey:
                if (newType != KeyType.NumberKey)
                {
                    return(false);
                }
                break;

            case KeyType.BacketRightKey:
                if (newType != KeyType.OperatorKey)
                {
                    return(false);
                }
                break;
            }

            bufferType = newType;
        }

        if (bufferType == KeyType.BacketLeftKey || bufferType == KeyType.OperatorKey)
        {
            return(false);
        }

        if (bracketLeft_Num != bracketRight_Num)
        {
            return(false);
        }

        return(true);
    }