public virtual Hyphenation hyphenate(char[] w, int offset, int len, int remainCharCount, int pushCharCount)
{
int i;
char[] word = new char[len + 3];
// normalize word
char[] c = new char[2];
int iIgnoreAtBeginning = 0;
int iLength = len;
bool bEndOfLetters = false;
for (i = 1; i <= len; i++)
{
c[0] = w[offset + i - 1];
int nc = classmap.find(c, 0);
if (nc < 0) // found a non-letter character ...
{
if (i == (1 + iIgnoreAtBeginning))
{
// ... before any letter character
iIgnoreAtBeginning++;
}
else
{
// ... after a letter character
bEndOfLetters = true;
}
iLength--;
}
else
{
if (!bEndOfLetters)
{
word[i - iIgnoreAtBeginning] = (char) nc;
}
else
{
return null;
}
}
}
len = iLength;
if (len < (remainCharCount + pushCharCount))
{
// word is too short to be hyphenated
return null;
}
int[] result = new int[len + 1];
int k = 0;
// check exception list first
string sw = new string(word, 1, len);
if (stoplist.ContainsKey(sw))
{
// assume only simple hyphens (Hyphen.pre="-", Hyphen.post = Hyphen.no =
// null)
List<object> hw = stoplist[sw];
int j = 0;
for (i = 0; i < hw.Count; i++)
{
object o = hw[i];
// j = index(sw) = letterindex(word)?
// result[k] = corresponding index(w)
if (o is string)
{
j += ((string) o).Length;
if (j >= remainCharCount && j < (len - pushCharCount))
{
result[k++] = j + iIgnoreAtBeginning;
}
}
}
}
else
{
// use algorithm to get hyphenation points
word[0] = '.'; // word start marker
word[len + 1] = '.'; // word end marker
word[len + 2] = (char)0; // null terminated
sbyte[] il = new sbyte[len + 3]; // initialized to zero
for (i = 0; i < len + 1; i++)
{
searchPatterns(word, i, il);
}
// hyphenation points are located where interletter value is odd
// i is letterindex(word),
// i + 1 is index(word),
// result[k] = corresponding index(w)
for (i = 0; i < len; i++)
{
if (((il[i + 1] & 1) == 1) && i >= remainCharCount && i <= (len - pushCharCount))
{
result[k++] = i + iIgnoreAtBeginning;
}
}
}
if (k > 0)
{
// trim result array
int[] res = new int[k + 2];
Array.Copy(result, 0, res, 1, k);
// We add the synthetical hyphenation points
// at the beginning and end of the word
res[0] = 0;
res[k + 1] = len;
return new Hyphenation(res);
}
else
{
return null;
}
}