public string GetNextWord() { Gtk.TextIter prevCharIter = new Gtk.TextIter(); Gtk.TextIter nextCharIter = new Gtk.TextIter(); Gtk.TextIter prevWordEndIter = new Gtk.TextIter(); string text; string word; bool bail = false; endPara = false; wao = 1; startWordIter = endWordIter; // Need to trap last word see gnomeRSVP if (!endWordIter.ForwardWordEnd()) { StopRsvp(null, null); } do { prevCharIter = endWordIter; prevCharIter.BackwardChar(); nextCharIter = endWordIter; nextCharIter.ForwardChar(); if (Regex.IsMatch(endWordIter.Char, @"^\S$", RegexOptions.None) && Regex.IsMatch(prevCharIter.Char, @"^\s$", RegexOptions.None)) { text = startWordIter.GetText(endWordIter); text = Regex.Replace(text, @"--", "", RegexOptions.Multiline); text = text.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); text = Regex.Replace(text, @"\s+", " ", RegexOptions.Multiline); if (text.Length <= config.WordGroupSize) { if (endWordIter.InsideSentence()) { prevWordEndIter = prevCharIter; wao++; } } else { bail = true; nextCharIter.BackwardChar(); } } else if (endWordIter.EndsSentence()) { bail = true; do { } while (endWordIter.EndsSentence() && endWordIter.ForwardChar()); nextCharIter.BackwardChar(); if (!endWordIter.IsEnd) { if (nextCharIter.Char == "\n") { endPara = true; } } } endWordIter = nextCharIter; } while (!bail && !endWordIter.IsEnd); word = startWordIter.GetText(endWordIter); word = Regex.Replace(word, @"--", "", RegexOptions.Multiline); word = word.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); word = Regex.Replace(word, @"\s+$", "", RegexOptions.Multiline); word = Regex.Replace(word, @"\s+", " ", RegexOptions.Multiline); if (word.Length > config.WordGroupSize && !prevWordEndIter.Equal(Gtk.TextIter.Zero)) { wao--; endWordIter = prevWordEndIter; } word = startWordIter.GetText(endWordIter); word = Regex.Replace(word, @"--", "", RegexOptions.Multiline); word = word.TrimStart(new char[4] { ' ', '\n', '\t', '-' }); word = Regex.Replace(word, @"\s+$", "", RegexOptions.Multiline); word = Regex.Replace(word, @"\s+", " ", RegexOptions.Multiline); if (endWordIter.IsEnd) { StopRsvp(null, null); } return(word); }