예제 #1
0
파일: History.cpp 프로젝트: rrps/calculator
void CHistoryCollector::AddOpndToHistory(wstring_view numStr, Rational const& rat, bool fRepetition)
{
    std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
    // Check for negate
    bool fNegative = (numStr[0] == L'-');
    bool fSciFmt = false;
    bool fDecimal = false;

    for (size_t i = (fNegative ? 1 : 0); i < numStr.length(); i++)
    {
        if (numStr[i] == m_decimalSymbol)
        {
            IFT(commands->Append(IDC_PNT));
            if (!fSciFmt)
            {
                fDecimal = true;
            }
        }
        else if (numStr[i] == L'e')
        {
            IFT(commands->Append(IDC_EXP));
            fSciFmt = true;
        }
        else if (numStr[i] == L'-')
        {
            IFT(commands->Append(IDC_SIGN));
        }
        else if (numStr[i] == L'+')
        {
            // Ignore.
        }
        // Number
        else
        {
            int num = static_cast<int>(numStr[i]) - ASCII_0;
            num += IDC_0;
            IFT(commands->Append(num));
        }
    }

    auto operandCommand = std::make_shared<COpndCommand>(commands, fNegative, fDecimal, fSciFmt);
    operandCommand->Initialize(rat);
    int iCommandEnd = AddCommand(operandCommand);
    m_lastOpStartIndex = IchAddSzToEquationSz(numStr, iCommandEnd);

    if (fRepetition)
    {
        SetExpressionDisplay();
    }
    m_bLastOpndBrace = false;
    m_lastBinOpStartIndex = -1;
}
예제 #2
0
파일: History.cpp 프로젝트: rrps/calculator
//Update the commands corresponding to the passed string Number
std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
{
    std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
    // Check for negate
    bool fNegative = (numStr[0] == L'-');

    for (size_t i = (fNegative ? 1 : 0); i < numStr.length(); i++)
    {
        if (numStr[i] == m_decimalSymbol)
        {
            IFT(commands->Append(IDC_PNT));
        }
        else if (numStr[i] == L'e')
        {
            IFT(commands->Append(IDC_EXP));
        }
        else if (numStr[i] == L'-')
        {
            IFT(commands->Append(IDC_SIGN));
        }
        else if (numStr[i] == L'+')
        {
            // Ignore.
        }
        // Number
        else
        {
            int num = static_cast<int>(numStr[i]) - ASCII_0;
            num += IDC_0;
            IFT(commands->Append(num));
        }
    }

    // If the number is negative, append a sign command at the end.
    if (fNegative)
    {
        IFT(commands->Append(IDC_SIGN));
    }
    return commands;
}
예제 #3
0
파일: MinGW32.cpp 프로젝트: coldzhang/YSLib
string
WCSToMBCS(wstring_view sv, unsigned cp)
{
	return sv.length() != 0 ? WCSToMBCS(CheckNonnegativeScalar<int>(
		sv.length()), sv.data(), cp) : string();
}