+bool Paragraph::find(docstring const & str, bool cs, bool mw,
+ pos_type pos, bool del) const
+{
+ int const strsize = str.length();
+ int i = 0;
+ pos_type const parsize = d->text_.size();
+ for (i = 0; pos + i < parsize; ++i) {
+ if (i >= strsize)
+ break;
+ if (cs && str[i] != d->text_[pos + i])
+ break;
+ if (!cs && uppercase(str[i]) != uppercase(d->text_[pos + i]))
+ break;
+ if (!del && isDeleted(pos + i))
+ break;
+ }
+
+ if (i != strsize)
+ return false;
+
+ // if necessary, check whether string matches word
+ if (mw) {
+ if (pos > 0 && isLetter(pos - 1))
+ return false;
+ if (pos + strsize < parsize
+ && isLetter(pos + strsize))
+ return false;
+ }
+
+ return true;
+}
+
+
+char_type Paragraph::getChar(pos_type pos) const
+{
+ return d->text_[pos];
+}
+
+
+pos_type Paragraph::size() const
+{
+ return d->text_.size();
+}
+
+
+bool Paragraph::empty() const
+{
+ return d->text_.empty();
+}
+
+
+bool Paragraph::isInset(pos_type pos) const
+{
+ return d->text_[pos] == META_INSET;
+}
+
+
+bool Paragraph::isSeparator(pos_type pos) const
+{
+ //FIXME: Are we sure this can be the only separator?
+ return d->text_[pos] == ' ';
+}
+
+
+void Paragraph::deregisterWords()
+{
+ Private::Words::const_iterator it;
+ WordList & wl = theWordList();
+ for (it = d->words_.begin(); it != d->words_.end(); ++it)
+ wl.remove(*it);
+ d->words_.clear();
+}
+
+
+void Paragraph::collectWords(CursorSlice const & sl)
+{
+ // find new words
+ bool inword = false;
+
+ //lyxerr << "Words: ";
+ pos_type n = size();
+ for (pos_type pos = 0; pos != n; ++pos) {
+ if (isDeleted(pos))
+ continue;
+
+ if (!isLetter(pos)) {
+ inword = false;
+ continue;
+ }
+
+ if (inword)
+ continue;
+
+ inword = true;
+ CursorSlice from = sl;
+ CursorSlice to = sl;
+ from.pos() = pos;
+ to.pos() = pos;
+ from.text()->getWord(from, to, WHOLE_WORD);
+ if (to.pos() - from.pos() < 6)
+ continue;
+ docstring word = asString(from.pos(), to.pos(), false);
+ d->words_.insert(word);
+ //lyxerr << word << " ";
+ }
+ //lyxerr << std::endl;
+}
+
+
+void Paragraph::registerWords()
+{
+ Private::Words::const_iterator it;
+ WordList & wl = theWordList();
+ for (it = d->words_.begin(); it != d->words_.end(); ++it)
+ wl.insert(*it);
+}
+
+
+void Paragraph::updateWords(CursorSlice const & sl)
+{
+ LASSERT(&sl.paragraph() == this, /**/);
+ deregisterWords();
+ collectWords(sl);
+ registerWords();
+}
+