From e8fc244bb60486691ca384334a0dfeacba57ec40 Mon Sep 17 00:00:00 2001 From: xsftk Date: Wed, 15 Nov 2017 13:51:00 +0700 Subject: [PATCH] some renaming and removed comment --- .../CustomReactions/Extensions/Extensions.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/NadekoBot.Core/Modules/CustomReactions/Extensions/Extensions.cs b/NadekoBot.Core/Modules/CustomReactions/Extensions/Extensions.cs index 1711b95c..b88fd3c0 100644 --- a/NadekoBot.Core/Modules/CustomReactions/Extensions/Extensions.cs +++ b/NadekoBot.Core/Modules/CustomReactions/Extensions/Extensions.cs @@ -127,32 +127,32 @@ namespace NadekoBot.Modules.CustomReactions.Extensions public static WordPosition GetWordPosition(this string str, string word) { - var indexOfWord = str.IndexOf(word); - if (indexOfWord == -1) + var wordIndex = str.IndexOf(word); + if (wordIndex == -1) return WordPosition.None; - if (indexOfWord == 0) // on start + if (wordIndex == 0) { - if (word.Length < str.Length && str.isInvalidWordChar(word.Length)) // filter char after word index + if (word.Length < str.Length && str.isValidWordDivider(word.Length)) return WordPosition.Start; } - else if ((indexOfWord + word.Length) == str.Length) // on end + else if ((wordIndex + word.Length) == str.Length) { - if (str.isInvalidWordChar(indexOfWord - 1)) // filter char before word index + if (str.isValidWordDivider(wordIndex - 1)) return WordPosition.End; } - else if (str.isInvalidWordChar(indexOfWord - 1) && str.isInvalidWordChar(indexOfWord + word.Length)) // on middle + else if (str.isValidWordDivider(wordIndex - 1) && str.isValidWordDivider(wordIndex + word.Length)) return WordPosition.Middle; return WordPosition.None; } - private static bool isInvalidWordChar(this string str, int index) + private static bool isValidWordDivider(this string str, int index) { - var ch = (ushort)str[index]; - if (ch >= 65 && ch <= 90) // must be A-Z + var ch = str[index]; + if (ch >= 'a' && ch <= 'z') return false; - if (ch >= 97 && ch <= 122) // a-z + if (ch >= 'A' && ch <= 'Z') return false; return true;