mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
simplified search in mathed
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8325 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2f33eaa286
commit
fa494db882
@ -11,12 +11,14 @@
|
||||
#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
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ public:
|
||||
char getChar() const { return char_; }
|
||||
///
|
||||
bool isRelOp() const;
|
||||
///
|
||||
bool match(MathInset const *) const;
|
||||
|
||||
private:
|
||||
/// the character
|
||||
|
@ -19,12 +19,15 @@
|
||||
#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;
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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?
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -15,11 +15,13 @@
|
||||
|
||||
#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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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_ << ']';
|
||||
|
@ -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<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;
|
||||
|
Loading…
Reference in New Issue
Block a user