Replace wstring used in public methods by Platform::String in CalcViewModel (#758)

This commit is contained in:
Rudy Huyn 2019-11-04 17:16:16 -08:00 committed by GitHub
parent 44e1984f6b
commit 93f1f784bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 514 additions and 538 deletions

View File

@ -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.

View File

@ -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;
static AppResourceProvider ^ s_instance = ref new AppResourceProvider();
return s_instance;
}

View File

@ -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
{
class AppResourceProvider
public ref class AppResourceProvider sealed
{
public:
static AppResourceProvider& GetInstance();
static AppResourceProvider ^ GetInstance();
Platform::String ^ GetResourceString(_In_ Platform::String ^ key);
Platform::String ^ GetCEngineString(_In_ Platform::String ^ key);

View File

@ -9,6 +9,7 @@
using namespace CalculatorApp;
using namespace CalculationManager;
using namespace Platform;
using namespace std;
CalculatorDisplay::CalculatorDisplay()
@ -31,7 +32,7 @@ void CalculatorDisplay::SetPrimaryDisplay(_In_ const wstring& displayStringValue
{
if (auto calcVM = m_callbackReference.Resolve<ViewModel::StandardCalculatorViewModel>())
{
calcVM->SetPrimaryDisplay(displayStringValue, isError);
calcVM->SetPrimaryDisplay(StringReference(displayStringValue.c_str()), isError);
}
}
}

View File

@ -15,7 +15,7 @@ using namespace Windows::Foundation;
using namespace Windows::System;
using namespace Windows::ApplicationModel::DataTransfer;
String ^ CopyPasteManager::supportedFormats[] = { StandardDataFormats::Text };
StringReference PasteErrorString(L"NoOp");
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);
}
task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
IAsyncOperation<String ^> ^ CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{
// Retrieve the text in the clipboard
auto dataPackageView = Clipboard::GetContent();
@ -76,36 +76,29 @@ task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupTy
//-- 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_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_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());
});
}
int CopyPasteManager::ClipboardTextFormat()
bool CopyPasteManager::HasStringToPaste()
{
const auto dataPackageView = Clipboard::GetContent();
for (int i = 0; i < RTL_NUMBER_OF(supportedFormats); i++)
{
if (dataPackageView->Contains(supportedFormats[i]))
{
return i;
}
}
return -1;
return Clipboard::GetContent()->Contains(StandardDataFormats::Text);
}
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, BitLength bitLengthType)
{
return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType);
return 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,
@ -116,16 +109,14 @@ String ^ CopyPasteManager::ValidatePasteExpression(
{
// return NoOp to indicate don't paste anything.
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
return StringReference(PasteErrorString);
return PasteErrorString;
}
wstring pasteExpression = pastedText->Data();
// Get english translated expression
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression);
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pastedText);
// Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333
pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data());
wstring 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'=')
@ -139,7 +130,7 @@ String ^ CopyPasteManager::ValidatePasteExpression(
if (operands.empty())
{
// return NoOp to indicate don't paste anything.
return StringReference(PasteErrorString);
return PasteErrorString;
}
if (modeType == CategoryGroupType::Converter)
@ -151,10 +142,10 @@ String ^ CopyPasteManager::ValidatePasteExpression(
if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType))
{
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
return StringReference(PasteErrorString);
return PasteErrorString;
}
return ref new String(pastedText->Data());
return pastedText;
}
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode)
@ -593,3 +584,8 @@ 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;
}

View File

@ -19,24 +19,19 @@ namespace CalculatorApp
inline constexpr auto OctBase = 7;
inline constexpr auto BinBase = 8;
class CopyPasteManager
public ref class CopyPasteManager sealed
{
public:
static void CopyToClipboard(Platform::String ^ stringToCopy);
static concurrency::task<Platform::String ^> GetStringToPaste(
static Windows::Foundation::IAsyncOperation<Platform::String ^>^ GetStringToPaste(
CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase = -1,
CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown);
static bool HasStringToPaste()
{
return ClipboardTextFormat() >= 0;
}
static constexpr auto PasteErrorString = L"NoOp";
int programmerNumberBase,
CalculatorApp::Common::BitLength bitLengthType);
static bool HasStringToPaste();
static bool IsErrorMessage(Platform::String ^ message);
private:
static int ClipboardTextFormat();
static Platform::String
^ ValidatePasteExpression(
Platform::String ^ pastedText,
@ -84,8 +79,6 @@ namespace CalculatorApp
static constexpr size_t MaxExponentLength = 4;
static constexpr size_t MaxProgrammerBitLength = 64;
static Platform::String ^ supportedFormats[];
friend class CalculatorUnitTests::CopyPasteManagerTest;
};
}

View File

@ -519,7 +519,7 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs
auto navView = buttons.first->second.Resolve<MUXC::NavigationView>();
auto appViewModel = safe_cast<ApplicationViewModel ^>(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<IObservableVector<Object ^> ^>(navView->MenuItemsSource);

View File

@ -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<wstring, wstring> LocalizationService::GetTokenToReadableNameMap()
unordered_map<wstring, wstring> 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<wstring, wstring> 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;
}
}

View File

@ -58,10 +58,11 @@ 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;

View File

@ -169,20 +169,21 @@ namespace CalculatorApp
}
}
Platform::String ^ GetEnglishValueFromLocalizedDigits(const std::wstring& localizedString) const
Platform::String ^ GetEnglishValueFromLocalizedDigits(Platform::String ^ localizedString) const
{
if (m_resolvedName == L"en-US")
{
return ref new Platform::String(localizedString.c_str());
return localizedString;
}
size_t i = 0;
size_t length = localizedString.size();
auto localizedStringData = localizedString->Data();
size_t length = localizedString->Length();
std::unique_ptr<wchar_t[]> englishString(new wchar_t[length + 1]); // +1 for the null termination
for (; i < length; ++i)
{
wchar_t ch = localizedString[i];
wchar_t ch = localizedStringData[i];
if (!IsEnUsDigit(ch))
{
for (int j = 0; j < 10; ++j)
@ -281,18 +282,17 @@ namespace CalculatorApp
return m_numberGrouping;
}
void RemoveGroupSeparators(const wchar_t* value, const size_t length, std::wstring* rawValue) const
Platform::String ^ RemoveGroupSeparators(Platform::String ^ source) const
{
rawValue->clear();
rawValue->reserve(length);
for (size_t i = 0; i < length; i++)
std::wstringstream stream;
for (auto c = source->Begin(); c < source->End(); ++c)
{
if (value[i] != L' ' && value[i] != m_numberGroupSeparator)
if (*c != L' ' && *c != m_numberGroupSeparator)
{
rawValue->append(1, value[i]);
stream << *c;
}
}
return ref new Platform::String(stream.str().c_str());
}
Platform::String ^ GetCalendarIdentifier() const

View File

@ -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,50 +9,88 @@ namespace CalculatorApp
{
namespace Common
{
class LocalizationStringUtil
class LocalizationStringUtilInternal
{
public:
static std::wstring GetLocalizedString(const wchar_t* pMessage, ...)
static Platform::String ^ GetLocalizedString(Platform::String ^ pMessage, ...)
{
std::wstring returnString = L"";
const UINT32 length = 1024;
std::unique_ptr<wchar_t[]> spBuffer = std::unique_ptr<wchar_t[]>(new wchar_t[length]);
va_list args = NULL;
va_start(args, pMessage);
DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage, 0, 0, spBuffer.get(), length, &args);
DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args);
va_end(args);
if (fmtReturnVal != 0)
{
returnString = spBuffer.get();
return ref new Platform::String(spBuffer.get());
}
return returnString;
}
template <typename... T>
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())
else
{
return;
return ref new Platform::String();
}
// If the formatVariable already has a value, we don't need to set it again. Simply return.
if (formatVariable != nullptr && !formatVariable->IsEmpty())
{
return;
}
formatVariable = AppResourceProvider::GetInstance().GetResourceString(resourceKey);
}
};
public
ref class LocalizationStringUtil sealed
{
public:
static Platform::String
^ GetLocalizedString(Platform::String ^ pMessage)
{
return LocalizationStringUtilInternal::GetLocalizedString(pMessage);
}
static Platform::String
^ GetLocalizedString(
Platform::String ^ pMessage,
Platform::String ^ param1)
{
return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data());
}
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);
}
};
}
}

View File

@ -368,33 +368,28 @@ NavCategoryGroup::NavCategoryGroup(const NavCategoryGroupInitializer& groupIniti
m_GroupType = groupInitializer.type;
auto resProvider = AppResourceProvider::GetInstance();
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);
m_Name = resProvider->GetResourceString(StringReference(groupInitializer.headerResourceKey));
String ^ groupMode = resProvider->GetResourceString(StringReference(groupInitializer.modeResourceKey));
String ^ automationName = resProvider->GetResourceString(StringReference(groupInitializer.automationResourceKey));
String ^ navCategoryHeaderAutomationNameFormat = resProvider.GetResourceString(L"NavCategoryHeader_AutomationNameFormat");
m_AutomationName =
ref new String(LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat->Data(), automationName->Data()).c_str());
String ^ navCategoryHeaderAutomationNameFormat = resProvider->GetResourceString(L"NavCategoryHeader_AutomationNameFormat");
m_AutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat, automationName);
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 = ref new String(
LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat->Data(), categoryName->Data(), m_Name->Data()).c_str());
String ^ categoryName = resProvider->GetResourceString(nameResourceKey + "Text");
String ^ categoryAutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat, categoryName, m_Name);
m_Categories->Append(ref new NavCategory(
categoryName,
categoryAutomationName,
StringReference(categoryInitializer.glyph),
resProvider.GetResourceString(nameResourceKey + "AccessKey"),
resProvider->GetResourceString(nameResourceKey + "AccessKey"),
groupMode,
categoryInitializer.viewMode,
categoryInitializer.supportsNegative));

View File

@ -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<ICurrencyHttpClient> clie
m_ratioFormatter->IsDecimalPointAlwaysDisplayed = true;
m_ratioFormatter->FractionDigits = FORMATTER_RATE_FRACTION_PADDING;
m_ratioFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyFromToRatioFormat")->Data();
m_timestampFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyTimestampFormat")->Data();
m_ratioFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyFromToRatioFormat");
m_timestampFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyTimestampFormat");
}
CurrencyDataLoader::~CurrencyDataLoader()
@ -300,16 +300,18 @@ pair<wstring, wstring> CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const U
double ratio = (iter2->second).ratio;
double rounded = RoundCurrencyRatio(ratio);
wstring digitSymbol = wstring{ LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1') };
wstring roundedFormat = m_ratioFormatter->Format(rounded)->Data();
auto digit = LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1');
auto digitSymbol = ref new String(&digit, 1);
auto roundedFormat = m_ratioFormatter->Format(rounded);
wstring ratioString = LocalizationStringUtil::GetLocalizedString(
m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.abbreviation.c_str(), roundedFormat.c_str(), unit2.abbreviation.c_str());
auto ratioString = LocalizationStringUtil::GetLocalizedString(
m_ratioFormat, digitSymbol, StringReference(unit1.abbreviation.c_str()), roundedFormat, StringReference(unit2.abbreviation.c_str()));
wstring accessibleRatioString = LocalizationStringUtil::GetLocalizedString(
m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.accessibleName.c_str(), roundedFormat.c_str(), unit2.accessibleName.c_str());
auto accessibleRatioString =
LocalizationStringUtil::GetLocalizedString(
m_ratioFormat, digitSymbol, StringReference(unit1.accessibleName.c_str()), roundedFormat, StringReference(unit2.accessibleName.c_str()));
return make_pair(ratioString, accessibleRatioString);
return make_pair(ratioString->Data(), accessibleRatioString->Data());
}
}
}
@ -747,21 +749,19 @@ void CurrencyDataLoader::UpdateDisplayedTimestamp()
}
wstring CurrencyDataLoader::GetCurrencyTimestamp()
{
wstring timestamp = L"";
DateTime epoch{};
if (m_cacheTimestamp.UniversalTime != epoch.UniversalTime)
{
DateTimeFormatter ^ dateFormatter = ref new DateTimeFormatter(L"shortdate");
wstring date = dateFormatter->Format(m_cacheTimestamp)->Data();
auto date = dateFormatter->Format(m_cacheTimestamp);
DateTimeFormatter ^ timeFormatter = ref new DateTimeFormatter(L"shorttime");
wstring time = timeFormatter->Format(m_cacheTimestamp)->Data();
auto time = timeFormatter->Format(m_cacheTimestamp);
timestamp = LocalizationStringUtil::GetLocalizedString(m_timestampFormat.c_str(), date.c_str(), time.c_str());
return LocalizationStringUtil::GetLocalizedString(m_timestampFormat, date, time)->Data();
}
return timestamp;
return L"";
}
#pragma optimize("", off) // Turn off optimizations to work around DevDiv 393321

View File

@ -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<UCM::IViewModelCurrencyCallback> m_vmCallback;
Windows::Globalization::NumberFormatting::DecimalFormatter ^ m_ratioFormatter;
std::wstring m_ratioFormat;
Platform::String ^ m_ratioFormat;
Windows::Foundation::DateTime m_cacheTimestamp;
std::wstring m_timestampFormat;
Platform::String ^ m_timestampFormat;
CurrencyLoadStatus m_loadStatus;

View File

@ -953,7 +953,7 @@ void UnitConverterDataLoader::GetConversionData(_In_ unordered_map<ViewMode, uno
wstring UnitConverterDataLoader::GetLocalizedStringName(String ^ stringId)
{
return AppResourceProvider::GetInstance().GetResourceString(stringId)->Data();
return AppResourceProvider::GetInstance()->GetResourceString(stringId)->Data();
}
void UnitConverterDataLoader::GetExplicitConversionData(_In_ unordered_map<int, unordered_map<int, UCM::ConversionData>>& unitToUnitConversionList)

View File

@ -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,16 +218,14 @@ void DateCalculatorViewModel::UpdateDisplayResult()
void DateCalculatorViewModel::UpdateStrDateDiffResultAutomationName()
{
String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_DifferenceResultAutomationName");
wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateDiffResult->Data());
StrDateDiffResultAutomationName = ref new String(localizedAutomationName.c_str());
String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_DifferenceResultAutomationName");
StrDateDiffResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateDiffResult);
}
void DateCalculatorViewModel::UpdateStrDateResultAutomationName()
{
String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_ResultingDateAutomationName");
wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateResult->Data());
StrDateResultAutomationName = ref new String(localizedAutomationName.c_str());
String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_ResultingDateAutomationName");
StrDateResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateResult);
}
void DateCalculatorViewModel::InitializeDateOutputFormats(_In_ String ^ calendarIdentifier)
@ -247,7 +245,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)
@ -257,11 +255,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
@ -285,11 +283,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();
}
}
@ -310,11 +308,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();
}
}
@ -335,11 +333,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();
}
}
@ -354,11 +352,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());

View File

@ -371,9 +371,10 @@ void HistoryViewModel::UpdateItemSize()
ItemSize = Items->Size;
}
void HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ &formatVariable)
Platform::String ^ HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ formatVariable)
{
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(resourceKey, formatVariable);
String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(resourceKey), formatVariable);
HistoryAnnouncement = CalculatorAnnouncement::GetHistoryClearedAnnouncement(announcement);
return announcement;
}

View File

@ -68,7 +68,7 @@ namespace CalculatorApp
void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode);
bool IsValid(_In_ CalculationManager::HISTORYITEM item);
void MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ &formatVariable);
Platform::String ^ MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ formatVariable);
friend class CalculatorDisplay;
void UpdateItemSize();

View File

@ -25,6 +25,7 @@ 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;
@ -93,15 +94,16 @@ StandardCalculatorViewModel::StandardCalculatorViewModel()
, m_localizedNoRightParenthesisAddedFormat(nullptr)
{
WeakReference calculatorViewModel(this);
auto appResourceProvider = AppResourceProvider::GetInstance();
m_calculatorDisplay.SetCallback(calculatorViewModel);
m_expressionAutomationNameFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorExpression);
m_localizedCalculationResultAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorResults);
m_expressionAutomationNameFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorExpression);
m_localizedCalculationResultAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorResults);
m_localizedCalculationResultDecimalAutomationFormat =
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);
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);
// Initialize the Automation Name
CalculationResultAutomationName = GetLocalizedStringFormat(m_localizedCalculationResultAutomationFormat, m_DisplayValue);
@ -192,13 +194,13 @@ String ^ StandardCalculatorViewModel::GetNarratorStringReadRawNumbers(_In_ Strin
return ref new String(wss.str().c_str());
}
void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ wstring const& displayStringValue, _In_ bool isError)
void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ String ^ displayStringValue, _In_ bool isError)
{
String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue, isError);
String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue->Data(), isError);
// Set this variable before the DisplayValue is modified, Otherwise the DisplayValue will
// not match what the narrator is saying
m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue, localizedDisplayStringValue, isError);
m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue->Data(), localizedDisplayStringValue, isError);
AreAlwaysOnTopResultsUpdated = false;
if (DisplayValue != localizedDisplayStringValue)
@ -239,10 +241,10 @@ void StandardCalculatorViewModel::SetOpenParenthesisCountNarratorAnnouncement()
wstring localizedParenthesisCount = to_wstring(m_OpenParenthesisCount).c_str();
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedParenthesisCount);
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::OpenParenthesisCountAutomationFormat,
String ^ announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::OpenParenthesisCountAutomationFormat),
m_localizedOpenParenthesisCountChangedAutomationFormat,
localizedParenthesisCount.c_str());
StringReference(localizedParenthesisCount.c_str()));
Announcement = CalculatorAnnouncement::GetOpenParenthesisCountChangedAnnouncement(announcement);
}
@ -255,7 +257,7 @@ void StandardCalculatorViewModel::OnNoRightParenAdded()
void StandardCalculatorViewModel::SetNoParenAddedNarratorAnnouncement()
{
String ^ announcement =
LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::NoParenthesisAdded, m_localizedNoRightParenthesisAddedFormat);
LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::NoParenthesisAdded), m_localizedNoRightParenthesisAddedFormat);
Announcement = CalculatorAnnouncement::GetNoRightParenthesisAddedAnnouncement(announcement);
}
@ -352,7 +354,7 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<vector<pair<wstri
type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator;
}
auto currentTokenString = ref new String(currentToken.first.c_str());
auto currentTokenString = StringReference(currentToken.first.c_str());
if (i < m_ExpressionTokens->Size)
{
auto existingItem = m_ExpressionTokens->GetAt(i);
@ -696,7 +698,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);
}
@ -727,7 +729,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
}
// Ensure that the paste happens on the UI thread
CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)
create_task(CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType))
.then([that, mode](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
}
@ -739,7 +741,7 @@ CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(
void StandardCalculatorViewModel::OnPaste(String ^ pastedString)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (pastedString == StringReference(CopyPasteManager::PasteErrorString))
if (CopyPasteManager::IsErrorMessage(pastedString))
{
this->DisplayPasteError();
return;
@ -893,7 +895,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter)
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::MemoryCleared, m_localizedMemoryCleared);
String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryCleared), m_localizedMemoryCleared);
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
}
@ -1046,8 +1048,8 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed()
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MemorySave, m_localizedMemorySavedAutomationFormat, m_DisplayValue->Data());
String ^ announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemorySave), m_localizedMemorySavedAutomationFormat, m_DisplayValue);
Announcement = CalculatorAnnouncement::GetMemoryItemAddedAnnouncement(announcement);
}
@ -1062,8 +1064,8 @@ void StandardCalculatorViewModel::OnMemoryItemChanged(unsigned int indexOfMemory
wstring localizedIndex = to_wstring(indexOfMemory + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MemoryItemChanged, m_localizedMemoryItemChangedAutomationFormat, localizedIndex.c_str(), localizedValue->Data());
String ^ announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemChanged), m_localizedMemoryItemChangedAutomationFormat, StringReference(localizedIndex.c_str()), localizedValue);
Announcement = CalculatorAnnouncement::GetMemoryItemChangedAnnouncement(announcement);
}
@ -1131,8 +1133,8 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
wstring localizedIndex = to_wstring(boxedPosition->Value + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MemoryItemCleared, m_localizedMemoryItemClearedAutomationFormat, localizedIndex.c_str());
String ^ announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemCleared), m_localizedMemoryItemClearedAutomationFormat, StringReference(localizedIndex.c_str()));
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
}
@ -1212,9 +1214,7 @@ String ^ StandardCalculatorViewModel::GetRawDisplayValue()
}
else
{
wstring rawValue;
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
return ref new String(rawValue.c_str());
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue);
}
}
@ -1223,8 +1223,7 @@ 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)
{
String ^ localizedString = ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), displayValue->Data()).c_str());
return localizedString;
return LocalizationStringUtil::GetLocalizedString(format, displayValue);
}
void StandardCalculatorViewModel::ResetDisplay()
@ -1585,7 +1584,7 @@ size_t StandardCalculatorViewModel::LengthWithoutPadding(wstring str)
wstring StandardCalculatorViewModel::AddPadding(wstring binaryString)
{
if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(binaryString) == L"0")
if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(StringReference(binaryString.c_str())) == L"0")
{
return binaryString;
}
@ -1684,7 +1683,7 @@ void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
{
pair<wstring, int> p = m_tokens->at(pos);
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text->Data());
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text);
p.first = englishString->Data();
int commandPos = p.second;
@ -1808,8 +1807,8 @@ void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
void StandardCalculatorViewModel::OnMaxDigitsReached()
{
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MaxDigitsReachedFormat, m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName->Data());
String ^ announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MaxDigitsReachedFormat), m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName);
Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement);
}
@ -1828,11 +1827,11 @@ NarratorAnnouncement ^ StandardCalculatorViewModel::GetDisplayUpdatedNarratorAnn
}
else
{
announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::ButtonPressFeedbackFormat,
announcement = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::ButtonPressFeedbackFormat),
m_localizedButtonPressFeedbackAutomationFormat,
m_CalculationResultAutomationName->Data(),
m_feedbackForButtonPress->Data());
m_CalculationResultAutomationName,
m_feedbackForButtonPress);
}
// Make sure we don't accidentally repeat an announcement.

View File

@ -340,7 +340,7 @@ namespace CalculatorApp
void OnPinUnpinCommand(Platform::Object ^ parameter);
void OnInputChanged();
void SetPrimaryDisplay(_In_ std::wstring const& displayString, _In_ bool isError);
void SetPrimaryDisplay(Platform::String ^ displayString, _In_ bool isError);
void DisplayPasteError();
void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens);
void SetExpressionDisplay(

View File

@ -137,12 +137,12 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConver
m_currencyMaxFractionDigits = m_currencyFormatter->FractionDigits;
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,8 +515,10 @@ void UnitConverterViewModel::OnPasteCommand(Platform::Object ^ parameter)
// Ensure that the paste happens on the UI thread
// EventWriteClipboardPaste_Start();
// Any converter ViewMode is fine here.
CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode))
.then([this](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
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());
}
void UnitConverterViewModel::InitializeView()
@ -650,7 +652,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);
}
@ -665,17 +667,18 @@ 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 refreshTask = create_task([this] { return m_model->RefreshCurrencyRatios().get(); });
auto that(this);
auto refreshTask = create_task([that] { return that->m_model->RefreshCurrencyRatios().get(); });
refreshTask.then(
[this](const pair<bool, wstring>& refreshResult) {
[that](const pair<bool, wstring>& refreshResult) {
bool didLoad = refreshResult.first;
wstring timestamp = refreshResult.second;
OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/);
OnCurrencyDataLoadFinished(didLoad);
that->OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/);
that->OnCurrencyDataLoadFinished(didLoad);
},
task_continuation_context::use_current());
}
@ -878,7 +881,7 @@ NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wch
void UnitConverterViewModel::OnPaste(String ^ stringToPaste)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (stringToPaste == StringReference(CopyPasteManager::PasteErrorString))
if (CopyPasteManager::IsErrorMessage(stringToPaste))
{
this->DisplayPasteError();
return;
@ -954,8 +957,7 @@ String ^ UnitConverterViewModel::GetLocalizedAutomationName(_In_ String ^ displa
format = m_localizedValueFromDecimalFormat;
}
wstring localizedResult = LocalizationStringUtil::GetLocalizedString(format->Data(), displayvalue->Data(), unitname->Data());
return ref new String(localizedResult.c_str());
return LocalizationStringUtil::GetLocalizedString(format, displayvalue, unitname);
}
String
@ -965,11 +967,7 @@ String
_In_ String ^ toValue,
_In_ String ^ toUnit)
{
String ^ localizedString =
ref new String(LocalizationStringUtil::GetLocalizedString(
m_localizedConversionResultFormat->Data(), fromValue->Data(), fromUnit->Data(), toValue->Data(), toUnit->Data())
.c_str());
return localizedString;
return LocalizationStringUtil::GetLocalizedString(m_localizedConversionResultFormat, fromValue, fromUnit, toValue, toUnit);
}
void UnitConverterViewModel::UpdateValue1AutomationName()
@ -990,9 +988,9 @@ void UnitConverterViewModel::UpdateValue2AutomationName()
void UnitConverterViewModel::OnMaxDigitsReached()
{
String ^ format = AppResourceProvider::GetInstance().GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat);
const wstring& announcement = LocalizationStringUtil::GetLocalizedString(format->Data(), m_lastAnnouncedConversionResult->Data());
Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(StringReference(announcement.c_str()));
String ^ format = AppResourceProvider::GetInstance()->GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat);
auto announcement = LocalizationStringUtil::GetLocalizedString(format, m_lastAnnouncedConversionResult);
Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement);
}
bool UnitConverterViewModel::UnitsAreValid()
@ -1002,17 +1000,18 @@ bool UnitConverterViewModel::UnitsAreValid()
void UnitConverterViewModel::StartConversionResultTimer()
{
m_conversionResultTaskHelper = make_unique<ConversionResultTaskHelper>(CONVERSION_FINALIZED_DELAY_IN_MS, [this]() {
if (UnitsAreValid())
auto that(this);
m_conversionResultTaskHelper = make_unique<ConversionResultTaskHelper>(CONVERSION_FINALIZED_DELAY_IN_MS, [that]() {
if (that->UnitsAreValid())
{
String ^ valueFrom = m_Value1Active ? m_Value1 : m_Value2;
String ^ valueTo = m_Value1Active ? m_Value2 : m_Value1;
String ^ valueFrom = that->m_Value1Active ? that->m_Value1 : that->m_Value2;
String ^ valueTo = that->m_Value1Active ? that->m_Value2 : that->m_Value1;
}
});
}
String ^ SupplementaryResult::GetLocalizedAutomationName()
{
auto format = AppResourceProvider::GetInstance().GetResourceString("SupplementaryUnit_AutomationName");
return ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), this->Value->Data(), this->Unit->Name->Data()).c_str());
auto format = AppResourceProvider::GetInstance()->GetResourceString("SupplementaryUnit_AutomationName");
return LocalizationStringUtil::GetLocalizedString(format, this->Value, this->Unit->Name);
}

View File

@ -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")->Data(), to_wstring(BUILD_YEAR).c_str());
AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str());
LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("AboutControlCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
AboutControlCopyrightRun->Text = copyrightText;
}
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;
}

View File

@ -63,11 +63,7 @@ CalculationResult::CalculationResult()
Platform::String ^ CalculationResult::GetRawDisplayValue()
{
std::wstring rawValue;
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
return ref new Platform::String(rawValue.c_str());
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue);
}
void CalculationResult::OnApplyTemplate()

View File

@ -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,8 +18,6 @@ using namespace Windows::UI::Xaml::Data;
String ^ RadixButton::GetRawDisplayValue()
{
wstring rawValue;
String ^ radixContent = Content->ToString();
LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent->Data(), radixContent->Length(), &rawValue);
return ref new String(rawValue.c_str());
return LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent);
}

View File

@ -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:

View File

@ -59,8 +59,8 @@ Calculator::Calculator()
m_displayFlyout = static_cast<MenuFlyout ^>(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,24 +149,21 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
}));
}
std::wstring Calculator::GetCurrentLayoutState()
Platform::String ^ Calculator::GetCurrentLayoutState()
{
std::wstring state;
if (IsProgrammer)
{
state = L"Programmer";
return L"Programmer";
}
else if (IsScientific)
{
state = L"Scientific";
return L"Scientific";
}
else
{
state = L"Standard";
return L"Standard";
}
return state;
}
void Calculator::UpdateViewState()
@ -479,7 +476,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->Data(), false);
Model->SetPrimaryDisplay(e->Result, false);
Model->IsFToEEnabled = false;
CloseHistoryFlyout();
@ -616,7 +613,7 @@ Memory ^ Calculator::GetMemory()
if (m_memory == nullptr)
{
m_memory = ref new Memory();
VisualStateManager::GoToState(m_memory, ref new String(GetCurrentLayoutState().c_str()), true /*useTransitions*/);
VisualStateManager::GoToState(m_memory, GetCurrentLayoutState(), true /*useTransitions*/);
}
return m_memory;
@ -672,28 +669,6 @@ 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;

View File

@ -94,7 +94,7 @@ public
void EnsureScientific();
void EnsureProgrammer();
void SetFontSizeResources();
std::wstring GetCurrentLayoutState();
Platform::String ^ GetCurrentLayoutState();
void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
private:
@ -140,7 +140,6 @@ 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);

View File

@ -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");
wstring bitPosition;
String ^ automationNameTemplate = resourceLoader->GetResourceString(L"BitFlipItemAutomationName");
String ^ bitPosition;
if (position == 0)
{
bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data());
bitPosition = resourceLoader->GetResourceString(L"LeastSignificantBit");
}
else
{
@ -263,14 +263,14 @@ String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int
if (position == lastPosition)
{
bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data());
bitPosition = resourceLoader->GetResourceString(L"MostSignificantBit");
}
else
{
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());
String ^ indexName = resourceLoader->GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
String ^ bitPositionTemplate = resourceLoader->GetResourceString(L"BitPosition");
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate, indexName);
}
}
return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
return LocalizationStringUtil::GetLocalizedString(automationNameTemplate, bitPosition, value ? L"1" : L"0");
}

View File

@ -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)

View File

@ -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);
}

View File

@ -10,6 +10,7 @@
#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;
@ -510,25 +511,20 @@ void MainPage::SetHeaderAutomationName()
String ^ name;
if (NavCategory::IsDateCalculatorViewMode(mode))
{
name = resProvider.GetResourceString(L"HeaderAutomationName_Date");
name = resProvider->GetResourceString(L"HeaderAutomationName_Date");
}
else
{
wstring full;
String ^ full;
if (NavCategory::IsCalculatorViewMode(mode))
{
full = resProvider.GetResourceString(L"HeaderAutomationName_Calculator")->Data();
full = resProvider->GetResourceString(L"HeaderAutomationName_Calculator");
}
else if (NavCategory::IsConverterViewMode(mode))
{
full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
full = resProvider->GetResourceString(L"HeaderAutomationName_Converter");
}
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());
name = LocalizationStringUtil::GetLocalizedString(full, m_model->CategoryName);
}
AutomationProperties::SetName(Header, name);

View File

@ -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
}

View File

@ -40,8 +40,6 @@ 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;
@ -66,14 +64,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<MenuFlyout ^>(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)
@ -165,7 +163,7 @@ void UnitConverter::SetFailedToRefreshStatus()
void UnitConverter::InitializeOfflineStatusTextBlock()
{
auto resProvider = AppResourceProvider::GetInstance();
std::wstring offlineStatusHyperlinkText = static_cast<String ^>(resProvider.GetResourceString(L"OfflineStatusHyperlinkText"))->Data();
std::wstring offlineStatusHyperlinkText = resProvider->GetResourceString(L"OfflineStatusHyperlinkText")->Data();
// The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'.
// Break the string and assign pieces appropriately.
@ -245,9 +243,9 @@ void UnitConverter::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEvent
void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
{
CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter).then([this](String ^ pastedString) {
Model->OnPaste(pastedString);
});
auto that(this);
create_task(CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown))
.then([that](String ^ pastedString) { that->Model->OnPaste(pastedString); });
}
void UnitConverter::AnimateConverter()

View File

@ -42,6 +42,10 @@ namespace CalculatorUnitTests
TEST_CLASS(CopyPasteManagerTest)
{
public:
CopyPasteManagerTest()
{
m_CopyPasteManager = ref new CopyPasteManager();
}
TEST_METHOD(FunctionalCopyPasteTest);
TEST_METHOD(ValidateStandardPasteExpressionTest);
TEST_METHOD(ValidateScientificPasteExpressionTest);
@ -54,35 +58,36 @@ 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");
};
@ -92,47 +97,47 @@ namespace CalculatorUnitTests
vector<wstring> results = {};
vector<wstring> 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<wstring> 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<wstring> 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<wstring> 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");
};
@ -140,31 +145,31 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidateExpressionRegExMatch)
{
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
m_CopyPasteManager->ExpressionRegExMatch(vector<wstring>{}, 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<wstring>{ 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<wstring>{ 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<wstring>{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"10000000000000000000000000000000000000000000000000000000000000000" },
ViewMode::Programmer,
CategoryGroupType::Calculator,
@ -172,12 +177,12 @@ namespace CalculatorUnitTests
BitLength::BitLengthQWord));
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ 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<wstring>{ L"((((((((((((((((((((123))))))))))))))))))))" },
ViewMode::Scientific,
CategoryGroupType::Calculator,
@ -185,20 +190,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<wstring>{ 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<wstring>{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"fab10" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(
m_CopyPasteManager.ExpressionRegExMatch(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ 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,
@ -207,34 +212,30 @@ namespace CalculatorUnitTests
L"Verify exponents are accepted in scientific mode.");
VERIFY_IS_FALSE(
m_CopyPasteManager.ExpressionRegExMatch(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ 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<wstring>{ L"123", L"9223372036854775808" },
ViewMode::Programmer,
CategoryGroupType::Calculator,
DecBase,
BitLength::BitLengthQWord),
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
L"Verify all operand must be within max value.");
};
TEST_METHOD(ValidateGetMaxOperandLengthAndValue)
{
pair<size_t, unsigned long long int> standardModeMaximums = make_pair(m_CopyPasteManager.MaxStandardOperandLength, 0);
pair<size_t, unsigned long long int> scientificModeMaximums = make_pair(m_CopyPasteManager.MaxScientificOperandLength, 0);
pair<size_t, unsigned long long int> converterModeMaximums = make_pair(m_CopyPasteManager.MaxConverterInputLength, 0);
pair<size_t, unsigned long long int> standardModeMaximums = make_pair(m_CopyPasteManager->MaxStandardOperandLength, 0);
pair<size_t, unsigned long long int> scientificModeMaximums = make_pair(m_CopyPasteManager->MaxScientificOperandLength, 0);
pair<size_t, unsigned long long int> 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");
@ -244,108 +245,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)
@ -353,199 +354,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);
}
};
@ -602,41 +603,38 @@ 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);
@ -674,19 +672,14 @@ 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);
@ -1072,8 +1065,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",
@ -1099,7 +1092,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);

View File

@ -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->Data(), false /*IsError*/);
m_standardViewModel->SetPrimaryDisplay(e->Result, false /*IsError*/);
m_standardViewModel->IsFToEEnabled = false;
}