diff --git a/src/CalcViewModel/Common/CopyPasteManager.cpp b/src/CalcViewModel/Common/CopyPasteManager.cpp index c8f9c5f0..4fc643c1 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.cpp +++ b/src/CalcViewModel/Common/CopyPasteManager.cpp @@ -307,11 +307,12 @@ bool CopyPasteManager::ExpressionRegExMatch(vector 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 operands, ViewMode m return expMatched; } +void CopyPasteManager::TrimOperand(std::wstring& operand, size_t exceededBy) +{ + operand = operand.substr(0, operand.length() - exceededBy); +} + pair CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType) { size_t maxLength = 0; diff --git a/src/CalcViewModel/Common/CopyPasteManager.h b/src/CalcViewModel/Common/CopyPasteManager.h index 1da4af4e..965bbd3e 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.h +++ b/src/CalcViewModel/Common/CopyPasteManager.h @@ -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;