Make suggestion system string distance algorithm case-insensitive (#10549)

* Make string distance algoriphm case-insensitive

* Use CurrentCulture in ToUpper()
This commit is contained in:
Ilya
2019-09-24 10:26:58 -07:00
committed by Travis Plunk
parent 146f11b2a1
commit 5dbaeb87ea
@@ -2,7 +2,7 @@
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace System.Management.Automation
{
@@ -23,7 +23,7 @@ namespace System.Management.Automation
/// <summary>
/// Compute the distance between two strings.
/// Compute the case-insensitive distance between two strings.
/// Based off https://www.csharpstar.com/csharp-string-distance-algorithm/.
/// </summary>
/// <param name="string1">The first string to compare.</param>
@@ -31,6 +31,9 @@ namespace System.Management.Automation
/// <returns>The distance value where the lower the value the shorter the distance between the two strings representing a closer match.</returns>
public static int GetDamerauLevenshteinDistance(string string1, string string2)
{
string1 = string1.ToUpper(CultureInfo.CurrentCulture);
string2 = string2.ToUpper(CultureInfo.CurrentCulture);
var bounds = new { Height = string1.Length + 1, Width = string2.Length + 1 };
int[,] matrix = new int[bounds.Height, bounds.Width];