Improved readablity of OperandLength and StandardScientificOperandLength

Moved to switch-case for OperandLength
This commit is contained in:
Nicholas Baron 2019-03-26 10:03:29 -07:00
commit 5937345151

View file

@ -460,33 +460,26 @@ bool CopyPasteManager::TryOperandToULL(const wstring& operand, int numberBase, u
size_t CopyPasteManager::OperandLength(wstring operand, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase) size_t CopyPasteManager::OperandLength(wstring operand, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase)
{ {
if (mode == ViewMode::Standard || mode == ViewMode::Scientific) if(modeType == CategoryGroupType::Converter) {
{
return StandardScientificOperandLength(operand);
}
else if (mode == ViewMode::Programmer)
{
return ProgrammerOperandLength(operand, programmerNumberBase);
}
else if (modeType == CategoryGroupType::Converter)
{
return operand.length(); 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) size_t CopyPasteManager::StandardScientificOperandLength(wstring operand)
{ {
// Loop until a decimal is found or if the end is reached const bool hasDecimal = operand.find('.') != std::wstring::npos;
bool hasDecimal = false;
for (size_t i = 0; i < operand.length() && !hasDecimal; i++)
{
if (operand[i] == L'.')
{
hasDecimal = true;
}
}
if (hasDecimal) if (hasDecimal)
{ {