GetWordPosition should ignore special characters now chinese sentence doesnt have space as word separator nor a word separator at all, same goes for thai,etc. iirc :)
This commit is contained in:
parent
91008be48d
commit
4f3e2565a4
@ -133,15 +133,15 @@ namespace NadekoBot.Modules.CustomReactions.Extensions
|
|||||||
|
|
||||||
if (indexOfWord == 0) // on start
|
if (indexOfWord == 0) // on start
|
||||||
{
|
{
|
||||||
if (word.Length < str.Length &&str.isInvalidWordChar(word.Length)) // filter char after word index
|
if (word.Length < str.Length && str.isInvalidWordChar(word.Length)) // filter char after word index
|
||||||
return WordPosition.Start;
|
return WordPosition.Start;
|
||||||
}
|
}
|
||||||
else if ((indexOfWord + word.Length) == str.Length) // on end
|
else if ((indexOfWord + word.Length) == str.Length) // on end
|
||||||
{
|
{
|
||||||
if (str.isInvalidWordChar(indexOfWord-1)) // filter char before word index
|
if (str.isInvalidWordChar(indexOfWord - 1)) // filter char before word index
|
||||||
return WordPosition.End;
|
return WordPosition.End;
|
||||||
}
|
}
|
||||||
else if (str.isInvalidWordChar(indexOfWord-1) && str.isInvalidWordChar(indexOfWord + word.Length)) // on middle
|
else if (str.isInvalidWordChar(indexOfWord - 1) && str.isInvalidWordChar(indexOfWord + word.Length)) // on middle
|
||||||
return WordPosition.Middle;
|
return WordPosition.Middle;
|
||||||
|
|
||||||
return WordPosition.None;
|
return WordPosition.None;
|
||||||
@ -149,10 +149,10 @@ namespace NadekoBot.Modules.CustomReactions.Extensions
|
|||||||
|
|
||||||
private static bool isInvalidWordChar(this string str, int index)
|
private static bool isInvalidWordChar(this string str, int index)
|
||||||
{
|
{
|
||||||
var ch = str[index];
|
var ch = (ushort)str[index];
|
||||||
if ((byte)ch > 64 && (byte)ch <= 90) // must be A-Z
|
if (ch > 64 && ch <= 90) // must be A-Z
|
||||||
return false;
|
return false;
|
||||||
if ((byte)ch > 97 && (byte)ch <= 122) // a-z
|
if (ch > 97 && ch <= 122) // a-z
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user