Introducing Paragraph::find().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21168 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-24 08:22:26 +00:00
parent 1297114b73
commit 372e605c2f
3 changed files with 45 additions and 27 deletions

View File

@ -2666,6 +2666,40 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
}
}
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];

View File

@ -361,6 +361,16 @@ public:
void changeCase(BufferParams const & bparams, pos_type pos,
pos_type right, TextCase action);
/// find \param str string inside Paragraph.
/// \return true if the specified string is at the specified position
/// \param del specifies whether deleted strings in ct mode will be considered
bool find(
docstring const & str, ///< string to search
bool cs, ///<
bool mw, ///<
pos_type pos, ///< start from here.
bool del = true) const;
private:
/// Pimpl away stuff
class Private;

View File

@ -66,33 +66,7 @@ public:
// del specifies whether deleted strings in ct mode will be considered
bool operator()(Paragraph const & par, pos_type pos, bool del = true) const
{
docstring::size_type const size = str.length();
pos_type i = 0;
pos_type const parsize = par.size();
for (i = 0; pos + i < parsize; ++i) {
if (docstring::size_type(i) >= size)
break;
if (cs && str[i] != par.getChar(pos + i))
break;
if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
break;
if (!del && par.isDeleted(pos + i))
break;
}
if (size != docstring::size_type(i))
return false;
// if necessary, check whether string matches word
if (mw) {
if (pos > 0 && par.isLetter(pos - 1))
return false;
if (pos + pos_type(size) < parsize
&& par.isLetter(pos + size))
return false;
}
return true;
return par.find(str, cs, mw, pos, del);
}
private: