Fix bug when the negate sign is before a space (#345)
* Ignore None characters while parsing the clipboard * reformat
This commit is contained in:
parent
8e1a14793a
commit
9728ccf119
@ -790,6 +790,12 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
|
|||||||
|
|
||||||
NumbersAndOperatorsEnum mappedNumOp = MapCharacterToButtonId(*it, canSendNegate);
|
NumbersAndOperatorsEnum mappedNumOp = MapCharacterToButtonId(*it, canSendNegate);
|
||||||
|
|
||||||
|
if (mappedNumOp == NumbersAndOperatorsEnum::None)
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (isFirstLegalChar || isPreviousOperator)
|
if (isFirstLegalChar || isPreviousOperator)
|
||||||
{
|
{
|
||||||
isFirstLegalChar = false;
|
isFirstLegalChar = false;
|
||||||
@ -811,74 +817,71 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mappedNumOp != NumbersAndOperatorsEnum::None)
|
switch (mappedNumOp)
|
||||||
{
|
{
|
||||||
switch (mappedNumOp)
|
// Opening parenthesis starts a new expression and pushes negation state onto the stack
|
||||||
|
case NumbersAndOperatorsEnum::OpenParenthesis:
|
||||||
|
negateStack.push_back(sendNegate);
|
||||||
|
sendNegate = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Closing parenthesis pops the negation state off the stack and sends it down to the calc engine
|
||||||
|
case NumbersAndOperatorsEnum::CloseParenthesis:
|
||||||
|
if (!negateStack.empty())
|
||||||
{
|
{
|
||||||
// Opening parenthesis starts a new expression and pushes negation state onto the stack
|
sendNegate = negateStack.back();
|
||||||
case NumbersAndOperatorsEnum::OpenParenthesis:
|
negateStack.pop_back();
|
||||||
negateStack.push_back(sendNegate);
|
canSendNegate = true;
|
||||||
sendNegate = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Closing parenthesis pops the negation state off the stack and sends it down to the calc engine
|
|
||||||
case NumbersAndOperatorsEnum::CloseParenthesis:
|
|
||||||
if (!negateStack.empty())
|
|
||||||
{
|
|
||||||
sendNegate = negateStack.back();
|
|
||||||
negateStack.pop_back();
|
|
||||||
canSendNegate = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Don't send a closing parenthesis if a matching opening parenthesis hasn't been sent already
|
|
||||||
sendCommand = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NumbersAndOperatorsEnum::Zero:
|
|
||||||
case NumbersAndOperatorsEnum::One:
|
|
||||||
case NumbersAndOperatorsEnum::Two:
|
|
||||||
case NumbersAndOperatorsEnum::Three:
|
|
||||||
case NumbersAndOperatorsEnum::Four:
|
|
||||||
case NumbersAndOperatorsEnum::Five:
|
|
||||||
case NumbersAndOperatorsEnum::Six:
|
|
||||||
case NumbersAndOperatorsEnum::Seven:
|
|
||||||
case NumbersAndOperatorsEnum::Eight:
|
|
||||||
case NumbersAndOperatorsEnum::Nine:
|
|
||||||
processedDigit = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NumbersAndOperatorsEnum::Add:
|
|
||||||
case NumbersAndOperatorsEnum::Subtract:
|
|
||||||
case NumbersAndOperatorsEnum::Multiply:
|
|
||||||
case NumbersAndOperatorsEnum::Divide:
|
|
||||||
isPreviousOperator = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (sendCommand)
|
|
||||||
{
|
{
|
||||||
sentEquals = (mappedNumOp == NumbersAndOperatorsEnum::Equals);
|
// Don't send a closing parenthesis if a matching opening parenthesis hasn't been sent already
|
||||||
Command cmdenum = ConvertToOperatorsEnum(mappedNumOp);
|
sendCommand = false;
|
||||||
m_standardCalculatorManager.SendCommand(cmdenum);
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// The CalcEngine state machine won't allow the negate command to be sent before any
|
case NumbersAndOperatorsEnum::Zero:
|
||||||
// other digits, so instead a flag is set and the command is sent after the first appropriate
|
case NumbersAndOperatorsEnum::One:
|
||||||
// command.
|
case NumbersAndOperatorsEnum::Two:
|
||||||
if (sendNegate)
|
case NumbersAndOperatorsEnum::Three:
|
||||||
|
case NumbersAndOperatorsEnum::Four:
|
||||||
|
case NumbersAndOperatorsEnum::Five:
|
||||||
|
case NumbersAndOperatorsEnum::Six:
|
||||||
|
case NumbersAndOperatorsEnum::Seven:
|
||||||
|
case NumbersAndOperatorsEnum::Eight:
|
||||||
|
case NumbersAndOperatorsEnum::Nine:
|
||||||
|
processedDigit = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NumbersAndOperatorsEnum::Add:
|
||||||
|
case NumbersAndOperatorsEnum::Subtract:
|
||||||
|
case NumbersAndOperatorsEnum::Multiply:
|
||||||
|
case NumbersAndOperatorsEnum::Divide:
|
||||||
|
isPreviousOperator = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendCommand)
|
||||||
|
{
|
||||||
|
sentEquals = (mappedNumOp == NumbersAndOperatorsEnum::Equals);
|
||||||
|
Command cmdenum = ConvertToOperatorsEnum(mappedNumOp);
|
||||||
|
m_standardCalculatorManager.SendCommand(cmdenum);
|
||||||
|
|
||||||
|
// The CalcEngine state machine won't allow the negate command to be sent before any
|
||||||
|
// other digits, so instead a flag is set and the command is sent after the first appropriate
|
||||||
|
// command.
|
||||||
|
if (sendNegate)
|
||||||
|
{
|
||||||
|
if (canSendNegate)
|
||||||
{
|
{
|
||||||
if (canSendNegate)
|
Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate);
|
||||||
{
|
m_standardCalculatorManager.SendCommand(cmdNegate);
|
||||||
Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate);
|
}
|
||||||
m_standardCalculatorManager.SendCommand(cmdNegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't send negate on a leading zero, so wait until the appropriate time to send it.
|
// Can't send negate on a leading zero, so wait until the appropriate time to send it.
|
||||||
if (NumbersAndOperatorsEnum::Zero != mappedNumOp && NumbersAndOperatorsEnum::Decimal != mappedNumOp)
|
if (NumbersAndOperatorsEnum::Zero != mappedNumOp && NumbersAndOperatorsEnum::Decimal != mappedNumOp)
|
||||||
{
|
{
|
||||||
sendNegate = false;
|
sendNegate = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user