mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Make suggestion system string distance algorithm case-insensitive (#10549)
* Make string distance algoriphm case-insensitive * Use CurrentCulture in ToUpper()
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user