diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp index 027eed3..a3fa093 100644 --- a/src/CalcViewModel/ApplicationViewModel.cpp +++ b/src/CalcViewModel/ApplicationViewModel.cpp @@ -152,7 +152,7 @@ void ApplicationViewModel::OnModeChanged() } auto resProvider = AppResourceProvider::GetInstance(); - CategoryName = resProvider->GetResourceString(NavCategory::GetNameResourceKey(m_mode)); + CategoryName = resProvider.GetResourceString(NavCategory::GetNameResourceKey(m_mode)); // Cast mode to an int in order to save it to app data. // Save the changed mode, so that the new window launches in this mode. diff --git a/src/CalcViewModel/Common/AppResourceProvider.cpp b/src/CalcViewModel/Common/AppResourceProvider.cpp index b843d55..a75a375 100644 --- a/src/CalcViewModel/Common/AppResourceProvider.cpp +++ b/src/CalcViewModel/Common/AppResourceProvider.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" @@ -14,9 +14,9 @@ AppResourceProvider::AppResourceProvider() m_cEngineStringResLoader = ResourceLoader::GetForViewIndependentUse(L"CEngineStrings"); } -AppResourceProvider ^ AppResourceProvider::GetInstance() +AppResourceProvider& AppResourceProvider::GetInstance() { - static AppResourceProvider ^ s_instance = ref new AppResourceProvider(); + static AppResourceProvider s_instance; return s_instance; } diff --git a/src/CalcViewModel/Common/AppResourceProvider.h b/src/CalcViewModel/Common/AppResourceProvider.h index be429a1..8876fb9 100644 --- a/src/CalcViewModel/Common/AppResourceProvider.h +++ b/src/CalcViewModel/Common/AppResourceProvider.h @@ -1,14 +1,14 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once namespace CalculatorApp { - public ref class AppResourceProvider sealed + class AppResourceProvider { public: - static AppResourceProvider ^ GetInstance(); + static AppResourceProvider& GetInstance(); Platform::String ^ GetResourceString(_In_ Platform::String ^ key); Platform::String ^ GetCEngineString(_In_ Platform::String ^ key); diff --git a/src/CalcViewModel/Common/CalculatorDisplay.cpp b/src/CalcViewModel/Common/CalculatorDisplay.cpp index 5cf8afb..3a4a544 100644 --- a/src/CalcViewModel/Common/CalculatorDisplay.cpp +++ b/src/CalcViewModel/Common/CalculatorDisplay.cpp @@ -9,7 +9,6 @@ using namespace CalculatorApp; using namespace CalculationManager; -using namespace Platform; using namespace std; CalculatorDisplay::CalculatorDisplay() @@ -32,7 +31,7 @@ void CalculatorDisplay::SetPrimaryDisplay(_In_ const wstring& displayStringValue { if (auto calcVM = m_callbackReference.Resolve()) { - calcVM->SetPrimaryDisplay(StringReference(displayStringValue.c_str()), isError); + calcVM->SetPrimaryDisplay(displayStringValue, isError); } } } diff --git a/src/CalcViewModel/Common/CopyPasteManager.cpp b/src/CalcViewModel/Common/CopyPasteManager.cpp index f67d005..f3a9759 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.cpp +++ b/src/CalcViewModel/Common/CopyPasteManager.cpp @@ -15,7 +15,7 @@ using namespace Windows::Foundation; using namespace Windows::System; using namespace Windows::ApplicationModel::DataTransfer; -StringReference PasteErrorString(L"NoOp"); +String ^ CopyPasteManager::supportedFormats[] = { StandardDataFormats::Text }; static const wstring c_validBasicCharacterSet = L"0123456789+-.e"; static const wstring c_validStandardCharacterSet = c_validBasicCharacterSet + L"*/"; @@ -66,7 +66,7 @@ void CopyPasteManager::CopyToClipboard(String ^ stringToCopy) Clipboard::SetContent(dataPackage); } -IAsyncOperation ^ CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType) +task CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType) { // Retrieve the text in the clipboard auto dataPackageView = Clipboard::GetContent(); @@ -76,29 +76,36 @@ IAsyncOperation ^ CopyPasteManager::GetStringToPaste(ViewMode mode, Ca //-- add support to allow pasting for expressions like .2 , -.2 //-- add support to allow pasting for expressions like 1.3e12(as of now we allow 1.3e+12) - return create_async([dataPackageView, mode, modeType, programmerNumberBase, bitLengthType] { - return create_task(dataPackageView->GetTextAsync(::StandardDataFormats::Text)) - .then( - [mode, modeType, programmerNumberBase, bitLengthType](String ^ pastedText) { - return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType); - }, - task_continuation_context::use_arbitrary()); - }); + return create_task((dataPackageView->GetTextAsync(::StandardDataFormats::Text))) + .then( + [mode, modeType, programmerNumberBase, bitLengthType](String ^ pastedText) { + return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType); + }, + task_continuation_context::use_arbitrary()); } -bool CopyPasteManager::HasStringToPaste() +int CopyPasteManager::ClipboardTextFormat() { - return Clipboard::GetContent()->Contains(StandardDataFormats::Text); + const auto dataPackageView = Clipboard::GetContent(); + + for (int i = 0; i < RTL_NUMBER_OF(supportedFormats); i++) + { + if (dataPackageView->Contains(supportedFormats[i])) + { + return i; + } + } + return -1; } String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, BitLength bitLengthType) { - return ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType); + return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType); } // return "NoOp" if pastedText is invalid else return pastedText -String - ^ CopyPasteManager::ValidatePasteExpression( + +String ^ CopyPasteManager::ValidatePasteExpression( String ^ pastedText, ViewMode mode, CategoryGroupType modeType, @@ -109,14 +116,16 @@ String { // return NoOp to indicate don't paste anything. TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed"); - return PasteErrorString; + return StringReference(PasteErrorString); } + wstring pasteExpression = pastedText->Data(); + // Get english translated expression - String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pastedText); + String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression); // Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333 - wstring pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data()); + pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data()); // If the last character is an = sign, remove it from the pasteExpression to allow evaluating the result on paste. if (!pasteExpression.empty() && pasteExpression.back() == L'=') @@ -130,7 +139,7 @@ String if (operands.empty()) { // return NoOp to indicate don't paste anything. - return PasteErrorString; + return StringReference(PasteErrorString); } if (modeType == CategoryGroupType::Converter) @@ -142,10 +151,10 @@ String if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType)) { TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode"); - return PasteErrorString; + return StringReference(PasteErrorString); } - return pastedText; + return ref new String(pastedText->Data()); } vector CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode) @@ -584,8 +593,3 @@ wstring CopyPasteManager::RemoveUnwantedCharsFromWstring(const wstring& input) wchar_t unWantedChars[] = { L' ', L',', L'"', 165, 164, 8373, 36, 8353, 8361, 8362, 8358, 8377, 163, 8364, 8234, 8235, 8236, 8237 }; return Utils::RemoveUnwantedCharsFromWstring(input, unWantedChars, 18); } - -bool CopyPasteManager::IsErrorMessage(Platform::String ^ message) -{ - return message == PasteErrorString; -} diff --git a/src/CalcViewModel/Common/CopyPasteManager.h b/src/CalcViewModel/Common/CopyPasteManager.h index 1b2f0bb..9571cdb 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.h +++ b/src/CalcViewModel/Common/CopyPasteManager.h @@ -19,19 +19,24 @@ namespace CalculatorApp inline constexpr auto OctBase = 7; inline constexpr auto BinBase = 8; - public ref class CopyPasteManager sealed + class CopyPasteManager { public: static void CopyToClipboard(Platform::String ^ stringToCopy); - static Windows::Foundation::IAsyncOperation^ GetStringToPaste( + static concurrency::task GetStringToPaste( CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, - int programmerNumberBase, - CalculatorApp::Common::BitLength bitLengthType); - static bool HasStringToPaste(); - static bool IsErrorMessage(Platform::String ^ message); + int programmerNumberBase = -1, + CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown); + static bool HasStringToPaste() + { + return ClipboardTextFormat() >= 0; + } + + static constexpr auto PasteErrorString = L"NoOp"; private: + static int ClipboardTextFormat(); static Platform::String ^ ValidatePasteExpression( Platform::String ^ pastedText, @@ -79,6 +84,8 @@ namespace CalculatorApp static constexpr size_t MaxExponentLength = 4; static constexpr size_t MaxProgrammerBitLength = 64; + static Platform::String ^ supportedFormats[]; + friend class CalculatorUnitTests::CopyPasteManagerTest; }; } diff --git a/src/CalcViewModel/Common/KeyboardShortcutManager.cpp b/src/CalcViewModel/Common/KeyboardShortcutManager.cpp index 8990d5e..8b2ca30 100644 --- a/src/CalcViewModel/Common/KeyboardShortcutManager.cpp +++ b/src/CalcViewModel/Common/KeyboardShortcutManager.cpp @@ -519,7 +519,7 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs auto navView = buttons.first->second.Resolve(); auto appViewModel = safe_cast(navView->DataContext); appViewModel->Mode = ViewMode::Date; - auto categoryName = AppResourceProvider::GetInstance()->GetResourceString(L"DateCalculationModeText"); + auto categoryName = AppResourceProvider::GetInstance().GetResourceString(L"DateCalculationModeText"); appViewModel->CategoryName = categoryName; auto menuItems = static_cast ^>(navView->MenuItemsSource); diff --git a/src/CalcViewModel/Common/LocalizationService.cpp b/src/CalcViewModel/Common/LocalizationService.cpp index 7963037..f314336 100644 --- a/src/CalcViewModel/Common/LocalizationService.cpp +++ b/src/CalcViewModel/Common/LocalizationService.cpp @@ -94,16 +94,16 @@ LocalizationService::LocalizationService(_In_ const wchar_t * const overridedLan m_locale = locale(""); } auto resourceLoader = AppResourceProvider::GetInstance(); - m_fontFamilyOverride = resourceLoader->GetResourceString(L"LocalizedFontFamilyOverride"); + m_fontFamilyOverride = resourceLoader.GetResourceString(L"LocalizedFontFamilyOverride"); String ^ reserved = L"RESERVED_FOR_FONTLOC"; m_overrideFontApiValues = ((m_fontFamilyOverride != nullptr) && (m_fontFamilyOverride != reserved)); if (m_overrideFontApiValues) { - String ^ localizedUICaptionFontSizeFactorOverride = resourceLoader->GetResourceString(L"LocalizedUICaptionFontSizeFactorOverride"); - String ^ localizedUITextFontSizeFactorOverride = resourceLoader->GetResourceString(L"LocalizedUITextFontSizeFactorOverride"); - String ^ localizedFontWeightOverride = resourceLoader->GetResourceString(L"LocalizedFontWeightOverride"); + String ^ localizedUICaptionFontSizeFactorOverride = resourceLoader.GetResourceString(L"LocalizedUICaptionFontSizeFactorOverride"); + String ^ localizedUITextFontSizeFactorOverride = resourceLoader.GetResourceString(L"LocalizedUITextFontSizeFactorOverride"); + String ^ localizedFontWeightOverride = resourceLoader.GetResourceString(L"LocalizedFontWeightOverride"); // If any of the font overrides are modified then all of them need to be modified assert(localizedFontWeightOverride != reserved); @@ -554,12 +554,12 @@ unordered_map LocalizationService::GetTokenToReadableNameMap() unordered_map tokenToReadableNameMap{}; auto resProvider = AppResourceProvider::GetInstance(); - static const wstring openParen = resProvider->GetCEngineString(StringReference(s_openParenResourceKey))->Data(); + static const wstring openParen = resProvider.GetCEngineString(StringReference(s_openParenResourceKey))->Data(); for (const auto& keyPair : s_parenEngineKeyResourceMap) { - wstring engineStr = resProvider->GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); - wstring automationName = resProvider->GetResourceString(StringReference(keyPair.second.c_str()))->Data(); + wstring engineStr = resProvider.GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); + wstring automationName = resProvider.GetResourceString(StringReference(keyPair.second.c_str()))->Data(); tokenToReadableNameMap.emplace(engineStr + openParen, automationName); } @@ -567,15 +567,15 @@ unordered_map LocalizationService::GetTokenToReadableNameMap() for (const auto& keyPair : s_noParenEngineKeyResourceMap) { - wstring engineStr = resProvider->GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); - wstring automationName = resProvider->GetResourceString(StringReference(keyPair.second.c_str()))->Data(); + wstring engineStr = resProvider.GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); + wstring automationName = resProvider.GetResourceString(StringReference(keyPair.second.c_str()))->Data(); tokenToReadableNameMap.emplace(engineStr, automationName); } s_noParenEngineKeyResourceMap.clear(); // Also replace hyphens with "minus" - wstring minusText = resProvider->GetResourceString(L"minus")->Data(); + wstring minusText = resProvider.GetResourceString(L"minus")->Data(); tokenToReadableNameMap.emplace(L"-", minusText); return tokenToReadableNameMap; @@ -592,7 +592,7 @@ String ^ LocalizationService::GetNarratorReadableToken(String ^ rawToken) } else { - static const String ^ openParen = AppResourceProvider::GetInstance()->GetCEngineString(StringReference(s_openParenResourceKey)); + static const String ^ openParen = AppResourceProvider::GetInstance().GetCEngineString(StringReference(s_openParenResourceKey)); return ref new String(itr->second.c_str()) + L" " + openParen; } } diff --git a/src/CalcViewModel/Common/LocalizationService.h b/src/CalcViewModel/Common/LocalizationService.h index d692137..6c5d0c5 100644 --- a/src/CalcViewModel/Common/LocalizationService.h +++ b/src/CalcViewModel/Common/LocalizationService.h @@ -58,11 +58,10 @@ namespace CalculatorApp Windows::Globalization::NumberFormatting::DecimalFormatter ^ GetRegionalSettingsAwareDecimalFormatter() const; Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(_In_ Platform::String ^ format) const; - Windows::Globalization::DateTimeFormatting::DateTimeFormatter - ^ GetRegionalSettingsAwareDateTimeFormatter( - _In_ Platform::String ^ format, - _In_ Platform::String ^ calendarIdentifier, - _In_ Platform::String ^ clockIdentifier) const; + Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter( + _In_ Platform::String ^ format, + _In_ Platform::String ^ calendarIdentifier, + _In_ Platform::String ^ clockIdentifier) const; Windows::Globalization::NumberFormatting::CurrencyFormatter ^ GetRegionalSettingsAwareCurrencyFormatter() const; diff --git a/src/CalcViewModel/Common/LocalizationSettings.h b/src/CalcViewModel/Common/LocalizationSettings.h index 7c160c4..addc0c3 100644 --- a/src/CalcViewModel/Common/LocalizationSettings.h +++ b/src/CalcViewModel/Common/LocalizationSettings.h @@ -169,21 +169,20 @@ namespace CalculatorApp } } - Platform::String ^ GetEnglishValueFromLocalizedDigits(Platform::String ^ localizedString) const + Platform::String ^ GetEnglishValueFromLocalizedDigits(const std::wstring& localizedString) const { if (m_resolvedName == L"en-US") { - return localizedString; + return ref new Platform::String(localizedString.c_str()); } size_t i = 0; - auto localizedStringData = localizedString->Data(); - size_t length = localizedString->Length(); + size_t length = localizedString.size(); std::unique_ptr englishString(new wchar_t[length + 1]); // +1 for the null termination for (; i < length; ++i) { - wchar_t ch = localizedStringData[i]; + wchar_t ch = localizedString[i]; if (!IsEnUsDigit(ch)) { for (int j = 0; j < 10; ++j) @@ -282,17 +281,18 @@ namespace CalculatorApp return m_numberGrouping; } - Platform::String ^ RemoveGroupSeparators(Platform::String ^ source) const + void RemoveGroupSeparators(const wchar_t* value, const size_t length, std::wstring* rawValue) const { - std::wstringstream stream; - for (auto c = source->Begin(); c < source->End(); ++c) + rawValue->clear(); + rawValue->reserve(length); + + for (size_t i = 0; i < length; i++) { - if (*c != L' ' && *c != m_numberGroupSeparator) + if (value[i] != L' ' && value[i] != m_numberGroupSeparator) { - stream << *c; + rawValue->append(1, value[i]); } } - return ref new Platform::String(stream.str().c_str()); } Platform::String ^ GetCalendarIdentifier() const diff --git a/src/CalcViewModel/Common/LocalizationStringUtil.h b/src/CalcViewModel/Common/LocalizationStringUtil.h index d3fc229..1a360bd 100644 --- a/src/CalcViewModel/Common/LocalizationStringUtil.h +++ b/src/CalcViewModel/Common/LocalizationStringUtil.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -9,88 +9,50 @@ namespace CalculatorApp { namespace Common { - class LocalizationStringUtilInternal + class LocalizationStringUtil { public: - static Platform::String ^ GetLocalizedString(Platform::String ^ pMessage, ...) + static std::wstring GetLocalizedString(const wchar_t* pMessage, ...) { std::wstring returnString = L""; const UINT32 length = 1024; std::unique_ptr spBuffer = std::unique_ptr(new wchar_t[length]); va_list args = NULL; va_start(args, pMessage); - DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args); + DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage, 0, 0, spBuffer.get(), length, &args); va_end(args); if (fmtReturnVal != 0) { - return ref new Platform::String(spBuffer.get()); - } - else - { - return ref new Platform::String(); + returnString = spBuffer.get(); } + + return returnString; } - }; - public - ref class LocalizationStringUtil sealed - { - public: - static Platform::String - ^ GetLocalizedString(Platform::String ^ pMessage) + template + static Platform::String^ GetLocalizedNarratorAnnouncement(Platform::String^ resourceKey, Platform::String^& formatVariable, T*... params) + { + EnsureInitialization(resourceKey, formatVariable); + return StringReference(GetLocalizedString(formatVariable->Data(), params...).c_str()); + } + + private: + static void EnsureInitialization(Platform::String^ resourceKey, Platform::String^& formatVariable) + { + if (resourceKey == nullptr || resourceKey->IsEmpty()) { - return LocalizationStringUtilInternal::GetLocalizedString(pMessage); + return; } - static Platform::String - ^ GetLocalizedString( - Platform::String ^ pMessage, - Platform::String ^ param1) + // If the formatVariable already has a value, we don't need to set it again. Simply return. + if (formatVariable != nullptr && !formatVariable->IsEmpty()) { - return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data()); + return; } - static Platform::String - ^ GetLocalizedString( - Platform::String ^ pMessage, - Platform::String ^ param1, - Platform::String ^ param2) - { - return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data()); - } - - static Platform::String - ^ GetLocalizedString( - Platform::String ^ pMessage, - Platform::String ^ param1, - Platform::String ^ param2, - Platform::String - ^ param3) - { - return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data()); - } - - static Platform::String - ^ GetLocalizedString( - Platform::String ^ pMessage, - Platform::String ^ param1, - Platform::String ^ param2, - Platform::String ^ param3, - Platform::String ^ param4) - { - return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data(), param4->Data()); - } - - static Platform::String - ^ GetResourceValue(Platform::String ^ resourceKey) { - if (resourceKey == nullptr || resourceKey->IsEmpty()) - { - return L""; - } - - return AppResourceProvider::GetInstance()->GetResourceString(resourceKey); - } + formatVariable = AppResourceProvider::GetInstance().GetResourceString(resourceKey); + } }; } } diff --git a/src/CalcViewModel/Common/NavCategory.cpp b/src/CalcViewModel/Common/NavCategory.cpp index 90f25c9..8bffc79 100644 --- a/src/CalcViewModel/Common/NavCategory.cpp +++ b/src/CalcViewModel/Common/NavCategory.cpp @@ -368,28 +368,33 @@ NavCategoryGroup::NavCategoryGroup(const NavCategoryGroupInitializer& groupIniti m_GroupType = groupInitializer.type; auto resProvider = AppResourceProvider::GetInstance(); - m_Name = resProvider->GetResourceString(StringReference(groupInitializer.headerResourceKey)); - String ^ groupMode = resProvider->GetResourceString(StringReference(groupInitializer.modeResourceKey)); - String ^ automationName = resProvider->GetResourceString(StringReference(groupInitializer.automationResourceKey)); + String ^ headerResourceKey = StringReference(groupInitializer.headerResourceKey); + String ^ modeResourceKey = StringReference(groupInitializer.modeResourceKey); + String ^ automationResourceKey = StringReference(groupInitializer.automationResourceKey); + m_Name = resProvider.GetResourceString(headerResourceKey); + String ^ groupMode = resProvider.GetResourceString(modeResourceKey); + String ^ automationName = resProvider.GetResourceString(automationResourceKey); - String ^ navCategoryHeaderAutomationNameFormat = resProvider->GetResourceString(L"NavCategoryHeader_AutomationNameFormat"); - m_AutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat, automationName); + String ^ navCategoryHeaderAutomationNameFormat = resProvider.GetResourceString(L"NavCategoryHeader_AutomationNameFormat"); + m_AutomationName = + ref new String(LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat->Data(), automationName->Data()).c_str()); - String ^ navCategoryItemAutomationNameFormat = resProvider->GetResourceString(L"NavCategoryItem_AutomationNameFormat"); + String ^ navCategoryItemAutomationNameFormat = resProvider.GetResourceString(L"NavCategoryItem_AutomationNameFormat"); for (const NavCategoryInitializer& categoryInitializer : s_categoryManifest) { if (categoryInitializer.groupType == groupInitializer.type) { String ^ nameResourceKey = StringReference(categoryInitializer.nameResourceKey); - String ^ categoryName = resProvider->GetResourceString(nameResourceKey + "Text"); - String ^ categoryAutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat, categoryName, m_Name); + String ^ categoryName = resProvider.GetResourceString(nameResourceKey + "Text"); + String ^ categoryAutomationName = ref new String( + LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat->Data(), categoryName->Data(), m_Name->Data()).c_str()); m_Categories->Append(ref new NavCategory( categoryName, categoryAutomationName, StringReference(categoryInitializer.glyph), - resProvider->GetResourceString(nameResourceKey + "AccessKey"), + resProvider.GetResourceString(nameResourceKey + "AccessKey"), groupMode, categoryInitializer.viewMode, categoryInitializer.supportsNegative)); diff --git a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp index e976888..5f6ce76 100644 --- a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" @@ -132,8 +132,8 @@ CurrencyDataLoader::CurrencyDataLoader(_In_ unique_ptr clie m_ratioFormatter->IsDecimalPointAlwaysDisplayed = true; m_ratioFormatter->FractionDigits = FORMATTER_RATE_FRACTION_PADDING; - m_ratioFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyFromToRatioFormat"); - m_timestampFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyTimestampFormat"); + m_ratioFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyFromToRatioFormat")->Data(); + m_timestampFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyTimestampFormat")->Data(); } CurrencyDataLoader::~CurrencyDataLoader() @@ -300,18 +300,16 @@ pair CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const U double ratio = (iter2->second).ratio; double rounded = RoundCurrencyRatio(ratio); - auto digit = LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1'); - auto digitSymbol = ref new String(&digit, 1); - auto roundedFormat = m_ratioFormatter->Format(rounded); + wstring digitSymbol = wstring{ LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1') }; + wstring roundedFormat = m_ratioFormatter->Format(rounded)->Data(); - auto ratioString = LocalizationStringUtil::GetLocalizedString( - m_ratioFormat, digitSymbol, StringReference(unit1.abbreviation.c_str()), roundedFormat, StringReference(unit2.abbreviation.c_str())); + wstring ratioString = LocalizationStringUtil::GetLocalizedString( + m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.abbreviation.c_str(), roundedFormat.c_str(), unit2.abbreviation.c_str()); - auto accessibleRatioString = - LocalizationStringUtil::GetLocalizedString( - m_ratioFormat, digitSymbol, StringReference(unit1.accessibleName.c_str()), roundedFormat, StringReference(unit2.accessibleName.c_str())); + wstring accessibleRatioString = LocalizationStringUtil::GetLocalizedString( + m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.accessibleName.c_str(), roundedFormat.c_str(), unit2.accessibleName.c_str()); - return make_pair(ratioString->Data(), accessibleRatioString->Data()); + return make_pair(ratioString, accessibleRatioString); } } } @@ -749,19 +747,21 @@ void CurrencyDataLoader::UpdateDisplayedTimestamp() } wstring CurrencyDataLoader::GetCurrencyTimestamp() { + wstring timestamp = L""; + DateTime epoch{}; if (m_cacheTimestamp.UniversalTime != epoch.UniversalTime) { DateTimeFormatter ^ dateFormatter = ref new DateTimeFormatter(L"shortdate"); - auto date = dateFormatter->Format(m_cacheTimestamp); + wstring date = dateFormatter->Format(m_cacheTimestamp)->Data(); DateTimeFormatter ^ timeFormatter = ref new DateTimeFormatter(L"shorttime"); - auto time = timeFormatter->Format(m_cacheTimestamp); + wstring time = timeFormatter->Format(m_cacheTimestamp)->Data(); - return LocalizationStringUtil::GetLocalizedString(m_timestampFormat, date, time)->Data(); + timestamp = LocalizationStringUtil::GetLocalizedString(m_timestampFormat.c_str(), date.c_str(), time.c_str()); } - return L""; + return timestamp; } #pragma optimize("", off) // Turn off optimizations to work around DevDiv 393321 diff --git a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.h b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.h index d2548dc..7a28c6c 100644 --- a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.h +++ b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -124,9 +124,9 @@ namespace CalculatorApp std::shared_ptr m_vmCallback; Windows::Globalization::NumberFormatting::DecimalFormatter ^ m_ratioFormatter; - Platform::String ^ m_ratioFormat; + std::wstring m_ratioFormat; Windows::Foundation::DateTime m_cacheTimestamp; - Platform::String ^ m_timestampFormat; + std::wstring m_timestampFormat; CurrencyLoadStatus m_loadStatus; diff --git a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp index f90260d..e69b8e2 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp @@ -953,7 +953,7 @@ void UnitConverterDataLoader::GetConversionData(_In_ unordered_mapGetResourceString(stringId)->Data(); + return AppResourceProvider::GetInstance().GetResourceString(stringId)->Data(); } void UnitConverterDataLoader::GetExplicitConversionData(_In_ unordered_map>& unitToUnitConversionList) diff --git a/src/CalcViewModel/DateCalculatorViewModel.cpp b/src/CalcViewModel/DateCalculatorViewModel.cpp index 3fcfe05..e89c136 100644 --- a/src/CalcViewModel/DateCalculatorViewModel.cpp +++ b/src/CalcViewModel/DateCalculatorViewModel.cpp @@ -172,14 +172,14 @@ void DateCalculatorViewModel::UpdateDisplayResult() { IsDiffInDays = false; StrDateDiffResultInDays = L""; - StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"CalculationFailed"); + StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"CalculationFailed"); } else if (m_dateDiffResultInDays.day == 0) { // to and from dates the same IsDiffInDays = true; StrDateDiffResultInDays = L""; - StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_SameDates"); + StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_SameDates"); } else if (m_dateDiffResult == DateDifferenceUnknown || (m_dateDiffResult.year == 0 && m_dateDiffResult.month == 0 && m_dateDiffResult.week == 0)) @@ -206,7 +206,7 @@ void DateCalculatorViewModel::UpdateDisplayResult() if (m_isOutOfBound) { // Display Date out of bound message - StrDateResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_OutOfBoundMessage"); + StrDateResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_OutOfBoundMessage"); } else { @@ -218,14 +218,16 @@ void DateCalculatorViewModel::UpdateDisplayResult() void DateCalculatorViewModel::UpdateStrDateDiffResultAutomationName() { - String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_DifferenceResultAutomationName"); - StrDateDiffResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateDiffResult); + String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_DifferenceResultAutomationName"); + wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateDiffResult->Data()); + StrDateDiffResultAutomationName = ref new String(localizedAutomationName.c_str()); } void DateCalculatorViewModel::UpdateStrDateResultAutomationName() { - String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_ResultingDateAutomationName"); - StrDateResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateResult); + String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_ResultingDateAutomationName"); + wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateResult->Data()); + StrDateResultAutomationName = ref new String(localizedAutomationName.c_str()); } void DateCalculatorViewModel::InitializeDateOutputFormats(_In_ String ^ calendarIdentifier) @@ -245,7 +247,7 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const { wstring result; bool addDelimiter = false; - AppResourceProvider ^ resourceLoader = AppResourceProvider::GetInstance(); + AppResourceProvider resourceLoader = AppResourceProvider::GetInstance(); auto yearCount = m_dateDiffResult.year; if (yearCount > 0) @@ -255,11 +257,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const if (yearCount > 1) { - result += resourceLoader->GetResourceString(L"Date_Years")->Data(); + result += resourceLoader.GetResourceString(L"Date_Years")->Data(); } else { - result += resourceLoader->GetResourceString(L"Date_Year")->Data(); + result += resourceLoader.GetResourceString(L"Date_Year")->Data(); } // set the flags to add a delimiter whenever the next unit is added @@ -283,11 +285,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const if (monthCount > 1) { - result += resourceLoader->GetResourceString(L"Date_Months")->Data(); + result += resourceLoader.GetResourceString(L"Date_Months")->Data(); } else { - result += resourceLoader->GetResourceString(L"Date_Month")->Data(); + result += resourceLoader.GetResourceString(L"Date_Month")->Data(); } } @@ -308,11 +310,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const if (weekCount > 1) { - result += resourceLoader->GetResourceString(L"Date_Weeks")->Data(); + result += resourceLoader.GetResourceString(L"Date_Weeks")->Data(); } else { - result += resourceLoader->GetResourceString(L"Date_Week")->Data(); + result += resourceLoader.GetResourceString(L"Date_Week")->Data(); } } @@ -333,11 +335,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const if (dayCount > 1) { - result += resourceLoader->GetResourceString(L"Date_Days")->Data(); + result += resourceLoader.GetResourceString(L"Date_Days")->Data(); } else { - result += resourceLoader->GetResourceString(L"Date_Day")->Data(); + result += resourceLoader.GetResourceString(L"Date_Day")->Data(); } } @@ -352,11 +354,11 @@ String ^ DateCalculatorViewModel::GetDateDiffStringInDays() const // Display the result as '1 day' or 'N days' if (m_dateDiffResultInDays.day > 1) { - result += AppResourceProvider::GetInstance()->GetResourceString(L"Date_Days")->Data(); + result += AppResourceProvider::GetInstance().GetResourceString(L"Date_Days")->Data(); } else { - result += AppResourceProvider::GetInstance()->GetResourceString(L"Date_Day")->Data(); + result += AppResourceProvider::GetInstance().GetResourceString(L"Date_Day")->Data(); } return ref new String(result.data()); diff --git a/src/CalcViewModel/HistoryViewModel.cpp b/src/CalcViewModel/HistoryViewModel.cpp index 468e937..8da5007 100644 --- a/src/CalcViewModel/HistoryViewModel.cpp +++ b/src/CalcViewModel/HistoryViewModel.cpp @@ -371,10 +371,9 @@ void HistoryViewModel::UpdateItemSize() ItemSize = Items->Size; } -Platform::String ^ HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ formatVariable) +void HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ &formatVariable) { - String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(resourceKey), formatVariable); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(resourceKey, formatVariable); HistoryAnnouncement = CalculatorAnnouncement::GetHistoryClearedAnnouncement(announcement); - return announcement; } diff --git a/src/CalcViewModel/HistoryViewModel.h b/src/CalcViewModel/HistoryViewModel.h index c87ca40..4ed61d9 100644 --- a/src/CalcViewModel/HistoryViewModel.h +++ b/src/CalcViewModel/HistoryViewModel.h @@ -68,7 +68,7 @@ namespace CalculatorApp void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode); bool IsValid(_In_ CalculationManager::HISTORYITEM item); - Platform::String ^ MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ formatVariable); + void MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ &formatVariable); friend class CalculatorDisplay; void UpdateItemSize(); diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index 814b49c..594db45 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -25,7 +25,6 @@ using namespace Windows::UI::Popups; using namespace Windows::Storage::Streams; using namespace Windows::Foundation::Collections; using namespace Utils; -using namespace concurrency; constexpr int StandardModePrecision = 16; constexpr int ScientificModePrecision = 32; @@ -94,16 +93,15 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() , m_localizedNoRightParenthesisAddedFormat(nullptr) { WeakReference calculatorViewModel(this); - auto appResourceProvider = AppResourceProvider::GetInstance(); m_calculatorDisplay.SetCallback(calculatorViewModel); - m_expressionAutomationNameFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorExpression); - m_localizedCalculationResultAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorResults); + m_expressionAutomationNameFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorExpression); + m_localizedCalculationResultAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorResults); m_localizedCalculationResultDecimalAutomationFormat = - appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorResults_DecimalSeparator_Announced); - m_localizedHexaDecimalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::HexButton); - m_localizedDecimalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::DecButton); - m_localizedOctalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::OctButton); - m_localizedBinaryAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::BinButton); + AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorResults_DecimalSeparator_Announced); + m_localizedHexaDecimalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::HexButton); + m_localizedDecimalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::DecButton); + m_localizedOctalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::OctButton); + m_localizedBinaryAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::BinButton); // Initialize the Automation Name CalculationResultAutomationName = GetLocalizedStringFormat(m_localizedCalculationResultAutomationFormat, m_DisplayValue); @@ -194,13 +192,13 @@ String ^ StandardCalculatorViewModel::GetNarratorStringReadRawNumbers(_In_ Strin return ref new String(wss.str().c_str()); } -void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ String ^ displayStringValue, _In_ bool isError) +void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ wstring const& displayStringValue, _In_ bool isError) { - String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue->Data(), isError); + String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue, isError); // Set this variable before the DisplayValue is modified, Otherwise the DisplayValue will // not match what the narrator is saying - m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue->Data(), localizedDisplayStringValue, isError); + m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue, localizedDisplayStringValue, isError); AreAlwaysOnTopResultsUpdated = false; if (DisplayValue != localizedDisplayStringValue) @@ -241,10 +239,10 @@ void StandardCalculatorViewModel::SetOpenParenthesisCountNarratorAnnouncement() wstring localizedParenthesisCount = to_wstring(m_OpenParenthesisCount).c_str(); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedParenthesisCount); - String ^ announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::OpenParenthesisCountAutomationFormat), + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::OpenParenthesisCountAutomationFormat, m_localizedOpenParenthesisCountChangedAutomationFormat, - StringReference(localizedParenthesisCount.c_str())); + localizedParenthesisCount.c_str()); Announcement = CalculatorAnnouncement::GetOpenParenthesisCountChangedAnnouncement(announcement); } @@ -257,7 +255,7 @@ void StandardCalculatorViewModel::OnNoRightParenAdded() void StandardCalculatorViewModel::SetNoParenAddedNarratorAnnouncement() { String ^ announcement = - LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::NoParenthesisAdded), m_localizedNoRightParenthesisAddedFormat); + LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::NoParenthesisAdded, m_localizedNoRightParenthesisAddedFormat); Announcement = CalculatorAnnouncement::GetNoRightParenthesisAddedAnnouncement(announcement); } @@ -354,7 +352,7 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptrGetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator; } - auto currentTokenString = StringReference(currentToken.first.c_str()); + auto currentTokenString = ref new String(currentToken.first.c_str()); if (i < m_ExpressionTokens->Size) { auto existingItem = m_ExpressionTokens->GetAt(i); @@ -698,7 +696,7 @@ void StandardCalculatorViewModel::OnCopyCommand(Object ^ parameter) { CopyPasteManager::CopyToClipboard(GetRawDisplayValue()); - String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(CalculatorResourceKeys::DisplayCopied); + String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::DisplayCopied); Announcement = CalculatorAnnouncement::GetDisplayCopiedAnnouncement(announcement); } @@ -729,7 +727,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter) } // Ensure that the paste happens on the UI thread - create_task(CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)) + CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType) .then([that, mode](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current()); } @@ -741,7 +739,7 @@ CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum( void StandardCalculatorViewModel::OnPaste(String ^ pastedString) { // If pastedString is invalid("NoOp") then display pasteError else process the string - if (CopyPasteManager::IsErrorMessage(pastedString)) + if (pastedString == StringReference(CopyPasteManager::PasteErrorString)) { this->DisplayPasteError(); return; @@ -895,7 +893,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter) TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); - String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryCleared), m_localizedMemoryCleared); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::MemoryCleared, m_localizedMemoryCleared); Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement); } @@ -1048,8 +1046,8 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed() TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode()); - String ^ announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemorySave), m_localizedMemorySavedAutomationFormat, m_DisplayValue); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::MemorySave, m_localizedMemorySavedAutomationFormat, m_DisplayValue->Data()); Announcement = CalculatorAnnouncement::GetMemoryItemAddedAnnouncement(announcement); } @@ -1064,8 +1062,8 @@ void StandardCalculatorViewModel::OnMemoryItemChanged(unsigned int indexOfMemory wstring localizedIndex = to_wstring(indexOfMemory + 1); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex); - String ^ announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemChanged), m_localizedMemoryItemChangedAutomationFormat, StringReference(localizedIndex.c_str()), localizedValue); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::MemoryItemChanged, m_localizedMemoryItemChangedAutomationFormat, localizedIndex.c_str(), localizedValue->Data()); Announcement = CalculatorAnnouncement::GetMemoryItemChangedAnnouncement(announcement); } @@ -1133,8 +1131,8 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition wstring localizedIndex = to_wstring(boxedPosition->Value + 1); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex); - String ^ announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemCleared), m_localizedMemoryItemClearedAutomationFormat, StringReference(localizedIndex.c_str())); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::MemoryItemCleared, m_localizedMemoryItemClearedAutomationFormat, localizedIndex.c_str()); Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement); } @@ -1214,7 +1212,9 @@ String ^ StandardCalculatorViewModel::GetRawDisplayValue() } else { - return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue); + wstring rawValue; + LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue); + return ref new String(rawValue.c_str()); } } @@ -1223,7 +1223,8 @@ String ^ StandardCalculatorViewModel::GetRawDisplayValue() // 'displayValue' is a localized string containing a numerical value to be displayed to the user. String ^ StandardCalculatorViewModel::GetLocalizedStringFormat(String ^ format, String ^ displayValue) { - return LocalizationStringUtil::GetLocalizedString(format, displayValue); + String ^ localizedString = ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), displayValue->Data()).c_str()); + return localizedString; } void StandardCalculatorViewModel::ResetDisplay() @@ -1584,7 +1585,7 @@ size_t StandardCalculatorViewModel::LengthWithoutPadding(wstring str) wstring StandardCalculatorViewModel::AddPadding(wstring binaryString) { - if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(StringReference(binaryString.c_str())) == L"0") + if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(binaryString) == L"0") { return binaryString; } @@ -1683,7 +1684,7 @@ void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text) { pair p = m_tokens->at(pos); - String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text); + String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text->Data()); p.first = englishString->Data(); int commandPos = p.second; @@ -1807,8 +1808,8 @@ void StandardCalculatorViewModel::UpdatecommandsInRecordingMode() void StandardCalculatorViewModel::OnMaxDigitsReached() { - String ^ announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MaxDigitsReachedFormat), m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName); + String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::MaxDigitsReachedFormat, m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName->Data()); Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement); } @@ -1827,11 +1828,11 @@ NarratorAnnouncement ^ StandardCalculatorViewModel::GetDisplayUpdatedNarratorAnn } else { - announcement = LocalizationStringUtil::GetLocalizedString( - LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::ButtonPressFeedbackFormat), + announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement( + CalculatorResourceKeys::ButtonPressFeedbackFormat, m_localizedButtonPressFeedbackAutomationFormat, - m_CalculationResultAutomationName, - m_feedbackForButtonPress); + m_CalculationResultAutomationName->Data(), + m_feedbackForButtonPress->Data()); } // Make sure we don't accidentally repeat an announcement. diff --git a/src/CalcViewModel/StandardCalculatorViewModel.h b/src/CalcViewModel/StandardCalculatorViewModel.h index 8c6644a..df2bf78 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.h +++ b/src/CalcViewModel/StandardCalculatorViewModel.h @@ -340,7 +340,7 @@ namespace CalculatorApp void OnPinUnpinCommand(Platform::Object ^ parameter); void OnInputChanged(); - void SetPrimaryDisplay(Platform::String ^ displayString, _In_ bool isError); + void SetPrimaryDisplay(_In_ std::wstring const& displayString, _In_ bool isError); void DisplayPasteError(); void SetTokens(_Inout_ std::shared_ptr>> const& tokens); void SetExpressionDisplay( diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp index 149f565..e57b0dc 100644 --- a/src/CalcViewModel/UnitConverterViewModel.cpp +++ b/src/CalcViewModel/UnitConverterViewModel.cpp @@ -137,12 +137,12 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptrFractionDigits; auto resourceLoader = AppResourceProvider::GetInstance(); - m_localizedValueFromFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueFromFormat); - m_localizedValueToFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueToFormat); - m_localizedConversionResultFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ConversionResultFormat); - m_localizedValueFromDecimalFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueFromDecimalFormat); - m_localizedInputUnitName = resourceLoader->GetResourceString(UnitConverterResourceKeys::InputUnit_Name); - m_localizedOutputUnitName = resourceLoader->GetResourceString(UnitConverterResourceKeys::OutputUnit_Name); + m_localizedValueFromFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromFormat); + m_localizedValueToFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueToFormat); + m_localizedConversionResultFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ConversionResultFormat); + m_localizedValueFromDecimalFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromDecimalFormat); + m_localizedInputUnitName = resourceLoader.GetResourceString(UnitConverterResourceKeys::InputUnit_Name); + m_localizedOutputUnitName = resourceLoader.GetResourceString(UnitConverterResourceKeys::OutputUnit_Name); Unit1AutomationName = m_localizedInputUnitName; Unit2AutomationName = m_localizedOutputUnitName; @@ -390,7 +390,7 @@ String ^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& st void UnitConverterViewModel::DisplayPasteError() { - String ^ errorMsg = AppResourceProvider::GetInstance()->GetCEngineString(StringReference(SIDS_DOMAIN)); /*SIDS_DOMAIN is for "invalid input"*/ + String ^ errorMsg = AppResourceProvider::GetInstance().GetCEngineString(StringReference(SIDS_DOMAIN)); /*SIDS_DOMAIN is for "invalid input"*/ Value1 = errorMsg; Value2 = errorMsg; m_relocalizeStringOnSwitch = false; @@ -515,10 +515,8 @@ void UnitConverterViewModel::OnPasteCommand(Platform::Object ^ parameter) // Ensure that the paste happens on the UI thread // EventWriteClipboardPaste_Start(); // Any converter ViewMode is fine here. - - auto that(this); - create_task(CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode), -1, BitLength::BitLengthUnknown)) - .then([that](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current()); + CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode)) + .then([this](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current()); } void UnitConverterViewModel::InitializeView() @@ -652,7 +650,7 @@ void UnitConverterViewModel::OnCurrencyDataLoadFinished(bool didLoad) ResetCategory(); StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed; - String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(key); + String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(key); Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement); } @@ -667,18 +665,17 @@ void UnitConverterViewModel::RefreshCurrencyRatios() m_isCurrencyDataLoaded = false; IsCurrencyLoadingVisible = true; - String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(UnitConverterResourceKeys::UpdatingCurrencyRates); + String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(UnitConverterResourceKeys::UpdatingCurrencyRates); Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement); - auto that(this); - auto refreshTask = create_task([that] { return that->m_model->RefreshCurrencyRatios().get(); }); + auto refreshTask = create_task([this] { return m_model->RefreshCurrencyRatios().get(); }); refreshTask.then( - [that](const pair& refreshResult) { + [this](const pair& refreshResult) { bool didLoad = refreshResult.first; wstring timestamp = refreshResult.second; - that->OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/); - that->OnCurrencyDataLoadFinished(didLoad); + OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/); + OnCurrencyDataLoadFinished(didLoad); }, task_continuation_context::use_current()); } @@ -881,7 +878,7 @@ NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wch void UnitConverterViewModel::OnPaste(String ^ stringToPaste) { // If pastedString is invalid("NoOp") then display pasteError else process the string - if (CopyPasteManager::IsErrorMessage(stringToPaste)) + if (stringToPaste == StringReference(CopyPasteManager::PasteErrorString)) { this->DisplayPasteError(); return; @@ -957,7 +954,8 @@ String ^ UnitConverterViewModel::GetLocalizedAutomationName(_In_ String ^ displa format = m_localizedValueFromDecimalFormat; } - return LocalizationStringUtil::GetLocalizedString(format, displayvalue, unitname); + wstring localizedResult = LocalizationStringUtil::GetLocalizedString(format->Data(), displayvalue->Data(), unitname->Data()); + return ref new String(localizedResult.c_str()); } String @@ -967,7 +965,11 @@ String _In_ String ^ toValue, _In_ String ^ toUnit) { - return LocalizationStringUtil::GetLocalizedString(m_localizedConversionResultFormat, fromValue, fromUnit, toValue, toUnit); + String ^ localizedString = + ref new String(LocalizationStringUtil::GetLocalizedString( + m_localizedConversionResultFormat->Data(), fromValue->Data(), fromUnit->Data(), toValue->Data(), toUnit->Data()) + .c_str()); + return localizedString; } void UnitConverterViewModel::UpdateValue1AutomationName() @@ -988,9 +990,9 @@ void UnitConverterViewModel::UpdateValue2AutomationName() void UnitConverterViewModel::OnMaxDigitsReached() { - String ^ format = AppResourceProvider::GetInstance()->GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat); - auto announcement = LocalizationStringUtil::GetLocalizedString(format, m_lastAnnouncedConversionResult); - Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement); + String ^ format = AppResourceProvider::GetInstance().GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat); + const wstring& announcement = LocalizationStringUtil::GetLocalizedString(format->Data(), m_lastAnnouncedConversionResult->Data()); + Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(StringReference(announcement.c_str())); } bool UnitConverterViewModel::UnitsAreValid() @@ -1000,18 +1002,17 @@ bool UnitConverterViewModel::UnitsAreValid() void UnitConverterViewModel::StartConversionResultTimer() { - auto that(this); - m_conversionResultTaskHelper = make_unique(CONVERSION_FINALIZED_DELAY_IN_MS, [that]() { - if (that->UnitsAreValid()) + m_conversionResultTaskHelper = make_unique(CONVERSION_FINALIZED_DELAY_IN_MS, [this]() { + if (UnitsAreValid()) { - String ^ valueFrom = that->m_Value1Active ? that->m_Value1 : that->m_Value2; - String ^ valueTo = that->m_Value1Active ? that->m_Value2 : that->m_Value1; + String ^ valueFrom = m_Value1Active ? m_Value1 : m_Value2; + String ^ valueTo = m_Value1Active ? m_Value2 : m_Value1; } }); } String ^ SupplementaryResult::GetLocalizedAutomationName() { - auto format = AppResourceProvider::GetInstance()->GetResourceString("SupplementaryUnit_AutomationName"); - return LocalizationStringUtil::GetLocalizedString(format, this->Value, this->Unit->Name); + auto format = AppResourceProvider::GetInstance().GetResourceString("SupplementaryUnit_AutomationName"); + return ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), this->Value->Data(), this->Unit->Name->Data()).c_str()); } diff --git a/src/Calculator/AboutFlyout.xaml.cpp b/src/Calculator/AboutFlyout.xaml.cpp index 9eab1af..87a15e6 100644 --- a/src/Calculator/AboutFlyout.xaml.cpp +++ b/src/Calculator/AboutFlyout.xaml.cpp @@ -35,11 +35,11 @@ AboutFlyout::AboutFlyout() this->SetVersionString(); - Header->Text = resourceLoader->GetResourceString("AboutButton/Content"); + Header->Text = resourceLoader.GetResourceString("AboutButton/Content"); auto copyrightText = - LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("AboutControlCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str())); - AboutControlCopyrightRun->Text = copyrightText; + LocalizationStringUtil::GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright")->Data(), to_wstring(BUILD_YEAR).c_str()); + AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str()); } void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) @@ -53,7 +53,7 @@ void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArg void AboutFlyout::SetVersionString() { PackageVersion version = Package::Current->Id->Version; - String ^ appName = AppResourceProvider::GetInstance()->GetResourceString(L"AppName"); + String ^ appName = AppResourceProvider::GetInstance().GetResourceString(L"AppName"); AboutFlyoutVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision; } diff --git a/src/Calculator/Controls/CalculationResult.cpp b/src/Calculator/Controls/CalculationResult.cpp index 2c969c4..3220e31 100644 --- a/src/Calculator/Controls/CalculationResult.cpp +++ b/src/Calculator/Controls/CalculationResult.cpp @@ -63,7 +63,11 @@ CalculationResult::CalculationResult() Platform::String ^ CalculationResult::GetRawDisplayValue() { - return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue); + std::wstring rawValue; + + LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue); + + return ref new Platform::String(rawValue.c_str()); } void CalculationResult::OnApplyTemplate() diff --git a/src/Calculator/Controls/RadixButton.cpp b/src/Calculator/Controls/RadixButton.cpp index 0786f21..43c3cf4 100644 --- a/src/Calculator/Controls/RadixButton.cpp +++ b/src/Calculator/Controls/RadixButton.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" @@ -18,6 +18,8 @@ using namespace Windows::UI::Xaml::Data; String ^ RadixButton::GetRawDisplayValue() { + wstring rawValue; String ^ radixContent = Content->ToString(); - return LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent); + LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent->Data(), radixContent->Length(), &rawValue); + return ref new String(rawValue.c_str()); } diff --git a/src/Calculator/Converters/RadixToStringConverter.cpp b/src/Calculator/Converters/RadixToStringConverter.cpp index 6928034..584c04c 100644 --- a/src/Calculator/Converters/RadixToStringConverter.cpp +++ b/src/Calculator/Converters/RadixToStringConverter.cpp @@ -28,22 +28,22 @@ namespace CalculatorApp { case RADIX_TYPE::BIN_RADIX: { - convertedValue = resourceLoader->GetResourceString("Bin"); + convertedValue = resourceLoader.GetResourceString("Bin"); break; } case RADIX_TYPE::OCT_RADIX: { - convertedValue = resourceLoader->GetResourceString("Oct"); + convertedValue = resourceLoader.GetResourceString("Oct"); break; } case RADIX_TYPE::DEC_RADIX: { - convertedValue = resourceLoader->GetResourceString("Dec"); + convertedValue = resourceLoader.GetResourceString("Dec"); break; } case RADIX_TYPE::HEX_RADIX: { - convertedValue = resourceLoader->GetResourceString("Hex"); + convertedValue = resourceLoader.GetResourceString("Hex"); break; } default: diff --git a/src/Calculator/Views/Calculator.xaml.cpp b/src/Calculator/Views/Calculator.xaml.cpp index 4fdad2e..af79dc6 100644 --- a/src/Calculator/Views/Calculator.xaml.cpp +++ b/src/Calculator/Views/Calculator.xaml.cpp @@ -59,8 +59,8 @@ Calculator::Calculator() m_displayFlyout = static_cast(Resources->Lookup(L"DisplayContextMenu")); auto resLoader = AppResourceProvider::GetInstance(); - CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem"); - PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem"); + CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem"); + PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem"); this->SizeChanged += ref new SizeChangedEventHandler(this, &Calculator::Calculator_SizeChanged); } @@ -68,10 +68,10 @@ Calculator::Calculator() void Calculator::LoadResourceStrings() { auto resProvider = AppResourceProvider::GetInstance(); - m_openMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Open"); - m_closeMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Close"); - m_openHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Open"); - m_closeHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Close"); + m_openMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Open"); + m_closeMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Close"); + m_openHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Open"); + m_closeHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Close"); AutomationProperties::SetName(MemoryButton, m_openMemoryFlyoutAutomationName); AutomationProperties::SetName(HistoryButton, m_openHistoryFlyoutAutomationName); } @@ -123,9 +123,9 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^) Model->HideMemoryClicked += ref new HideMemoryClickedHandler(this, &Calculator::OnHideMemoryClicked); InitializeHistoryView(Model->HistoryVM); - String ^ historyPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"HistoryPane"); + String ^ historyPaneName = AppResourceProvider::GetInstance().GetResourceString(L"HistoryPane"); HistoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, historyPaneName)); - String ^ memoryPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"MemoryPane"); + String ^ memoryPaneName = AppResourceProvider::GetInstance().GetResourceString(L"MemoryPane"); MemoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, memoryPaneName)); if (Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Controls.Primitives.FlyoutBase", L"Closing")) @@ -149,21 +149,24 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^) })); } -Platform::String ^ Calculator::GetCurrentLayoutState() +std::wstring Calculator::GetCurrentLayoutState() { + std::wstring state; if (IsProgrammer) { - return L"Programmer"; + state = L"Programmer"; } else if (IsScientific) { - return L"Scientific"; + state = L"Scientific"; } else { - return L"Standard"; + state = L"Standard"; } + + return state; } void Calculator::UpdateViewState() @@ -476,7 +479,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e) assert(e->GetTokens() != nullptr); Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands()); Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); - Model->SetPrimaryDisplay(e->Result, false); + Model->SetPrimaryDisplay(e->Result->Data(), false); Model->IsFToEEnabled = false; CloseHistoryFlyout(); @@ -613,7 +616,7 @@ Memory ^ Calculator::GetMemory() if (m_memory == nullptr) { m_memory = ref new Memory(); - VisualStateManager::GoToState(m_memory, GetCurrentLayoutState(), true /*useTransitions*/); + VisualStateManager::GoToState(m_memory, ref new String(GetCurrentLayoutState().c_str()), true /*useTransitions*/); } return m_memory; @@ -669,6 +672,28 @@ void Calculator::OnHistoryFlyOutTapped(_In_ Object ^ sender, _In_ TappedRoutedEv } } +bool Calculator::IsValidRegularExpression(std::wstring str) +{ + bool result = false; + std::wregex regexPatterns[3]; + regexPatterns[0] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}"; + regexPatterns[1] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[+]{1}[0-9]{1,}"; + regexPatterns[2] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[-]{1}[0-9]{1,}"; + + const auto& localizer = LocalizationSettings::GetInstance(); + String ^ englishString = localizer.GetEnglishValueFromLocalizedDigits(str); + + for (int i = 0; i < 3; ++i) + { + if (regex_match(englishString->Data(), regexPatterns[i])) + { + result = true; + break; + } + } + return result; +} + void Calculator::DockPanelTapped(_In_ TappedRoutedEventArgs ^ e) { int index = DockPivot->SelectedIndex; diff --git a/src/Calculator/Views/Calculator.xaml.h b/src/Calculator/Views/Calculator.xaml.h index a7b1a92..e7d3610 100644 --- a/src/Calculator/Views/Calculator.xaml.h +++ b/src/Calculator/Views/Calculator.xaml.h @@ -94,7 +94,7 @@ public void EnsureScientific(); void EnsureProgrammer(); void SetFontSizeResources(); - Platform::String ^ GetCurrentLayoutState(); + std::wstring GetCurrentLayoutState(); void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); private: @@ -140,6 +140,7 @@ public void EnableMemoryControls(bool enable); void OnMemoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void OnHistoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); + bool IsValidRegularExpression(std::wstring str); void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void OnHistoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args); void OnMemoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args); diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp index 9b975ed..e9b6439 100644 --- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp +++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp @@ -247,11 +247,11 @@ int CalculatorProgrammerBitFlipPanel::GetIndexOfLastBit(BitLength length) const String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value) { auto resourceLoader = AppResourceProvider::GetInstance(); - String ^ automationNameTemplate = resourceLoader->GetResourceString(L"BitFlipItemAutomationName"); - String ^ bitPosition; + String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName"); + wstring bitPosition; if (position == 0) { - bitPosition = resourceLoader->GetResourceString(L"LeastSignificantBit"); + bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data()); } else { @@ -263,14 +263,14 @@ String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int if (position == lastPosition) { - bitPosition = resourceLoader->GetResourceString(L"MostSignificantBit"); + bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data()); } else { - String ^ indexName = resourceLoader->GetResourceString(ref new Platform::String(to_wstring(position).c_str())); - String ^ bitPositionTemplate = resourceLoader->GetResourceString(L"BitPosition"); - bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate, indexName); + String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str())); + String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition"); + bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data()); } } - return LocalizationStringUtil::GetLocalizedString(automationNameTemplate, bitPosition, value ? L"1" : L"0"); + return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str()); } diff --git a/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp index 3b2cb2e..6b2125c 100644 --- a/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp +++ b/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp @@ -33,7 +33,7 @@ CalculatorProgrammerOperators::CalculatorProgrammerOperators() { InitializeComponent(); - CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem"); + CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem"); } void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) diff --git a/src/Calculator/Views/DateCalculator.xaml.cpp b/src/Calculator/Views/DateCalculator.xaml.cpp index 5538f5b..5986bdf 100644 --- a/src/Calculator/Views/DateCalculator.xaml.cpp +++ b/src/Calculator/Views/DateCalculator.xaml.cpp @@ -92,7 +92,7 @@ DateCalculator::DateCalculator() DateDiff_FromDate->PlaceholderText = placeholderText; DateDiff_ToDate->PlaceholderText = placeholderText; - CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem"); + CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem"); m_dateCalcOptionChangedEventToken = DateCalculationOption->SelectionChanged += ref new SelectionChangedEventHandler(this, &DateCalculator::DateCalcOption_Changed); } diff --git a/src/Calculator/Views/MainPage.xaml.cpp b/src/Calculator/Views/MainPage.xaml.cpp index a573f6c..74a79e1 100644 --- a/src/Calculator/Views/MainPage.xaml.cpp +++ b/src/Calculator/Views/MainPage.xaml.cpp @@ -10,7 +10,6 @@ #include "CalcViewModel/Common/AppResourceProvider.h" #include "Views/Memory.xaml.h" #include "Converters/BooleanToVisibilityConverter.h" -#include "CalcViewModel/Common/LocalizationStringUtil.h" #include "Common/AppLifecycleLogger.h" using namespace CalculatorApp; using namespace CalculatorApp::Common; @@ -511,20 +510,25 @@ void MainPage::SetHeaderAutomationName() String ^ name; if (NavCategory::IsDateCalculatorViewMode(mode)) { - name = resProvider->GetResourceString(L"HeaderAutomationName_Date"); + name = resProvider.GetResourceString(L"HeaderAutomationName_Date"); } else { - String ^ full; + wstring full; if (NavCategory::IsCalculatorViewMode(mode)) { - full = resProvider->GetResourceString(L"HeaderAutomationName_Calculator"); + full = resProvider.GetResourceString(L"HeaderAutomationName_Calculator")->Data(); } else if (NavCategory::IsConverterViewMode(mode)) { - full = resProvider->GetResourceString(L"HeaderAutomationName_Converter"); + full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data(); } - name = LocalizationStringUtil::GetLocalizedString(full, m_model->CategoryName); + + string::size_type found = full.find(L"%1"); + wstring strMode = m_model->CategoryName->Data(); + full = full.replace(found, 2, strMode); + + name = ref new String(full.c_str()); } AutomationProperties::SetName(Header, name); diff --git a/src/Calculator/Views/TitleBar.xaml.cpp b/src/Calculator/Views/TitleBar.xaml.cpp index 44f4a8c..6b8ab4d 100644 --- a/src/Calculator/Views/TitleBar.xaml.cpp +++ b/src/Calculator/Views/TitleBar.xaml.cpp @@ -37,9 +37,9 @@ namespace CalculatorApp Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded); Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded); #ifdef IS_STORE_BUILD - AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"AppName"); + AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"AppName"); #else - AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"DevAppName"); + AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"DevAppName"); #endif // IS_STORE_BUILD } diff --git a/src/Calculator/Views/UnitConverter.xaml.cpp b/src/Calculator/Views/UnitConverter.xaml.cpp index b94d838..cb404c2 100644 --- a/src/Calculator/Views/UnitConverter.xaml.cpp +++ b/src/Calculator/Views/UnitConverter.xaml.cpp @@ -40,6 +40,8 @@ using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::ViewManagement; +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + // Calculate number of 100-nanosecond intervals in 500 milliseconds. // There are 10,000 intervals in 1 ms. static const long long DURATION_500_MS = 10000 * 500; @@ -64,14 +66,14 @@ UnitConverter::UnitConverter() m_isAnimationEnabled = userSettings->AnimationsEnabled; auto resLoader = AppResourceProvider::GetInstance(); - m_chargesMayApplyText = resLoader->GetResourceString(L"DataChargesMayApply"); - m_failedToRefreshText = resLoader->GetResourceString(L"FailedToRefresh"); + m_chargesMayApplyText = resLoader.GetResourceString(L"DataChargesMayApply"); + m_failedToRefreshText = resLoader.GetResourceString(L"FailedToRefresh"); InitializeOfflineStatusTextBlock(); m_resultsFlyout = static_cast(Resources->Lookup(L"CalculationResultContextMenu")); - CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem"); - PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem"); + CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem"); + PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem"); } void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChangedEventArgs ^ e) @@ -163,7 +165,7 @@ void UnitConverter::SetFailedToRefreshStatus() void UnitConverter::InitializeOfflineStatusTextBlock() { auto resProvider = AppResourceProvider::GetInstance(); - std::wstring offlineStatusHyperlinkText = resProvider->GetResourceString(L"OfflineStatusHyperlinkText")->Data(); + std::wstring offlineStatusHyperlinkText = static_cast(resProvider.GetResourceString(L"OfflineStatusHyperlinkText"))->Data(); // The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'. // Break the string and assign pieces appropriately. @@ -243,9 +245,9 @@ void UnitConverter::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEvent void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { - auto that(this); - create_task(CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown)) - .then([that](String ^ pastedString) { that->Model->OnPaste(pastedString); }); + CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter).then([this](String ^ pastedString) { + Model->OnPaste(pastedString); + }); } void UnitConverter::AnimateConverter() diff --git a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp index 0d8972c..a944e89 100644 --- a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp +++ b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp @@ -42,10 +42,6 @@ namespace CalculatorUnitTests TEST_CLASS(CopyPasteManagerTest) { public: - CopyPasteManagerTest() - { - m_CopyPasteManager = ref new CopyPasteManager(); - } TEST_METHOD(FunctionalCopyPasteTest); TEST_METHOD(ValidateStandardPasteExpressionTest); TEST_METHOD(ValidateScientificPasteExpressionTest); @@ -58,36 +54,35 @@ namespace CalculatorUnitTests TEST_METHOD(ValidatePasteExpressionErrorStates) { wstring exp_TooLong = L""; - for (int i = 0; i < m_CopyPasteManager->MaxPasteableLength / 8; i++) + for (int i = 0; i < m_CopyPasteManager.MaxPasteableLength / 8; i++) { exp_TooLong += L"-1234567"; } VERIFY_ARE_EQUAL( - m_CopyPasteManager->ValidatePasteExpression( - StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(exp_TooLong.c_str()), L"Verify ValidatePasteExpression handles expressions up to max length"); exp_TooLong += L"1"; VERIFY_ARE_EQUAL( - m_CopyPasteManager->ValidatePasteExpression( + m_CopyPasteManager.ValidatePasteExpression( StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(L"NoOp"), L"Verify ValidatePasteExpression returns NoOp for strings over max length"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->ValidatePasteExpression( + m_CopyPasteManager.ValidatePasteExpression( StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(L"NoOp"), L"Verify empty string is invalid"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->ValidatePasteExpression( + m_CopyPasteManager.ValidatePasteExpression( StringReference(L"1a23f456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(L"NoOp"), L"Verify pasting unsupported strings for the current mode is invalid"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), StringReference(L"NoOp"), L"Verify pasting without a ViewMode or Category is invalid"); }; @@ -97,47 +92,47 @@ namespace CalculatorUnitTests vector results = {}; vector oneOperand = { L"123456" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123456", ViewMode::Standard), oneOperand); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123456", ViewMode::Standard), oneOperand); oneOperand = { L"123^456" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123^456", ViewMode::Standard), oneOperand); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123^456", ViewMode::Standard), oneOperand); vector twoOperands = { L"123", L"456" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123+456", ViewMode::Standard), twoOperands); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123-456", ViewMode::Standard), twoOperands); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123*456", ViewMode::Standard), twoOperands); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123/456", ViewMode::Standard), twoOperands); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123+456", ViewMode::Standard), twoOperands); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123-456", ViewMode::Standard), twoOperands); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123*456", ViewMode::Standard), twoOperands); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123/456", ViewMode::Standard), twoOperands); vector expOperand = { L"123e456" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e456", ViewMode::Standard), expOperand); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123e456", ViewMode::Standard), expOperand); expOperand = { L"123e4567" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e4567", ViewMode::Standard), expOperand); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123e4567", ViewMode::Standard), expOperand); vector twoOperandsParens = { L"((45)", L"(-30))" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens); }; TEST_METHOD(ValidateExtractOperandsErrors) { wstring exp_OperandLimit = L""; - for (int i = 0; i < m_CopyPasteManager->MaxOperandCount; i++) + for (int i = 0; i < m_CopyPasteManager.MaxOperandCount; i++) { exp_OperandLimit += L"+1"; } VERIFY_ARE_EQUAL( - m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), + m_CopyPasteManager.ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), 100, L"Verify ExtractOperands handles up to MaxOperandCount operands"); exp_OperandLimit += L"+1"; VERIFY_ARE_EQUAL( - m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), + m_CopyPasteManager.ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), 0, L"Verify ExtractOperands returns empty vector on too many operands"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->ExtractOperands(L"12e9999", ViewMode::Standard).size(), 1, L"Verify ExtractOperands handles up to 4 digit exponents"); + m_CopyPasteManager.ExtractOperands(L"12e9999", ViewMode::Standard).size(), 1, L"Verify ExtractOperands handles up to 4 digit exponents"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->ExtractOperands(L"12e10000", ViewMode::Standard).size(), + m_CopyPasteManager.ExtractOperands(L"12e10000", ViewMode::Standard).size(), 0, L"Verify ExtractOperands returns empty vector when the exponent is too long"); }; @@ -145,31 +140,31 @@ namespace CalculatorUnitTests TEST_METHOD(ValidateExpressionRegExMatch) { VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch(vector{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.ExpressionRegExMatch(vector{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), L"Verify empty list of operands returns false."); VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), L"Verify invalid ViewMode/CategoryGroups return false."); VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), L"Verify invalid ViewMode/CategoryGroups return false."); Logger::WriteMessage(L"Verify operand lengths > max return false."); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"10000000000000000000000000000000000000000000000000000000000000000" }, ViewMode::Programmer, CategoryGroupType::Calculator, @@ -177,12 +172,12 @@ namespace CalculatorUnitTests BitLength::BitLengthQWord)); VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), L"Verify operand values > max return false."); VERIFY_IS_TRUE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"((((((((((((((((((((123))))))))))))))))))))" }, ViewMode::Scientific, CategoryGroupType::Calculator, @@ -190,20 +185,20 @@ namespace CalculatorUnitTests BitLength::BitLengthUnknown), L"Verify sanitized operand is detected as within max length."); VERIFY_IS_TRUE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), L"Verify operand values == max return true."); Logger::WriteMessage(L"Verify all operands must match patterns."); - VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); - VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); - VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( + VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123", L"fab10" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); VERIFY_IS_TRUE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"1.23e+456", L"1.23e456", L".23e+456", L"123e-456", L"12e2", L"12e+2", L"12e-2", L"-12e2", L"-12e+2", L"-12e-2" }, ViewMode::Scientific, CategoryGroupType::Calculator, @@ -212,30 +207,34 @@ namespace CalculatorUnitTests L"Verify exponents are accepted in scientific mode."); VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch( + m_CopyPasteManager.ExpressionRegExMatch( vector{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), L"Verify all operands must be within maxlength"); VERIFY_IS_FALSE( - m_CopyPasteManager->ExpressionRegExMatch( - vector{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), + m_CopyPasteManager.ExpressionRegExMatch( + vector{ L"123", L"9223372036854775808" }, + ViewMode::Programmer, + CategoryGroupType::Calculator, + DecBase, + BitLength::BitLengthQWord), L"Verify all operand must be within max value."); }; TEST_METHOD(ValidateGetMaxOperandLengthAndValue) { - pair standardModeMaximums = make_pair(m_CopyPasteManager->MaxStandardOperandLength, 0); - pair scientificModeMaximums = make_pair(m_CopyPasteManager->MaxScientificOperandLength, 0); - pair converterModeMaximums = make_pair(m_CopyPasteManager->MaxConverterInputLength, 0); + pair standardModeMaximums = make_pair(m_CopyPasteManager.MaxStandardOperandLength, 0); + pair scientificModeMaximums = make_pair(m_CopyPasteManager.MaxScientificOperandLength, 0); + pair converterModeMaximums = make_pair(m_CopyPasteManager.MaxConverterInputLength, 0); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), standardModeMaximums, L"Verify Standard mode maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), scientificModeMaximums, L"Verify Scientific mode maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown), converterModeMaximums, L"Verify Converter mode maximum values"); @@ -245,108 +244,108 @@ namespace CalculatorUnitTests unsigned long long int ullByteMax = UINT8_MAX; Logger::WriteMessage(L"Verify Programmer Mode HexBase maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord), make_pair((size_t)16u, ullQwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord), make_pair((size_t)8u, ullDwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord), make_pair((size_t)4u, ullWordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte), make_pair((size_t)2u, ullByteMax)); Logger::WriteMessage(L"Verify Programmer Mode DecBase maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord), make_pair((size_t)19u, ullQwordMax >> 1)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord), make_pair((size_t)10u, ullDwordMax >> 1)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord), make_pair((size_t)5u, ullWordMax >> 1)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte), make_pair((size_t)3u, ullByteMax >> 1)); Logger::WriteMessage(L"Verify Programmer Mode OctBase maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord), make_pair((size_t)22u, ullQwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord), make_pair((size_t)11u, ullDwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord), make_pair((size_t)6u, ullWordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte), make_pair((size_t)3u, ullByteMax)); Logger::WriteMessage(L"Verify Programmer Mode BinBase maximum values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord), make_pair((size_t)64u, ullQwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord), make_pair((size_t)32u, ullDwordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord), make_pair((size_t)16u, ullWordMax)); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte), make_pair((size_t)8u, ullByteMax)); Logger::WriteMessage(L"Verify invalid ViewModes/Categories return 0 for max values"); VERIFY_ARE_EQUAL( - m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), + m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, - 1, BitLength::BitLengthUnknown), make_pair((size_t)0u, 0ull)); }; TEST_METHOD(ValidateSanitizeOperand) { - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"((1234"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1234))"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1234))"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"-1234"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"+1234"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"-(1234)"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"+(1234)"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"12-34"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"((((1234))))"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1'2'3'4"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"'''''1234''''"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1_2_3_4"), L"1234"); - VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"______1234___"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"((1234"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1234))"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1234))"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"-1234"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"+1234"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"-(1234)"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"+(1234)"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"12-34"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"((((1234))))"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1'2'3'4"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"'''''1234''''"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1_2_3_4"), L"1234"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"______1234___"), L"1234"); }; // Using unicode literals here until the encoding issues get figured out TEST_METHOD(ValidatePrefixCurrencySymbols) { // ¥5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A5\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A5\u0035"), L"5"); // ¤5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A4\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A4\u0035"), L"5"); // ₵5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B5\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20B5\u0035"), L"5"); // $5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u0024\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u0024\u0035"), L"5"); // ₡5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A1\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A1\u0035"), L"5"); // ₩5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A9\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A9\u0035"), L"5"); // ₪5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AA\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20AA\u0035"), L"5"); // ₦5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A6\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A6\u0035"), L"5"); // ₹5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B9\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20B9\u0035"), L"5"); // £5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A3\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A3\u0035"), L"5"); // €5 - VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AC\u0035"), L"5"); + VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20AC\u0035"), L"5"); }; TEST_METHOD(ValidateTryOperandToULL) @@ -354,199 +353,199 @@ namespace CalculatorUnitTests unsigned long long int result = 0; Logger::WriteMessage(L"Verify TryOperandToULL HexBase conversion"); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", HexBase, result)); VERIFY_ARE_EQUAL(result, 0x1234ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FF", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"FF", HexBase, result)); VERIFY_ARE_EQUAL(result, 0xFFull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FFFFFFFFFFFFFFFF", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"FFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", HexBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); Logger::WriteMessage(L"Verify TryOperandToULL DecBase conversion"); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", DecBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", DecBase, result)); VERIFY_ARE_EQUAL(result, 1234ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"18446744073709551615", DecBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"18446744073709551615", DecBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"018446744073709551615", DecBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"018446744073709551615", DecBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); Logger::WriteMessage(L"Verify TryOperandToULL OctBase conversion"); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"777", OctBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"777", OctBase, result)); VERIFY_ARE_EQUAL(result, 0777ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0777", OctBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0777", OctBase, result)); VERIFY_ARE_EQUAL(result, 0777ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1777777777777777777777", OctBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1777777777777777777777", OctBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01777777777777777777777", OctBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"01777777777777777777777", OctBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); Logger::WriteMessage(L"Verify TryOperandToULL BinBase conversion"); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111", BinBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1111", BinBase, result)); VERIFY_ARE_EQUAL(result, 0b1111ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0010", BinBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0010", BinBase, result)); VERIFY_ARE_EQUAL(result, 0b10ull); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); Logger::WriteMessage(L"Verify TryOperandToULL invalid numberBase defaults to DecBase"); - VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", 128, result)); + VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", 128, result)); VERIFY_ARE_EQUAL(result, 1234ull); Logger::WriteMessage(L"Verify TryOperandToULL returns false when input is invalid or strtoull throws exceptions"); // Max values + 1 - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"0xFFFFFFFFFFFFFFFFF1", HexBase, result)); - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"18446744073709551616", DecBase, result)); - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"2000000000000000000000", OctBase, result)); - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"0xFFFFFFFFFFFFFFFFF1", HexBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"18446744073709551616", DecBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"2000000000000000000000", OctBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); // Invalid values/characters - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"-1", DecBase, result)); - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"5555", BinBase, result)); - VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"xyz", BinBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"-1", DecBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"5555", BinBase, result)); + VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"xyz", BinBase, result)); }; TEST_METHOD(ValidateStandardScientificOperandLength) { - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L""), 0); - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"0.2"), 1); - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"1.2"), 2); - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"0."), 0); - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"12345"), 5); - VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"-12345"), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L""), 0); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"0.2"), 1); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"1.2"), 2); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"0."), 0); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"12345"), 5); + VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"-12345"), 6); }; TEST_METHOD(ValidateProgrammerOperandLength) { - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001b", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001B", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b1001", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0B1001", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0y1001", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0Y1001", BinBase), 4); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b", BinBase), 1); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001b", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001B", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0b1001", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0B1001", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0y1001", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0Y1001", BinBase), 4); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0b", BinBase), 1); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123456", OctBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0t123456", OctBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0T123456", OctBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0o123456", OctBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0O123456", OctBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123456", OctBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0t123456", OctBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0T123456", OctBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0o123456", OctBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0O123456", OctBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"", DecBase), 0); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-", DecBase), 0); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"12345", DecBase), 5); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-12345", DecBase), 5); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0n12345", DecBase), 5); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0N12345", DecBase), 5); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"", DecBase), 0); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"-", DecBase), 0); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"12345", DecBase), 5); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"-12345", DecBase), 5); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0n12345", DecBase), 5); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0N12345", DecBase), 5); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABC", HexBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0x123ABC", HexBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0X123ABC", HexBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCh", HexBase), 6); - VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCH", HexBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABC", HexBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0x123ABC", HexBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0X123ABC", HexBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABCh", HexBase), 6); + VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABCH", HexBase), 6); }; private: - CopyPasteManager ^ m_CopyPasteManager; + CopyPasteManager m_CopyPasteManager; String^ ValidateStandardPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown); } String^ ValidateScientificPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown); } String^ ValidateConverterPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, BitLength::BitLengthUnknown); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, BitLength::BitLengthUnknown); } String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord); } String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord); } String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord); } String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte); } String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord); } String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord); } String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord); } String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte); } String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord); } String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord); } String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord); } String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte); } String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord); } String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord); } String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord); } String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText) { - return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte); + return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte); } }; @@ -603,38 +602,41 @@ namespace CalculatorUnitTests void CopyPasteManagerTest::ValidateStandardPasteExpressionTest() { - String ^ positiveInput[] = { - L"123", - L"+123", - L"-133", - L"12345.", - L"+12.34", - L"12.345", - L"012.034", - L"-23.032", - L"-.123", - L".1234", - L"012.012", - L"123+456", - L"123+-234", - L"123*-345", - L"123*4*-3", - L"123*+4*-3", - L"1,234", - L"1 2 3", - L"\n\r1,234\n", - L"\f\n1+2\t\r\v\x85", - L"\n 1+\n2 ", - L"1\"2", - L"1234567891234567" /*boundary condition <=16 digits*/, - L"2+2=", - L"2+2= ", - L"1.2e23", - L"12345e-23", - + String ^ positiveInput[] = { L"123", + L"+123", + L"-133", + L"12345.", + L"+12.34", + L"12.345", + L"012.034", + L"-23.032", + L"-.123", + L".1234", + L"012.012", + L"123+456", + L"123+-234", + L"123*-345", + L"123*4*-3", + L"123*+4*-3", + L"1,234", + L"1 2 3", + L"\n\r1,234\n", + L"\f\n1+2\t\r\v\x85", + L"\n 1+\n2 ", + L"1\"2", + L"1234567891234567" /*boundary condition <=16 digits*/, + L"2+2=", + L"2+2= ", + L"1.2e23", + L"12345e-23", + }; - String ^ negativeInput[] = { L"(123)+(456)", L"abcdef", L"xyz", L"ABab", L"e+234", L"12345678912345678" /*boundary condition: greater than 16 digits*/, - L"SIN(2)", L"2+2==", L"2=+2", L"2%2", L"10^2" }; + String ^ negativeInput[] = { L"(123)+(456)", L"abcdef", + L"xyz", L"ABab", + L"e+234", L"12345678912345678" /*boundary condition: greater than 16 digits*/, + L"SIN(2)", L"2+2==", + L"2=+2", L"2%2", + L"10^2" }; ASSERT_POSITIVE_TESTCASES(ValidateStandardPasteExpression, positiveInput); ASSERT_NEGATIVE_TESTCASES(ValidateStandardPasteExpression, negativeInput); @@ -672,14 +674,19 @@ namespace CalculatorUnitTests "-(432+3232)", "-(+(-3213)+(-2312))", "-(-(432+3232))", - L"1.2e23" /*unsigned exponent*/, + L"1.2e23"/*unsigned exponent*/, L"12^2", L"-12.12^-2", L"61%99" L"-6.1%99" }; - String - ^ negativeInput[] = { L"abcdef", L"xyz", L"ABab", L"e+234", L"123456789123456781234567890123456" /*boundary condition: greater than 32 digits*/, - L"SIN(2)", L"2+2==", L"2=+2" }; + String ^ negativeInput[] = { L"abcdef", + L"xyz", + L"ABab", + L"e+234", + L"123456789123456781234567890123456" /*boundary condition: greater than 32 digits*/, + L"SIN(2)", + L"2+2==", + L"2=+2" }; ASSERT_POSITIVE_TESTCASES(ValidateScientificPasteExpression, positiveInput); ASSERT_NEGATIVE_TESTCASES(ValidateScientificPasteExpression, negativeInput); @@ -1065,8 +1072,8 @@ namespace CalculatorUnitTests void CopyPasteManagerTest::ValidateProgrammerOctPasteExpressionTest() { - String ^ qwordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", - L"\n 1+\n2 ", L"1\"2", L"(123)+(456)", L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u", + String ^ qwordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", + L"\n 1+\n2 ", L"1\"2", L"(123)+(456)", L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u", L"1234ul", L"1234ULL", L"2+2=", L"2+2= ", L"127%71" }; String ^ qwordNegativeInput[] = { L"+123", L"1.23", @@ -1092,7 +1099,7 @@ namespace CalculatorUnitTests L"1234ulll", L"2+2==", L"2=+2", - L"89%12" }; + L"89%12"}; ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordPositiveInput); ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordNegativeInput); diff --git a/src/CalculatorUnitTests/HistoryTests.cpp b/src/CalculatorUnitTests/HistoryTests.cpp index becf1b4..f4713c1 100644 --- a/src/CalculatorUnitTests/HistoryTests.cpp +++ b/src/CalculatorUnitTests/HistoryTests.cpp @@ -75,7 +75,7 @@ namespace CalculatorFunctionalTests { m_standardViewModel->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands()); m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); - m_standardViewModel->SetPrimaryDisplay(e->Result, false /*IsError*/); + m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false /*IsError*/); m_standardViewModel->IsFToEEnabled = false; }