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