Applied C++ Core Guideline NR.2

Added some auto deductions.
One C-cast changed to a static_cast.
This commit is contained in:
Nicholas Baron 2019-03-25 22:54:51 -07:00
commit b0998501e2

View file

@ -106,19 +106,16 @@ task<String^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupTyp
int CopyPasteManager::ClipboardTextFormat() int CopyPasteManager::ClipboardTextFormat()
{ {
int result = -1; const auto dataPackageView = Clipboard::GetContent();
auto dataPackageView = Clipboard::GetContent();
for (int i = 0; i < RTL_NUMBER_OF(supportedFormats); i++) for (int i = 0; i < RTL_NUMBER_OF(supportedFormats); i++)
{ {
if (dataPackageView->Contains(supportedFormats[i])) if (dataPackageView->Contains(supportedFormats[i]))
{ {
result = i; return i;
break;
} }
} }
return result; return -1;
} }
String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode mode, int programmerNumberBase, int bitLengthType) String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode mode, int programmerNumberBase, int bitLengthType)
@ -394,7 +391,7 @@ pair<size_t, uint64_t> CopyPasteManager::GetMaxOperandLengthAndValue(ViewMode mo
unsigned int signBit = (programmerNumberBase == DecBase) ? 1 : 0; unsigned int signBit = (programmerNumberBase == DecBase) ? 1 : 0;
maxLength = (size_t)ceil((bitLength - signBit) / bitsPerDigit); maxLength = static_cast<size_t>(ceil((bitLength - signBit) / bitsPerDigit));
maxValue = UINT64_MAX >> (MaxProgrammerBitLength - (bitLength - signBit)); maxValue = UINT64_MAX >> (MaxProgrammerBitLength - (bitLength - signBit));
} }
else if (modeType == CategoryGroupType::Converter) else if (modeType == CategoryGroupType::Converter)
@ -459,21 +456,20 @@ 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)
{ {
size_t len = 0;
if (mode == ViewMode::Standard || mode == ViewMode::Scientific) if (mode == ViewMode::Standard || mode == ViewMode::Scientific)
{ {
len = StandardScientificOperandLength(operand); return StandardScientificOperandLength(operand);
} }
else if (mode == ViewMode::Programmer) else if (mode == ViewMode::Programmer)
{ {
len = ProgrammerOperandLength(operand, programmerNumberBase); return ProgrammerOperandLength(operand, programmerNumberBase);
} }
else if (modeType == CategoryGroupType::Converter) else if (modeType == CategoryGroupType::Converter)
{ {
len = operand.length(); return operand.length();
} }
return len; return 0;
} }
size_t CopyPasteManager::StandardScientificOperandLength(wstring operand) size_t CopyPasteManager::StandardScientificOperandLength(wstring operand)
@ -484,6 +480,7 @@ size_t CopyPasteManager::StandardScientificOperandLength(wstring operand)
if (operand[i] == L'.') if (operand[i] == L'.')
{ {
hasDecimal = true; hasDecimal = true;
break;
} }
} }
@ -541,7 +538,7 @@ size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int num
// Detect if there is a suffix and subtract its length // Detect if there is a suffix and subtract its length
// Check suffixes first to allow e.g. "0b" to result in length 1 (value 0), rather than length 0 (no value). // Check suffixes first to allow e.g. "0b" to result in length 1 (value 0), rather than length 0 (no value).
for (const wstring& suffix : suffixes) for (const auto& suffix : suffixes)
{ {
if (len < suffix.length()) if (len < suffix.length())
{ {
@ -556,7 +553,7 @@ size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int num
} }
// Detect if there is a prefix and subtract its length // Detect if there is a prefix and subtract its length
for (const wstring& prefix : prefixes) for (const auto& prefix : prefixes)
{ {
if (len < prefix.length()) if (len < prefix.length())
{ {