private int findEnding(StringBuilder stemmingZone, int startIndex, char[][] theEndingClass)
{
bool match = false;
for (int i = theEndingClass.Length - 1; i >= 0; i--)
{
char[] theEnding = theEndingClass[i];
// check if the ending is bigger than stemming zone
if (startIndex < theEnding.Length - 1)
{
match = false;
continue;
}
match = true;
int stemmingIndex = startIndex;
for (int j = theEnding.Length - 1; j >= 0; j--)
{
if (stemmingZone[stemmingIndex--] != theEnding[j])
{
match = false;
break;
}
}
// check if ending was found
if (match)
{
return theEndingClass[i].Length; // cut ending
}
}
return 0;
}