Fixes #202 This PR fixes code style for the project files. The Problem Different files in the project use different code style. That is not consistent and leads to harder maintenance of the project. Description of the changes: Have investigated and determined the most used code style across the given codebase Have configured IDE and applied code style to all project files. Have crafted clang-formatter config. see https://clang.llvm.org/docs/ClangFormat.html https://clang.llvm.org/docs/ClangFormatStyleOptions.html Some cases were fixed manually How changes were validated: manual/ad-hoc testing, automated testing All tests pass as before because these are only code style changes. Additional Please review, and let me know if I have any mistake in the code style. In case of any mistake, I will change the configuration and re-apply it to the project.
81 lines
3.1 KiB
C++
81 lines
3.1 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "pch.h"
|
|
#include "CalcViewModel/Common/AppResourceProvider.h"
|
|
#include "CalcViewModel/Common/LocalizationSettings.h"
|
|
#include "BitFlipAutomationNameConverter.h"
|
|
|
|
using namespace CalculatorApp::Common;
|
|
using namespace CalculatorApp::Converters;
|
|
using namespace Platform;
|
|
using namespace std;
|
|
using namespace Windows::ApplicationModel::Resources;
|
|
using namespace Windows::Foundation;
|
|
using namespace Windows::UI::Xaml::Interop;
|
|
|
|
// returns automationName in form "Nth bit Value zero/one" depending if bit is set/unset at corresponding index of binary display
|
|
Object ^ BitFlipAutomationNameConverter::Convert(_In_ Object ^ value, TypeName targetType, _In_ Object ^ parameter, _In_ String ^ language)
|
|
{
|
|
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
|
|
// initialising the updated display with 64 bits of zeros
|
|
wstring updatedBinaryDisplay(64, L'0');
|
|
|
|
const auto& localizationSettings = LocalizationSettings::GetInstance();
|
|
wchar_t ch0 = localizationSettings.GetDigitSymbolFromEnUsDigit('0');
|
|
wchar_t ch1 = localizationSettings.GetDigitSymbolFromEnUsDigit('1');
|
|
|
|
String ^ indexName = resourceLoader.GetResourceString(static_cast<String ^>(parameter));
|
|
String ^ bitName = resourceLoader.GetResourceString(L"BitAutomationName");
|
|
String ^ valueName = resourceLoader.GetResourceString(L"ValueAutomationName");
|
|
String ^ zero = resourceLoader.GetResourceString(L"BinaryZeroValueAutomationName");
|
|
String ^ one = resourceLoader.GetResourceString(L"BinaryOneValueAutomationName");
|
|
if ((value != nullptr) && (parameter != nullptr))
|
|
{
|
|
wstring binaryDisplay = (static_cast<String ^>(value))->Data();
|
|
wstring indexString = (static_cast<String ^>(parameter))->Data();
|
|
wstringstream converter;
|
|
converter << indexString;
|
|
unsigned int index;
|
|
converter >> index;
|
|
unsigned int binaryLength = 0;
|
|
|
|
// remove all the characters except 0 and 1 from the array.
|
|
for (wchar_t bit : binaryDisplay)
|
|
{
|
|
if ((bit == ch1) || (bit == ch0))
|
|
{
|
|
updatedBinaryDisplay[binaryLength++] = bit;
|
|
}
|
|
if (binaryLength == 63)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
// return if binaryDisplay is empty
|
|
if (binaryLength == 0)
|
|
{
|
|
return (indexName + bitName + valueName + zero);
|
|
}
|
|
|
|
// if index is more than the length of binary display return automation name with zero
|
|
if (index >= binaryLength)
|
|
{
|
|
return (indexName + bitName + valueName + zero);
|
|
}
|
|
// if bit is set return automation name with one else return zero
|
|
if (updatedBinaryDisplay[binaryLength - index - 1] == ch1)
|
|
{
|
|
return (indexName + bitName + valueName + one);
|
|
}
|
|
}
|
|
return (indexName + bitName + valueName + zero);
|
|
}
|
|
|
|
Object ^ BitFlipAutomationNameConverter::ConvertBack(_In_ Object ^ value, TypeName targetType, _In_ Object ^ parameter, _In_ String ^ language)
|
|
{
|
|
return value;
|
|
}
|