Skip to content

Commit

Permalink
Fixed bug with custom command interpreter that could cause incorrect …
Browse files Browse the repository at this point in the history
…commands to be returned
  • Loading branch information
ben_singer committed Dec 5, 2024
1 parent 5de0e16 commit 63d9ed7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion NetAF/Interpretation/CustomCommandInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static Dictionary<CustomCommand, int> ScoreCommandsAgainstInput(string i
if (upperCaseCommand.Length < i + 1 && upperCaseShortcut.Length < i + 1)
break;

if (upperCaseCommand[i] != upperCaseInput[i] && upperCaseShortcut[i] != upperCaseInput[i])
if (!AreCharactersEqual(upperCaseCommand, upperCaseInput, i) && !AreCharactersEqual(upperCaseShortcut, upperCaseInput, i))
break;
}

Expand All @@ -48,6 +48,21 @@ private static Dictionary<CustomCommand, int> ScoreCommandsAgainstInput(string i
return scores;
}

/// <summary>
/// Get if a character at a given index is equal in two strings.
/// </summary>
/// <param name="a">String a.</param>
/// <param name="b">String b.</param>
/// <param name="index">The index of the character.</param>
/// <returns>True if the characters are equal, else false.</returns>
private static bool AreCharactersEqual(string a, string b, int index)
{
if (a.Length - 1 < index || b.Length - 1 < index)
return false;

return a[index] == b[index];
}

#endregion

#region Implementation of IInterpreter
Expand Down

0 comments on commit 63d9ed7

Please sign in to comment.