From 63d9ed7f74dc263db12b98bfe713f3c3ea10cb76 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Thu, 5 Dec 2024 19:48:28 +0000 Subject: [PATCH] Fixed bug with custom command interpreter that could cause incorrect commands to be returned --- .../Interpretation/CustomCommandInterpreter.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/NetAF/Interpretation/CustomCommandInterpreter.cs b/NetAF/Interpretation/CustomCommandInterpreter.cs index 4f79990..f0b6143 100644 --- a/NetAF/Interpretation/CustomCommandInterpreter.cs +++ b/NetAF/Interpretation/CustomCommandInterpreter.cs @@ -38,7 +38,7 @@ private static Dictionary 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; } @@ -48,6 +48,21 @@ private static Dictionary ScoreCommandsAgainstInput(string i return scores; } + /// + /// Get if a character at a given index is equal in two strings. + /// + /// String a. + /// String b. + /// The index of the character. + /// True if the characters are equal, else false. + 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