From a0b10edf5a1489b0f11ba378cc87e808e6df5130 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:59:17 +0200 Subject: [PATCH 1/5] [Run-UnitConverter] Use capital letters in DegreePrefixer --- .../InputInterpreter.cs | 12 ++++++------ .../UnitHandler.cs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs index 3a36b3b175a..96101eb2efe 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs @@ -91,7 +91,7 @@ public static void ShorthandFeetInchHandler(ref string[] split, CultureInfo cult if (!isFeet || !isInches) { - // atleast one could not be parsed correctly + // at least one could not be parsed correctly break; } @@ -114,7 +114,7 @@ public static void ShorthandFeetInchHandler(ref string[] split, CultureInfo cult } /// - /// Adds degree prefixes to degree units for shorthand notation. E.g. '10 c in fahrenheit' becomes '10 °c in DegreeFahrenheit'. + /// Adds degree prefixes to degree units for shorthand notation. E.g. '10 c in fahrenheit' becomes '10 °C in DegreeFahrenheit'. /// public static void DegreePrefixer(ref string[] split) { @@ -129,11 +129,11 @@ public static void DegreePrefixer(ref string[] split) break; case "c": - split[1] = "°c"; + split[1] = "°C"; break; case "f": - split[1] = "°f"; + split[1] = "°F"; break; default: @@ -151,11 +151,11 @@ public static void DegreePrefixer(ref string[] split) break; case "c": - split[3] = "°c"; + split[3] = "°C"; break; case "f": - split[3] = "°f"; + split[3] = "°F"; break; default: diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs index 5038c13a3ea..17867206401 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs @@ -10,7 +10,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter { public static class UnitHandler { - private static readonly int _roundingFractionalDigits = 4; + private static readonly int _roundingSignificantDigits = 4; private static readonly QuantityInfo[] _included = new QuantityInfo[] { @@ -71,7 +71,7 @@ public static double Round(double value) var power = Math.Floor(Math.Log10(Math.Abs(value))); var exponent = Math.Pow(10, power); - var rounded = Math.Round(value / exponent, _roundingFractionalDigits) * exponent; + var rounded = Math.Round(value / exponent, _roundingSignificantDigits) * exponent; return rounded; } From 7aeaa78b2340ec96a2e99c728f0aa75442d0a7c1 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:05:15 +0200 Subject: [PATCH 2/5] doc update --- .../modules/launcher/plugins/community.unitconverter.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/devdocs/modules/launcher/plugins/community.unitconverter.md b/doc/devdocs/modules/launcher/plugins/community.unitconverter.md index aff29968b0d..33d0fb58ba5 100644 --- a/doc/devdocs/modules/launcher/plugins/community.unitconverter.md +++ b/doc/devdocs/modules/launcher/plugins/community.unitconverter.md @@ -19,13 +19,13 @@ This plugin uses a package called [UnitsNet](https://github.com/angularsen/Units - [Temperature](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/GeneratedCode/Units/TemperatureUnit.g.cs) - [Volume](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/GeneratedCode/Units/VolumeUnit.g.cs) - These are the ones that are currently enabled (though UnitsNet supports many more). They are defined in [`Main.cs`](/src/modules/launcher/Plugins/Community.PowerToys.Run.UnitConverter/Main.cs). + These are the ones that are currently enabled (though UnitsNet supports many more). They are defined in [`UnitHandler.cs`](/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs). -### [`InputInterpreter`](/src/modules/launcher/Plugins/Community.PowerToys.Run.UnitConverter/InputInterpreter.cs) +### [`InputInterpreter`](/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs) - Class which manipulates user input such that it may be interpreted correctly and thus converted. - Uses a regex amongst other things to do this. -### [`UnitHandler`](/src/modules/launcher/Plugins/Community.PowerToys.Run.UnitConverter/UnitHandler.cs) +### [`UnitHandler`](/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs) - Class that does the actual conversion. - Supports abbreviations in user input (single, double, or none). \ No newline at end of file From 1359b4141f77fe778a2793fbf08ff0ed501808c1 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:53:17 +0200 Subject: [PATCH 3/5] Update tests --- .../InputInterpreterTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs index 99a1a265b99..4fba38913c2 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/InputInterpreterTests.cs @@ -67,9 +67,9 @@ public void HandlesMetreVsMeterNotation(string[] input, string[] expectedResult) [DataTestMethod] [DataRow(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" })] - [DataRow(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "°f", "in", "DegreeCelsius" })] - [DataRow(new string[] { "5", "c", "in", "f" }, new string[] { "5", "°c", "in", "°f" })] - [DataRow(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°f", "in", "°c" })] + [DataRow(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "°F", "in", "DegreeCelsius" })] + [DataRow(new string[] { "5", "c", "in", "f" }, new string[] { "5", "°C", "in", "°F" })] + [DataRow(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°F", "in", "°C" })] #pragma warning restore CA1861 // Avoid constant arrays as arguments public void PrefixesDegrees(string[] input, string[] expectedResult) { From 816463733895918134a931634206856826932b75 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:41:49 +0200 Subject: [PATCH 4/5] Remove FeetToFt --- .../InputInterpreter.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs index 96101eb2efe..fb0314f4281 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs @@ -163,22 +163,6 @@ public static void DegreePrefixer(ref string[] split) } } - /// - /// The plural form "feet" is not recognized by UniteNets. Replace it with "ft". - /// - public static void FeetToFt(ref string[] split) - { - if (string.Equals(split[1], "feet", StringComparison.OrdinalIgnoreCase)) - { - split[1] = "ft"; - } - - if (string.Equals(split[3], "feet", StringComparison.OrdinalIgnoreCase)) - { - split[3] = "ft"; - } - } - /// /// Converts spelling "kph" to "km/h" /// @@ -291,7 +275,6 @@ public static ConvertModel Parse(Query query) InputInterpreter.DegreePrefixer(ref split); InputInterpreter.MetreToMeter(ref split); - InputInterpreter.FeetToFt(ref split); InputInterpreter.KPHHandler(ref split); InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture); InputInterpreter.OunceHandler(ref split, CultureInfo.CurrentCulture); From 5d8fbe9d55a2fcac72cb8bf01600b2fa93baf67d Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:00:43 +0200 Subject: [PATCH 5/5] trigger checks