From 59373451513b74a49295303c4f3926d3622c4937 Mon Sep 17 00:00:00 2001 From: Nicholas Baron Date: Tue, 26 Mar 2019 10:03:29 -0700 Subject: [PATCH] Improved readablity of OperandLength and StandardScientificOperandLength Moved to switch-case for OperandLength --- src/CalcViewModel/Common/CopyPasteManager.cpp | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/CalcViewModel/Common/CopyPasteManager.cpp b/src/CalcViewModel/Common/CopyPasteManager.cpp index 9b024691..ad9ee362 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.cpp +++ b/src/CalcViewModel/Common/CopyPasteManager.cpp @@ -459,34 +459,27 @@ bool CopyPasteManager::TryOperandToULL(const wstring& operand, int numberBase, u } size_t CopyPasteManager::OperandLength(wstring operand, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase) -{ - if (mode == ViewMode::Standard || mode == ViewMode::Scientific) - { - return StandardScientificOperandLength(operand); - } - else if (mode == ViewMode::Programmer) - { - return ProgrammerOperandLength(operand, programmerNumberBase); - } - else if (modeType == CategoryGroupType::Converter) - { +{ + if(modeType == CategoryGroupType::Converter) { return operand.length(); } - return 0; + switch(mode) { + case ViewMode::Standard: + case ViewMode::Scientific: + return StandardScientificOperandLength(operand); + + case ViewMode::Programmer: + return ProgrammerOperandLength(operand, programmerNumberBase); + + default: + return 0; + } } size_t CopyPasteManager::StandardScientificOperandLength(wstring operand) -{ - // Loop until a decimal is found or if the end is reached - bool hasDecimal = false; - for (size_t i = 0; i < operand.length() && !hasDecimal; i++) - { - if (operand[i] == L'.') - { - hasDecimal = true; - } - } +{ + const bool hasDecimal = operand.find('.') != std::wstring::npos; if (hasDecimal) {