mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
[PTRun][UnitConverter]Fix "feet" and "gal" (#16618)
* Update InputInterpreter.cs * Update InputInterpreter.cs
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -151,6 +152,53 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The plural form "feet" is not recognized by UniteNets. Replace it with "ft".
|
||||
/// </summary>
|
||||
public static void FeetToFt(ref string[] split)
|
||||
{
|
||||
if (split[1].ToLower() == "feet")
|
||||
{
|
||||
split[1] = "ft";
|
||||
}
|
||||
|
||||
if (split[3].ToLower() == "feet")
|
||||
{
|
||||
split[3] = "ft";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Choose "UsGallon" or "ImperialGallon" according to current culture when the input contains "gal" or "gallon".
|
||||
/// </summary>
|
||||
public static void GallonHandler(ref string[] split, CultureInfo culture)
|
||||
{
|
||||
HashSet<string> britishCultureNames = new HashSet<string>() { "en-AI", "en-VG", "en-GB", "en-KY", "en-MS", "en-AG", "en-DM", "en-GD", "en-KN", "en-LC", "en-VC", "en-IE", "en-GY", "en-AE" };
|
||||
if (split[1].ToLower() == "gal" || split[1].ToLower() == "gallon")
|
||||
{
|
||||
if (britishCultureNames.Contains(culture.Name))
|
||||
{
|
||||
split[1] = "ImperialGallon";
|
||||
}
|
||||
else
|
||||
{
|
||||
split[1] = "UsGallon";
|
||||
}
|
||||
}
|
||||
|
||||
if (split[3].ToLower() == "gal" || split[3].ToLower() == "gallon")
|
||||
{
|
||||
if (britishCultureNames.Contains(culture.Name))
|
||||
{
|
||||
split[3] = "ImperialGallon";
|
||||
}
|
||||
else
|
||||
{
|
||||
split[3] = "UsGallon";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ConvertModel Parse(Query query)
|
||||
{
|
||||
string[] split = query.Search.Split(' ');
|
||||
@@ -167,6 +215,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
||||
}
|
||||
|
||||
InputInterpreter.DegreePrefixer(ref split);
|
||||
InputInterpreter.FeetToFt(ref split);
|
||||
InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture);
|
||||
if (!double.TryParse(split[0], out double value))
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user