diff --git a/src/mathed/math_autocorrect.C b/src/mathed/math_autocorrect.C index 7dd038b14f..986f3da9d8 100644 --- a/src/mathed/math_autocorrect.C +++ b/src/mathed/math_autocorrect.C @@ -11,12 +11,14 @@ #include #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 @@ -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 diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 5026340031..1b32d44786 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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_; -} diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 0f4509bbd3..067affac0b 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -42,8 +42,6 @@ public: char getChar() const { return char_; } /// bool isRelOp() const; - /// - bool match(MathInset const *) const; private: /// the character diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index a7f606eb63..35c727e263 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -19,12 +19,15 @@ #include "math_replace.h" #include "debug.h" #include "LColor.h" + #include "frontends/Painter.h" + #include 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; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 168727061d..779e590fa3 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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? diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 6047c3811d..8912501b5e 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -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; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 9692a0b7f6..36c9075234 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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) diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 2c4a6f14c7..5ec7b9234d 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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? diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 050d5401cf..148d33e54e 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -12,8 +12,8 @@ #include #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(); +} diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index 2788a7e46b..17a4880752 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -15,11 +15,13 @@ #include - 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); diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 6657899b3f..995acee314 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -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); diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 174e59cc68..f8f2fb276b 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -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; diff --git a/src/mathed/math_unknowninset.C b/src/mathed/math_unknowninset.C index a8a0be9aa1..a4075d2b3d 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -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_ << ']'; diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index f7178a2c39..af0971777a 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -14,14 +14,15 @@ #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 clone() const; + std::auto_ptr 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;