mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
simple search-and-replace
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3037 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
af2a6c6512
commit
39924c351c
@ -94,6 +94,7 @@ libmathed_la_SOURCES = \
|
|||||||
math_notinset.h \
|
math_notinset.h \
|
||||||
math_parser.C \
|
math_parser.C \
|
||||||
math_parser.h \
|
math_parser.h \
|
||||||
|
math_replace.h \
|
||||||
math_rootinset.C \
|
math_rootinset.C \
|
||||||
math_rootinset.h \
|
math_rootinset.h \
|
||||||
math_scriptinset.C \
|
math_scriptinset.C \
|
||||||
|
@ -118,3 +118,10 @@ void MathCharInset::handleFont(MathTextCodes t)
|
|||||||
{
|
{
|
||||||
code_ = (code_ == t) ? LM_TC_VAR : t;
|
code_ = (code_ == t) ? LM_TC_VAR : t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MathCharInset::match(MathInset * p) const
|
||||||
|
{
|
||||||
|
MathCharInset const * q = p->asCharInset();
|
||||||
|
return q && char_ == q->char_ && code_ == q->code_;
|
||||||
|
}
|
||||||
|
@ -52,6 +52,8 @@ public:
|
|||||||
bool isRelOp() const;
|
bool isRelOp() const;
|
||||||
///
|
///
|
||||||
void handleFont(MathTextCodes t);
|
void handleFont(MathTextCodes t);
|
||||||
|
///
|
||||||
|
bool match(MathInset *) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// the character
|
/// the character
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
#include "math_spaceinset.h"
|
#include "math_spaceinset.h"
|
||||||
#include "math_specialcharinset.h"
|
#include "math_specialcharinset.h"
|
||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
|
#include "math_replace.h"
|
||||||
|
#include "math_parser.h"
|
||||||
|
|
||||||
#define FILEDEBUG 0
|
#define FILEDEBUG 0
|
||||||
|
|
||||||
@ -1272,6 +1274,18 @@ bool MathCursor::interpret(string const & s)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.size() >= 7 && s.substr(0, 7) == "replace") {
|
||||||
|
ReplaceData rep;
|
||||||
|
istringstream is(s.substr(7).c_str());
|
||||||
|
string from, to;
|
||||||
|
is >> from >> to;
|
||||||
|
mathed_parse_cell(rep.from, from);
|
||||||
|
mathed_parse_cell(rep.to, to);
|
||||||
|
lyxerr << "replacing '" << from << "' with '" << to << "'\n";
|
||||||
|
par()->replace(rep);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (s == "\\over" || s == "\\choose" || s == "\\atop") {
|
if (s == "\\over" || s == "\\choose" || s == "\\atop") {
|
||||||
MathArray ar = array();
|
MathArray ar = array();
|
||||||
MathAtom t = createMathInset(s.substr(1));
|
MathAtom t = createMathInset(s.substr(1));
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma implementation
|
#pragma implementation
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "math_data.h"
|
||||||
#include "math_inset.h"
|
#include "math_inset.h"
|
||||||
#include "math_deliminset.h"
|
#include "math_deliminset.h"
|
||||||
#include "math_charinset.h"
|
#include "math_charinset.h"
|
||||||
@ -10,7 +11,7 @@
|
|||||||
#include "math_matrixinset.h"
|
#include "math_matrixinset.h"
|
||||||
#include "math_mathmlstream.h"
|
#include "math_mathmlstream.h"
|
||||||
#include "math_support.h"
|
#include "math_support.h"
|
||||||
#include "math_data.h"
|
#include "math_replace.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "support/LAssert.h"
|
#include "support/LAssert.h"
|
||||||
|
|
||||||
@ -215,3 +216,25 @@ bool MathArray::match(MathArray const & ar) const
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathArray::replace(ReplaceData & rep)
|
||||||
|
{
|
||||||
|
for (size_type i = 0; i < size(); ++i) {
|
||||||
|
iterator it = begin() + i;
|
||||||
|
const_iterator rt = rep.from.begin();
|
||||||
|
const_iterator et = rep.from.end();
|
||||||
|
for (const_iterator jt = it; jt != end() && rt != et; ++jt, ++rt)
|
||||||
|
if (!jt->nucleus()->match(rt->nucleus()))
|
||||||
|
break;
|
||||||
|
if (rt == et) {
|
||||||
|
// match found
|
||||||
|
lyxerr << "match found!\n";
|
||||||
|
erase(it, it + rep.from.size());
|
||||||
|
insert(i, rep.to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const_iterator it = begin(); it != end(); ++it)
|
||||||
|
it->nucleus()->replace(rep);
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
class MathMacro;
|
class MathMacro;
|
||||||
class LaTeXFeatures;
|
class LaTeXFeatures;
|
||||||
|
class ReplaceData;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
@ -104,6 +105,8 @@ public:
|
|||||||
void substitute(MathMacro const &);
|
void substitute(MathMacro const &);
|
||||||
///
|
///
|
||||||
bool match(MathArray const &) const;
|
bool match(MathArray const &) const;
|
||||||
|
///
|
||||||
|
void replace(ReplaceData &);
|
||||||
|
|
||||||
///
|
///
|
||||||
MathAtom & at(size_type pos);
|
MathAtom & at(size_type pos);
|
||||||
|
@ -231,6 +231,8 @@ public:
|
|||||||
virtual void handleFont(MathTextCodes) {}
|
virtual void handleFont(MathTextCodes) {}
|
||||||
///
|
///
|
||||||
virtual bool match(MathInset *) const { return false; }
|
virtual bool match(MathInset *) const { return false; }
|
||||||
|
///
|
||||||
|
virtual void replace(ReplaceData &) {}
|
||||||
|
|
||||||
/// write normalized content
|
/// write normalized content
|
||||||
virtual void normalize(NormalStream &) const;
|
virtual void normalize(NormalStream &) const;
|
||||||
|
@ -63,6 +63,8 @@ public:
|
|||||||
void validate(LaTeXFeatures &) const;
|
void validate(LaTeXFeatures &) const;
|
||||||
///
|
///
|
||||||
bool isMacro() const { return true; }
|
bool isMacro() const { return true; }
|
||||||
|
///
|
||||||
|
bool match(MathInset *) const { return false; }
|
||||||
|
|
||||||
///
|
///
|
||||||
void normalize(NormalStream &) const;
|
void normalize(NormalStream &) const;
|
||||||
|
@ -189,3 +189,10 @@ bool MathNestInset::match(MathInset * p) const
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathNestInset::replace(ReplaceData & rep)
|
||||||
|
{
|
||||||
|
for (idx_type i = 0; i < nargs(); ++i)
|
||||||
|
cell(i).replace(rep);
|
||||||
|
}
|
||||||
|
@ -67,6 +67,8 @@ public:
|
|||||||
void dump() const;
|
void dump() const;
|
||||||
///
|
///
|
||||||
bool match(MathInset *) const;
|
bool match(MathInset *) const;
|
||||||
|
///
|
||||||
|
void replace(ReplaceData &);
|
||||||
|
|
||||||
///
|
///
|
||||||
void validate(LaTeXFeatures & features) const;
|
void validate(LaTeXFeatures & features) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user