2001-12-18 03:16:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-11-16 09:55:37 +00:00
|
|
|
#include "math_data.h"
|
2001-07-13 09:54:32 +00:00
|
|
|
#include "math_inset.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "math_deliminset.h"
|
2001-08-17 13:18:10 +00:00
|
|
|
#include "math_charinset.h"
|
2001-09-11 10:58:17 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-11-05 17:08:45 +00:00
|
|
|
#include "math_stringinset.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "math_matrixinset.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-11-16 09:55:37 +00:00
|
|
|
#include "math_replace.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
#include "debug.h"
|
2001-10-12 12:02:49 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
|
2001-11-07 08:51:35 +00:00
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
MathArray::MathArray(const_iterator from, const_iterator to)
|
|
|
|
: base_type(from, to)
|
2001-11-09 10:44:24 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathArray::substitute(MathMacro const & m)
|
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
for (iterator it = begin(); it != end(); ++it)
|
2001-10-12 12:02:49 +00:00
|
|
|
it->nucleus()->substitute(m);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 14:16:57 +00:00
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
MathAtom & MathArray::operator[](size_type pos)
|
2001-04-27 12:35:55 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos < size());
|
2002-07-30 13:56:02 +00:00
|
|
|
return base_type::operator[](pos);
|
2001-07-12 07:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
MathAtom const & MathArray::operator[](size_type pos) const
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos < size());
|
2002-07-30 13:56:02 +00:00
|
|
|
return base_type::operator[](pos);
|
2001-10-12 12:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::insert(size_type pos, MathAtom const & t)
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
base_type::insert(begin() + pos, t);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
2001-11-08 12:55:58 +00:00
|
|
|
void MathArray::insert(size_type pos, MathArray const & ar)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
base_type::insert(begin() + pos, ar.begin(), ar.end());
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
void MathArray::append(MathArray const & ar)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-11-08 12:55:58 +00:00
|
|
|
insert(size(), ar);
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
void MathArray::erase(size_type pos)
|
2001-02-14 17:50:58 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
if (pos < size())
|
2001-08-07 12:02:21 +00:00
|
|
|
erase(pos, pos + 1);
|
2001-02-14 17:50:58 +00:00
|
|
|
}
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
2001-11-09 10:44:24 +00:00
|
|
|
void MathArray::erase(iterator pos1, iterator pos2)
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
base_type::erase(pos1, pos2);
|
2001-11-09 10:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::erase(iterator pos)
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
base_type::erase(pos);
|
2001-11-09 10:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
void MathArray::erase(size_type pos1, size_type pos2)
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
base_type::erase(begin() + pos1, begin() + pos2);
|
2001-11-09 16:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
void MathArray::dump2() const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-08 12:06:56 +00:00
|
|
|
ns << it->nucleus() << ' ';
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
void MathArray::dump() const
|
2001-02-12 08:55:14 +00:00
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-08 12:06:56 +00:00
|
|
|
ns << "<" << it->nucleus() << ">";
|
2001-02-12 08:55:14 +00:00
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathArray::validate(LaTeXFeatures & features) const
|
2001-07-13 14:54:56 +00:00
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2001-11-07 08:51:35 +00:00
|
|
|
if (it->nucleus())
|
|
|
|
it->nucleus()->validate(features);
|
2001-07-13 14:54:56 +00:00
|
|
|
}
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
|
2001-11-16 09:07:40 +00:00
|
|
|
bool MathArray::match(MathArray const & ar) const
|
|
|
|
{
|
2002-01-03 09:41:26 +00:00
|
|
|
return size() == ar.size() && matchpart(ar, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
|
|
|
|
{
|
|
|
|
if (size() < ar.size() + pos)
|
2001-11-16 09:07:40 +00:00
|
|
|
return false;
|
2002-03-21 17:42:56 +00:00
|
|
|
const_iterator it = begin() + pos;
|
2002-01-03 09:41:26 +00:00
|
|
|
for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
|
|
|
|
if (!jt->nucleus()->match(it->nucleus()))
|
2001-11-16 09:07:40 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2001-11-16 09:55:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathArray::replace(ReplaceData & rep)
|
|
|
|
{
|
|
|
|
for (size_type i = 0; i < size(); ++i) {
|
2002-06-18 15:44:30 +00:00
|
|
|
if (find1(rep.from, i)) {
|
2001-11-16 09:55:37 +00:00
|
|
|
// match found
|
|
|
|
lyxerr << "match found!\n";
|
2002-06-18 15:44:30 +00:00
|
|
|
erase(i, i + rep.from.size());
|
2001-11-16 09:55:37 +00:00
|
|
|
insert(i, rep.to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
|
|
|
it->nucleus()->replace(rep);
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
bool MathArray::find1(MathArray const & ar, size_type pos) const
|
2002-02-01 17:01:30 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
//lyxerr << "finding '" << ar << "' in '" << *this << "'\n";
|
|
|
|
for (size_type i = 0, n = ar.size(); i < n; ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
if (!operator[](pos + i)->match(ar[i].nucleus()))
|
2002-06-18 15:44:30 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::size_type MathArray::find(MathArray const & ar) const
|
|
|
|
{
|
|
|
|
for (int i = 0, last = size() - ar.size(); i < last; ++i)
|
|
|
|
if (find1(ar, i))
|
|
|
|
return i;
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::size_type MathArray::find_last(MathArray const & ar) const
|
|
|
|
{
|
|
|
|
for (int i = size() - ar.size(); i >= 0; --i)
|
|
|
|
if (find1(ar, i))
|
|
|
|
return i;
|
|
|
|
return size();
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
bool MathArray::contains(MathArray const & ar) const
|
|
|
|
{
|
|
|
|
if (find(ar) != size())
|
|
|
|
return true;
|
2002-02-01 17:01:30 +00:00
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
|
|
|
if (it->nucleus()->contains(ar))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|