]> git.lyx.org Git - features.git/commitdiff
Introducing Paragraph::find().
authorAbdelrazak Younes <younes@lyx.org>
Wed, 24 Oct 2007 08:22:26 +0000 (08:22 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 24 Oct 2007 08:22:26 +0000 (08:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21168 a592a061-630c-0410-9148-cb99ea01b6c8

src/Paragraph.cpp
src/Paragraph.h
src/lyxfind.cpp

index 64ef984eb0b57b78fb63b6160798fd68cd837f37..0c5057b61ac5b27e8e0c8383f48c85d251eaabe6 100644 (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];
index e264bb273715b25d07d97dfc5acd41c04805ea66..b1f7884a53b25401ffd7dc4510c890ecd46b39a8 100644 (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;
index 514c508114f62b69c1db5364414faa71bf767538..00800c2c66dc95789d8e79c388cc83f7fafe6271 100644 (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: