]> git.lyx.org Git - features.git/commitdiff
simplified search in mathed
authorAndré Pönitz <poenitz@gmx.net>
Wed, 7 Jan 2004 18:28:50 +0000 (18:28 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 7 Jan 2004 18:28:50 +0000 (18:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8325 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/mathed/math_autocorrect.C
src/mathed/math_charinset.C
src/mathed/math_charinset.h
src/mathed/math_data.C
src/mathed/math_inset.h
src/mathed/math_macro.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_support.C
src/mathed/math_support.h
src/mathed/math_symbolinset.C
src/mathed/math_symbolinset.h
src/mathed/math_unknowninset.C
src/mathed/math_unknowninset.h

index 7dd038b14f8ca94ba913260b319a1dc7da2b7241..986f3da9d8607093045b2e0fdf68ef9eed558d70 100644 (file)
 #include <config.h>
 
 #include "math_autocorrect.h"
-#include "support/std_sstream.h"
-#include "debug.h"
-#include "support/filetools.h" //  LibFileSearch
 #include "math_data.h"
 #include "math_inset.h"
+#include "math_support.h"
 #include "math_parser.h"
+#include "debug.h"
+
+#include "support/std_sstream.h"
+#include "support/filetools.h" //  LibFileSearch
 
 #include <fstream>
 
@@ -85,7 +87,7 @@ bool Correction::correct(MathAtom & at, char c) const
        //      << "trying to correct ar: " << at << " from: '" << from1_ << '\'' << endl;
        if (from2_ != c)
                return false;
-       if (!at->match(from1_))
+       if (asString(at) != asString(from1_))
                return false;
        lyxerr[Debug::MATHED]
                << "match found! subst in " << at
index 50263400310b087d760266dbaa6187f7bc304832..1b32d447862de68a92fda60e6c1e8a4ea9c6352b 100644 (file)
@@ -151,10 +151,3 @@ bool MathCharInset::isRelOp() const
 {
        return char_ == '=' || char_ == '<' || char_ == '>';
 }
-
-
-bool MathCharInset::match(MathInset const * p) const
-{
-       MathCharInset const * q = p->asCharInset();
-       return q && char_ == q->char_;
-}
index 0f4509bbd3addf4485d065d21f76da5e65c9eecf..067affac0bd7b82ac2b300b777c5002de2c1e909 100644 (file)
@@ -42,8 +42,6 @@ public:
        char getChar() const { return char_; }
        ///
        bool isRelOp() const;
-       ///
-       bool match(MathInset const *) const;
 
 private:
        /// the character
index a7f606eb6314a21df53fc7ae3b5932d9b58120ec..35c727e263d229ba291c87157b25a8013d5b1f60 100644 (file)
 #include "math_replace.h"
 #include "debug.h"
 #include "LColor.h"
+
 #include "frontends/Painter.h"
+
 #include <boost/assert.hpp>
 
 using std::abs;
 using std::endl;
 using std::min;
+using std::ostringstream;
 
 
 MathArray::MathArray()
@@ -137,7 +140,7 @@ bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
                return false;
        const_iterator it = begin() + pos;
        for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
-               if (!(*jt)->match(*it))
+               if (asString(*it) != asString(*jt))
                        return false;
        return true;
 }
@@ -164,9 +167,9 @@ void MathArray::replace(ReplaceData & rep)
 
 bool MathArray::find1(MathArray const & ar, size_type pos) const
 {
-       //lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
+       lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
        for (size_type i = 0, n = ar.size(); i < n; ++i)
-               if (!operator[](pos + i)->match(ar[i]))
+               if (asString(operator[](pos + i)) != asString(ar[i]))
                        return false;
        return true;
 }
index 168727061d97f62aedb897b339a4d0d4e460bd45..779e590fa38925b9bf8b6341770de4b4abbac321 100644 (file)
@@ -205,8 +205,6 @@ public:
 
        /// char char code if possible
        virtual void handleFont(std::string const &) {}
-       /// is this inset equal to a given other inset?
-       virtual bool match(MathAtom const &) const { return false; }
        /// replace things by other things
        virtual void replace(ReplaceData &) {}
        /// do we contain a given subsequence?
index 6047c3811d2b8e74d02cdda34b3fb990bb1b4dbb..8912501b5e32711aa6c8a39ed61df1c0bce99460 100644 (file)
@@ -48,8 +48,6 @@ public:
        void validate(LaTeXFeatures &) const;
        ///
        bool isMacro() const { return true; }
-       ///
-       bool match(MathAtom const &) const { return false; }
 
        ///
        void maple(MapleStream &) const;
index 9692a0b7f697692e7b2bf53b8df92ef29d14b4ee..36c90752345b9f5985e801c132b0b36cdbcdd3d5 100644 (file)
@@ -197,17 +197,6 @@ void MathNestInset::validate(LaTeXFeatures & features) const
 }
 
 
-bool MathNestInset::match(MathAtom const & at) const
-{
-       if (nargs() != at->nargs())
-               return false;
-       for (idx_type i = 0; i < nargs(); ++i)
-               if (!cell(i).match(at->cell(i)))
-                       return false;
-       return true;
-}
-
-
 void MathNestInset::replace(ReplaceData & rep)
 {
        for (idx_type i = 0; i < nargs(); ++i)
index 2c4a6f14c792d52f17d65d5d607510222f142cf2..5ec7b9234d546864bfe70b8fcf1f84a532448a1b 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "math_diminset.h"
 
-class MathArray;
-
 
 /** Abstract base class for all math objects that contain nested items.
     This is basically everything that is not a single character or a
@@ -83,8 +81,6 @@ public:
        /// request "external features"
        void validate(LaTeXFeatures & features) const;
 
-       /// match in all cells
-       bool match(MathAtom const &) const;
        /// replace in all cells
        void replace(ReplaceData &);
        /// do we contain a given pattern?
index 050d5401cfcdb33481830180496c2e58de51fcac..148d33e54e870624a84c5f232618872533293583 100644 (file)
@@ -12,8 +12,8 @@
 #include <config.h>
 
 #include "math_support.h"
-
 #include "math_data.h"
+#include "math_inset.h"
 #include "math_mathmlstream.h"
 #include "math_parser.h"
 
@@ -708,3 +708,21 @@ void asArray(string const & str, MathArray & ar)
 {
        mathed_parse_cell(ar, str);
 }
+
+
+string asString(MathInset const & inset)
+{
+       std::ostringstream os;
+       WriteStream ws(os);
+       inset.write(ws);
+       return os.str();
+}
+
+
+string asString(MathAtom const & at)
+{
+       std::ostringstream os;
+       WriteStream ws(os);
+       at->write(ws);
+       return os.str();
+}
index 2788a7e46b611259c697cc7035542ceb23fe5be4..17a48807525b4059cf45f59f31ce9d836f2ecefa 100644 (file)
 
 #include <string>
 
-
 class PainterInfo;
 class LyXFont;
 class Dimension;
 class MathArray;
+class MathAtom;
+class MathInset;
+
 
 void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim);
 int mathed_char_width(LyXFont const &, unsigned char c);
@@ -46,6 +48,9 @@ bool isFontName(std::string const & name);
 
 // converts single cell to string
 std::string asString(MathArray const & ar);
+// converts single inset to string
+std::string asString(MathInset const &);
+std::string asString(MathAtom const &);
 // converts string to single cell
 void asArray(std::string const & str, MathArray & ar);
 
index 6657899b3f06c6fd5aaff51b3715bf9c9150a6f6..995acee314642552d71a37df15a94f3e446e1e86 100644 (file)
@@ -182,13 +182,6 @@ char const * MathMLtype(string const & s)
 }
 
 
-bool MathSymbolInset::match(MathAtom const & at) const
-{
-       MathSymbolInset const * q = at->asSymbolInset();
-       return q && name() == q->name();
-}
-
-
 void MathSymbolInset::mathmlize(MathMLStream & os) const
 {
        char const * type = MathMLtype(sym_->extra);
index 174e59cc686ea88ab1899fe7f0c295341ce2741c..f8f2fb276b487dbad784925a3cb06e3fd77ae0d7 100644 (file)
@@ -44,8 +44,6 @@ public:
        MathSymbolInset const * asSymbolInset() const { return this; }
        /// the LaTeX name of the symbol (without the backslash)
        std::string name() const;
-       ///
-       bool match(MathAtom const &) const;
        /// request "external features"
        void validate(LaTeXFeatures & features) const;
 
index a8a0be9aa15546e65ac09b7bd4ebf3b43c5d351a..a4075d2b3d3dab47940b9ac954b0e2e6b7003d29 100644 (file)
@@ -44,13 +44,6 @@ void MathUnknownInset::setName(string const & name)
 }
 
 
-bool MathUnknownInset::match(MathAtom const & at) const
-{
-       MathUnknownInset const * q = at->asUnknownInset();
-       return q && name_ == q->name_;
-}
-
-
 void MathUnknownInset::normalize(NormalStream & os) const
 {
        os << "[unknown " << name_ << ']';
index f7178a2c39a5865590a18beda55b1c90c576e2f4..af0971777a499aa4813b3d4a3d3cb5c5da9c3fe4 100644 (file)
 
 #include "math_diminset.h"
 
-/// Unknowntions or LaTeX names for objects that we really don't know
+
+/// LaTeX names for objects that we really don't know
 class MathUnknownInset : public MathDimInset {
 public:
        ///
        explicit MathUnknownInset(std::string const & name,
                bool final = true, bool black = false);
        ///
-       virtual std::auto_ptr<InsetBase> clone() const;
+       std::auto_ptr<InsetBase> clone() const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -34,8 +35,6 @@ public:
        MathUnknownInset const * asUnknownInset() const { return this; }
        /// identifies UnknownInsets
        MathUnknownInset * asUnknownInset() { return this; }
-       ///
-       bool match(MathAtom const & at) const;
 
        ///
        void normalize(NormalStream &) const;