From fb36e6ced99b812654aef4bf65d5efade9bc01bc Mon Sep 17 00:00:00 2001
From: Vaibhav Sharma <48472541+GhostVaibhav@users.noreply.github.com>
Date: Wed, 17 Jul 2024 20:30:05 +0530
Subject: [PATCH] [PTRun][UnitConverter]Accept kilometers per hour
abbreviations (#33594)
## Summary of the Pull Request
This PR introduces abbreviations for the units - `kph` that gets
converted to `km/h` and `cph` that gets converted to `cm/h`.
---
.github/actions/spell-check/expect.txt | 3 +++
.../InputInterpreter.cs | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index 0e05495e25..c697204f95 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -200,6 +200,7 @@ CMINVOKECOMMANDINFO
CMINVOKECOMMANDINFOEX
CMock
CMONITORS
+cmph
cmpgt
cne
CNF
@@ -244,6 +245,7 @@ copiedcolorrepresentation
cotaskmem
COULDNOT
countof
+cph
CPower
cppblog
cppruntime
@@ -760,6 +762,7 @@ keyremaps
keyvault
KILLFOCUS
killrunner
+kmph
Knownfolders
ksh
KSPROPERTY
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 5cdaf9683e..aadab74821 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
@@ -179,6 +179,22 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
}
}
+ ///
+ /// Converts spelling "kph" to "km/h"
+ ///
+ public static void KPHHandler(ref string[] split)
+ {
+ split[1] = split[1].Replace("cph", "cm/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[1] = split[1].Replace("kph", "km/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[1] = split[1].Replace("kmph", "km/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[1] = split[1].Replace("cmph", "cm/h", System.StringComparison.CurrentCultureIgnoreCase);
+
+ split[3] = split[3].Replace("cph", "cm/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[3] = split[3].Replace("kph", "km/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[3] = split[3].Replace("kmph", "km/h", System.StringComparison.CurrentCultureIgnoreCase);
+ split[3] = split[3].Replace("cmph", "cm/h", System.StringComparison.CurrentCultureIgnoreCase);
+ }
+
///
/// Converts spelling "metre" to "meter", also for centimetre and other variants
///
@@ -239,6 +255,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
InputInterpreter.DegreePrefixer(ref split);
InputInterpreter.MetreToMeter(ref split);
InputInterpreter.FeetToFt(ref split);
+ InputInterpreter.KPHHandler(ref split);
InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture);
if (!double.TryParse(split[0], out double value))
{