mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Trim the string when it exceeds the maximum allowed length in Standard mode
This commit is contained in:
parent
6a1c2e4bbf
commit
7068311643
2 changed files with 11 additions and 4 deletions
|
@ -307,11 +307,12 @@ bool CopyPasteManager::ExpressionRegExMatch(vector<wstring> operands, ViewMode m
|
|||
// or which will break conversion from string-to-ULL.
|
||||
wstring operandValue = SanitizeOperand(operand);
|
||||
|
||||
// If an operand exceeds the maximum length allowed, break and return.
|
||||
if (OperandLength(operandValue, mode, modeType, programmerNumberBase) > maxOperandLength)
|
||||
// If an operand exceeds the maximum length allowed, trim it to its allowed length.
|
||||
size_t OperandLen = OperandLength(operandValue, mode, modeType, programmerNumberBase);
|
||||
if (OperandLen > maxOperandLength)
|
||||
{
|
||||
expMatched = false;
|
||||
break;
|
||||
// Try to trim the length to allowed length
|
||||
TrimOperand(operandValue, OperandLen - maxOperandLength);
|
||||
}
|
||||
|
||||
// If maxOperandValue is set and the operandValue exceeds it, break and return.
|
||||
|
@ -339,6 +340,11 @@ bool CopyPasteManager::ExpressionRegExMatch(vector<wstring> operands, ViewMode m
|
|||
return expMatched;
|
||||
}
|
||||
|
||||
void CopyPasteManager::TrimOperand(std::wstring& operand, size_t exceededBy)
|
||||
{
|
||||
operand = operand.substr(0, operand.length() - exceededBy);
|
||||
}
|
||||
|
||||
pair<size_t, uint64_t> CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
|
||||
{
|
||||
size_t maxLength = 0;
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace CalculatorApp
|
|||
static size_t OperandLength(std::wstring operand, CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1);
|
||||
static size_t StandardScientificOperandLength(std::wstring operand);
|
||||
static size_t ProgrammerOperandLength(const std::wstring& operand, int numberBase);
|
||||
static void TrimOperand(std::wstring& operand, size_t exceededBy);
|
||||
|
||||
static constexpr size_t MaxStandardOperandLength = 16;
|
||||
static constexpr size_t MaxScientificOperandLength = 32;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue