diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 5e3247f9f..4d671fbd6 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -18,7 +18,6 @@ #include #include "Header Files/CalcEngine.h" #include "Header Files/CalcUtils.h" -#include "NumberFormattingUtils.h" using namespace std; using namespace CalcEngine; diff --git a/src/CalcManager/NumberFormattingUtils.cpp b/src/CalcManager/NumberFormattingUtils.cpp index 635639720..3c5b9feba 100644 --- a/src/CalcManager/NumberFormattingUtils.cpp +++ b/src/CalcManager/NumberFormattingUtils.cpp @@ -3,7 +3,7 @@ using namespace std; -namespace CalcManager::NumberFormattingUtils +namespace UnitConversionManager::NumberFormattingUtils { /// /// Trims out any trailing zeros or decimals in the given input string diff --git a/src/CalcManager/NumberFormattingUtils.h b/src/CalcManager/NumberFormattingUtils.h index f5587fe69..05585fea8 100644 --- a/src/CalcManager/NumberFormattingUtils.h +++ b/src/CalcManager/NumberFormattingUtils.h @@ -6,7 +6,7 @@ #include #include "sal_cross_platform.h" -namespace CalcManager::NumberFormattingUtils +namespace UnitConversionManager::NumberFormattingUtils { void TrimTrailingZeros(_Inout_ std::wstring& input); unsigned int GetNumberDigits(std::wstring value); diff --git a/src/CalcManager/UnitConverter.cpp b/src/CalcManager/UnitConverter.cpp index 3d4b18657..41afd272e 100644 --- a/src/CalcManager/UnitConverter.cpp +++ b/src/CalcManager/UnitConverter.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace UnitConversionManager; -using namespace CalcManager::NumberFormattingUtils; +using namespace UnitConversionManager::NumberFormattingUtils; static constexpr uint32_t EXPECTEDSERIALIZEDCATEGORYTOKENCOUNT = 3U; static constexpr uint32_t EXPECTEDSERIALIZEDUNITTOKENCOUNT = 6U; diff --git a/src/CalcViewModel/Common/Utils.cpp b/src/CalcViewModel/Common/Utils.cpp index 8715cea16..daae9e86d 100644 --- a/src/CalcViewModel/Common/Utils.cpp +++ b/src/CalcViewModel/Common/Utils.cpp @@ -13,7 +13,6 @@ #include "Common/AppResourceProvider.h" #include "Common/ExpressionCommandSerializer.h" #include "Common/ExpressionCommandDeserializer.h" -#include "CalcManager/NumberFormattingUtils.h" using namespace CalculatorApp; using namespace CalculatorApp::ViewModel::Common; @@ -239,13 +238,6 @@ String^ CalculatorApp::ViewModel::Common::Utilities::EscapeHtmlSpecialCharacters return replaceCharacters ? replacementString : originalString; } -Platform::String^ CalculatorApp::ViewModel::Common::Utilities::TrimTrailingZeros(Platform::String^ input) -{ - std::wstring tmp(input->Data()); - CalcManager::NumberFormattingUtils::TrimTrailingZeros(tmp); - return ref new Platform::String(tmp.c_str()); -} - bool CalculatorApp::ViewModel::Common::Utilities::AreColorsEqual(Windows::UI::Color color1, Windows::UI::Color color2) { return Utils::AreColorsEqual(color1, color2); diff --git a/src/CalcViewModel/Common/Utils.h b/src/CalcViewModel/Common/Utils.h index cd04350d6..8c3f5d2e5 100644 --- a/src/CalcViewModel/Common/Utils.h +++ b/src/CalcViewModel/Common/Utils.h @@ -713,7 +713,6 @@ namespace CalculatorApp { public: static Platform::String ^ EscapeHtmlSpecialCharacters(Platform::String ^ originalString); - static Platform::String^ TrimTrailingZeros(Platform::String^ input); static bool AreColorsEqual(Windows::UI::Color color1, Windows::UI::Color color2); static Windows::UI::Xaml::Media::SolidColorBrush ^ GetContrastColor(Windows::UI::Color backgroundColor); static int GetWindowId(); diff --git a/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.cpp b/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.cpp index 8bb0d7f80..4353777ca 100644 --- a/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.cpp +++ b/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.cpp @@ -3,11 +3,9 @@ #include "pch.h" #include "GraphingSettingsViewModel.h" -#include using namespace CalculatorApp::ViewModel; using namespace CalculatorApp::ViewModel::Common; -using namespace CalcManager::NumberFormattingUtils; using namespace GraphControl; using namespace std; using namespace Platform; @@ -55,21 +53,22 @@ void GraphingSettingsViewModel::InitRanges() m_XMaxValue = xMax; m_YMinValue = yMin; m_YMaxValue = yMax; - auto valueStr = to_wstring(m_XMinValue); - TrimTrailingZeros(valueStr); - XMin = ref new String(valueStr.c_str()); - valueStr = to_wstring(m_XMaxValue); - TrimTrailingZeros(valueStr); - XMax = ref new String(valueStr.c_str()); + std::wostringstream xMinStr; + xMinStr << m_XMinValue; + XMin = ref new String(xMinStr.str().c_str()); - valueStr = to_wstring(m_YMinValue); - TrimTrailingZeros(valueStr); - YMin = ref new String(valueStr.c_str()); + std::wostringstream xMaxStr; + xMaxStr << m_XMaxValue; + XMax = ref new String(xMaxStr.str().c_str()); - valueStr = to_wstring(m_YMaxValue); - TrimTrailingZeros(valueStr); - YMax = ref new String(valueStr.c_str()); + std::wostringstream yMinStr; + yMinStr << m_YMinValue; + YMin = ref new String(yMinStr.str().c_str()); + + std::wostringstream yMaxStr; + yMaxStr << m_YMaxValue; + YMax = ref new String(yMaxStr.str().c_str()); m_dontUpdateDisplayRange = false; } diff --git a/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.h b/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.h index 77f1dda16..81bb77fb9 100644 --- a/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.h +++ b/src/CalcViewModel/GraphingCalculator/GraphingSettingsViewModel.h @@ -51,21 +51,14 @@ namespace CalculatorApp::ViewModel m_XIsMinLastChanged = true; if (m_Graph != nullptr) { - try + std::wistringstream input(value->Data()); + double number; + if (input >> number && input.eof()) { - size_t sz; - auto number = std::stod(value->Data(), &sz); - if (value->Length() == sz) - { - m_Graph->XAxisMin = m_XMinValue = number; - XMinError = false; - } - else - { - XMinError = true; - } + m_Graph->XAxisMin = m_XMinValue = number; + XMinError = false; } - catch (...) + else { XMinError = true; } @@ -92,21 +85,14 @@ namespace CalculatorApp::ViewModel m_XIsMinLastChanged = false; if (m_Graph != nullptr) { - try + std::wistringstream input(value->Data()); + double number; + if (input >> number && input.eof()) { - size_t sz; - auto number = std::stod(value->Data(), &sz); - if (value->Length() == sz) - { - m_Graph->XAxisMax = m_XMaxValue = number; - XMaxError = false; - } - else - { - XMaxError = true; - } + m_Graph->XAxisMax = m_XMaxValue = number; + XMaxError = false; } - catch (...) + else { XMaxError = true; } @@ -133,21 +119,14 @@ namespace CalculatorApp::ViewModel m_YIsMinLastChanged = true; if (m_Graph != nullptr) { - try + std::wistringstream input(value->Data()); + double number; + if (input >> number && input.eof()) { - size_t sz; - auto number = std::stod(value->Data(), &sz); - if (value->Length() == sz) - { - m_Graph->YAxisMin = m_YMinValue = number; - YMinError = false; - } - else - { - YMinError = true; - } + m_Graph->YAxisMin = m_YMinValue = number; + YMinError = false; } - catch (...) + else { YMinError = true; } @@ -174,21 +153,14 @@ namespace CalculatorApp::ViewModel m_YIsMinLastChanged = false; if (m_Graph != nullptr) { - try + std::wistringstream input(value->Data()); + double number; + if (input >> number && input.eof()) { - size_t sz; - auto number = std::stod(value->Data(), &sz); - if (value->Length() == sz) - { - m_Graph->YAxisMax = m_YMaxValue = number; - YMaxError = false; - } - else - { - YMaxError = true; - } + m_Graph->YAxisMax = m_YMaxValue = number; + YMaxError = false; } - catch (...) + else { YMaxError = true; } diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs index 4b47241d1..385ca7557 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs @@ -12,9 +12,7 @@ using CalculatorApp.Controls; using CalculatorApp.Utils; using CalculatorApp.ViewModel; -//using CalcManager.NumberFormattingUtils; using GraphControl; -//using Utils; using Windows.ApplicationModel.DataTransfer; using Windows.ApplicationModel.Resources; using Windows.Foundation; @@ -467,8 +465,7 @@ private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs var value = variables[i].Value; rawHtml += name + "="; - var formattedValue = value.ToString("R"); - formattedValue = Utilities.TrimTrailingZeros(formattedValue); + var formattedValue = value.ToString(); rawHtml += formattedValue; if (variables.Count - 1 != i) diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp index e1233891c..aa1b0fe9a 100644 --- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp +++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp @@ -12,7 +12,7 @@ using namespace CalculatorApp; using namespace CalculatorApp::ViewModel::Common; using namespace CalculationManager; -using namespace CalcManager::NumberFormattingUtils; +using namespace UnitConversionManager::NumberFormattingUtils; using namespace Platform; using namespace std; using namespace Microsoft::VisualStudio::CppUnitTestFramework; @@ -191,11 +191,11 @@ namespace CalculatorManagerTest TEST_METHOD(CalculatorManagerTestMaxDigitsReached_LeadingDecimal); TEST_METHOD(CalculatorManagerTestMaxDigitsReached_TrailingDecimal); - TEST_METHOD(CalculatorManagerNumberFormattingUtils_TrimTrailingZeros); - TEST_METHOD(CalculatorManagerNumberFormattingUtils_GetNumberDigits); - TEST_METHOD(CalculatorManagerNumberFormattingUtils_GetNumberDigitsWholeNumberPart); - TEST_METHOD(CalculatorManagerNumberFormattingUtils_RoundSignificantDigits); - TEST_METHOD(CalculatorManagerNumberFormattingUtils_ToScientificNumber); + TEST_METHOD(UnitConversionManagerNumberFormattingUtils_TrimTrailingZeros); + TEST_METHOD(UnitConversionManagerNumberFormattingUtils_GetNumberDigits); + TEST_METHOD(UnitConversionManagerNumberFormattingUtils_GetNumberDigitsWholeNumberPart); + TEST_METHOD(UnitConversionManagerNumberFormattingUtils_RoundSignificantDigits); + TEST_METHOD(UnitConversionManagerNumberFormattingUtils_ToScientificNumber); TEST_METHOD(CalculatorManagerTestBinaryOperatorReceived); TEST_METHOD(CalculatorManagerTestBinaryOperatorReceived_Multiple); @@ -917,7 +917,7 @@ namespace CalculatorManagerTest TestMaxDigitsReachedScenario(L"123,456,789,101,112.13"); } - void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_TrimTrailingZeros() + void CalculatorManagerTest::UnitConversionManagerNumberFormattingUtils_TrimTrailingZeros() { wstring number = L"2.1032100000000"; TrimTrailingZeros(number); @@ -942,7 +942,7 @@ namespace CalculatorManagerTest VERIFY_ARE_EQUAL(number, L"322423"); } - void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_GetNumberDigits() + void CalculatorManagerTest::UnitConversionManagerNumberFormattingUtils_GetNumberDigits() { wstring number = L"2.10321"; unsigned int digitsCount = GetNumberDigits(number); @@ -961,7 +961,7 @@ namespace CalculatorManagerTest VERIFY_ARE_EQUAL(digitsCount, 8); } - void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_GetNumberDigitsWholeNumberPart() + void CalculatorManagerTest::UnitConversionManagerNumberFormattingUtils_GetNumberDigitsWholeNumberPart() { unsigned int digitsCount = GetNumberDigitsWholeNumberPart(2.10321); VERIFY_ARE_EQUAL(digitsCount, 1); @@ -981,7 +981,7 @@ namespace CalculatorManagerTest VERIFY_ARE_EQUAL(digitsCount, 1); } - void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_RoundSignificantDigits() + void CalculatorManagerTest::UnitConversionManagerNumberFormattingUtils_RoundSignificantDigits() { wstring result = RoundSignificantDigits(12.342343242, 3); VERIFY_ARE_EQUAL(result, L"12.342"); @@ -997,7 +997,7 @@ namespace CalculatorManagerTest VERIFY_ARE_EQUAL(result, L"0.3423000"); } - void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_ToScientificNumber() + void CalculatorManagerTest::UnitConversionManagerNumberFormattingUtils_ToScientificNumber() { wstring result = ToScientificNumber(3423); VERIFY_ARE_EQUAL(result, L"3.423000e+03");