Transfer word locating code from Text to Paragraph.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29455 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-05-01 07:26:12 +00:00
parent ce0c09d1ae
commit 30c70c1670
3 changed files with 45 additions and 42 deletions

View File

@ -2866,6 +2866,43 @@ void Paragraph::deregisterWords()
}
void Paragraph::locateWord(pos_type & from, pos_type & to,
word_location const loc) const
{
switch (loc) {
case WHOLE_WORD_STRICT:
if (from == 0 || from == size()
|| !isLetter(from)
|| !isLetter(from - 1)) {
to = from;
return;
}
// no break here, we go to the next
case WHOLE_WORD:
// If we are already at the beginning of a word, do nothing
if (!from || !isLetter(from - 1))
break;
// no break here, we go to the next
case PREVIOUS_WORD:
// always move the cursor to the beginning of previous word
while (from && isLetter(from - 1))
--from;
break;
case NEXT_WORD:
LYXERR0("Paragraph::locateWord: NEXT_WORD not implemented yet");
break;
case PARTIAL_WORD:
// no need to move the 'from' cursor
break;
}
to = from;
while (to < size() && isLetter(to))
++to;
}
void Paragraph::collectWords(CursorSlice const & sl)
{
// find new words
@ -2873,27 +2910,22 @@ void Paragraph::collectWords(CursorSlice const & sl)
//lyxerr << "Words: ";
pos_type n = size();
for (pos_type pos = 0; pos != n; ++pos) {
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)
pos_type from = pos;
locateWord(from, pos, WHOLE_WORD);
if (pos - from < 6)
continue;
docstring word = asString(from.pos(), to.pos(), false);
docstring word = asString(from, pos, false);
d->words_.insert(word);
//lyxerr << word << " ";
}

View File

@ -401,6 +401,8 @@ public:
pos_type pos, ///< start from here.
bool del = true) const;
void locateWord(pos_type & from, pos_type & to,
word_location const loc) const;
///
void updateWords(CursorSlice const & sl);

View File

@ -1246,39 +1246,8 @@ bool Text::dissolveInset(Cursor & cur)
void Text::getWord(CursorSlice & from, CursorSlice & to,
word_location const loc) const
{
Paragraph const & from_par = pars_[from.pit()];
switch (loc) {
case WHOLE_WORD_STRICT:
if (from.pos() == 0 || from.pos() == from_par.size()
|| !from_par.isLetter(from.pos())
|| !from_par.isLetter(from.pos() - 1)) {
to = from;
return;
}
// no break here, we go to the next
case WHOLE_WORD:
// If we are already at the beginning of a word, do nothing
if (!from.pos() || !from_par.isLetter(from.pos() - 1))
break;
// no break here, we go to the next
case PREVIOUS_WORD:
// always move the cursor to the beginning of previous word
while (from.pos() && from_par.isLetter(from.pos() - 1))
--from.pos();
break;
case NEXT_WORD:
LYXERR0("Text::getWord: NEXT_WORD not implemented yet");
break;
case PARTIAL_WORD:
// no need to move the 'from' cursor
break;
}
to = from;
Paragraph const & to_par = pars_[to.pit()];
while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
++to.pos();
pars_[to.pit()].locateWord(from.pos(), to.pos(), loc);
}