somewhat clearer logic

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8314 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-01-07 14:07:46 +00:00
parent bb5291a013
commit 8af1fa7aeb

View File

@ -27,8 +27,6 @@
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "insets/insettext.h"
#include "support/textutils.h" #include "support/textutils.h"
using lyx::support::lowercase; using lyx::support::lowercase;
@ -47,8 +45,10 @@ class MatchString
{ {
public: public:
MatchString(string const & str, bool cs, bool mw) MatchString(string const & str, bool cs, bool mw)
: str(str), cs(cs), mw(mw) {}; : str(str), cs(cs), mw(mw)
// returns true if the specified string is at the specified position {}
// returns true if the specified string is at the specified position
bool operator()(Paragraph const & par, pos_type pos) const bool operator()(Paragraph const & par, pos_type pos) const
{ {
string::size_type size = str.length(); string::size_type size = str.length();
@ -60,22 +60,28 @@ public:
: (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) { : (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) {
++i; ++i;
} }
if (size == string::size_type(i)) {
// if necessary, check whether string matches word if (size != string::size_type(i))
if (!mw) return false;
return true;
if ((pos <= 0 || !IsLetterCharOrDigit(par.getChar(pos - 1))) // if necessary, check whether string matches word
&& (pos + pos_type(size) >= parsize if (mw) {
|| !IsLetterCharOrDigit(par.getChar(pos + size)))) { if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1)))
return true; return false;
} if (pos + pos_type(size) < parsize
&& IsLetterCharOrDigit(par.getChar(pos + size)));
return false;
} }
return false;
return true;
} }
private: private:
// search string
string str; string str;
// case sensitive
bool cs; bool cs;
// match whole words only
bool mw; bool mw;
}; };
@ -127,8 +133,7 @@ bool searchAllowed(BufferView * bv, string const & str)
bool find(BufferView * bv, string const & searchstr, bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
bool cs, bool mw, bool fw)
{ {
if (!searchAllowed(bv, searchstr)) if (!searchAllowed(bv, searchstr))
return false; return false;