Skip to content

Commit 5dbaeb8

Browse files
iSazonovTravisEz13
authored andcommitted
Make suggestion system string distance algorithm case-insensitive (PowerShell#10549)
* Make string distance algoriphm case-insensitive * Use CurrentCulture in ToUpper()
1 parent 146f11b commit 5dbaeb8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/System.Management.Automation/utils/FuzzyMatch.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Generic;
5+
using System.Globalization;
66

77
namespace System.Management.Automation
88
{
@@ -23,14 +23,17 @@ public static bool IsFuzzyMatch(string string1, string string2)
2323

2424

2525
/// <summary>
26-
/// Compute the distance between two strings.
26+
/// Compute the case-insensitive distance between two strings.
2727
/// Based off https://www.csharpstar.com/csharp-string-distance-algorithm/.
2828
/// </summary>
2929
/// <param name="string1">The first string to compare.</param>
3030
/// <param name="string2">The second string to compare.</param>
3131
/// <returns>The distance value where the lower the value the shorter the distance between the two strings representing a closer match.</returns>
3232
public static int GetDamerauLevenshteinDistance(string string1, string string2)
3333
{
34+
string1 = string1.ToUpper(CultureInfo.CurrentCulture);
35+
string2 = string2.ToUpper(CultureInfo.CurrentCulture);
36+
3437
var bounds = new { Height = string1.Length + 1, Width = string2.Length + 1 };
3538

3639
int[,] matrix = new int[bounds.Height, bounds.Width];

0 commit comments

Comments
 (0)