Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/System.Management.Automation/utils/FuzzyMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Globalization;

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


/// <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>
/// <param name="string2">The second string to compare.</param>
/// <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];
Expand Down