Extract vert, langle, rangle in MathExtern like parentheses and brackets.

This patch is part of a series that aims at solving https://www.lyx.org/trac/ticket/12891. It is an excerpt of the patch that lynx published at https://www.lyx.org/trac/ticket/12270.
This commit is contained in:
Thibaut Cuvelier 2024-03-11 01:22:12 +01:00
parent b1a4eb118c
commit 9e6b810b37

View File

@ -292,6 +292,19 @@ bool testString(MathAtom const & at, char const * const str)
return testString(at, from_ascii(str)); return testString(at, from_ascii(str));
} }
bool testSymbol(MathAtom const & at, docstring const & name)
{
return at->asSymbolInset() && at->asSymbolInset()->name() == name;
}
bool testSymbol(MathAtom const & at, char const * const name)
{
return testSymbol(at, from_ascii(name));
}
// search end of nested sequence // search end of nested sequence
MathData::iterator endNestSearch( MathData::iterator endNestSearch(
MathData::iterator it, MathData::iterator it,
@ -523,12 +536,52 @@ MathAtom replaceBracketDelims(const MathData & ar)
} }
// replace '('...')' and '['...']' sequences by a real InsetMathDelim bool testOpenVert(MathAtom const & at)
{
return testSymbol(at, "lvert");
}
bool testCloseVert(MathAtom const & at)
{
return testSymbol(at, "rvert");
}
MathAtom replaceVertDelims(const MathData & ar)
{
return MathAtom(new InsetMathDelim(const_cast<Buffer *>(ar.buffer()),
from_ascii("lvert"), from_ascii("rvert"), ar, true));
}
bool testOpenAngled(MathAtom const & at)
{
return testSymbol(at, "langle");
}
bool testCloseAngled(MathAtom const & at)
{
return testSymbol(at, "rangle");
}
MathAtom replaceAngledDelims(const MathData & ar)
{
return MathAtom(new InsetMathDelim(const_cast<Buffer *>(ar.buffer()),
from_ascii("langle"), from_ascii("rangle"), ar, true));
}
// replace '('...')', '['...']', '|'...'|', and '<'...'>' sequences by a real InsetMathDelim
void extractDelims(MathData & ar) void extractDelims(MathData & ar)
{ {
//lyxerr << "\nDelims from: " << ar << endl; //lyxerr << "\nDelims from: " << ar << endl;
replaceNested(ar, testOpenParen, testCloseParen, replaceParenDelims); replaceNested(ar, testOpenParen, testCloseParen, replaceParenDelims);
replaceNested(ar, testOpenBracket, testCloseBracket, replaceBracketDelims); replaceNested(ar, testOpenBracket, testCloseBracket, replaceBracketDelims);
replaceNested(ar, testOpenVert, testCloseVert, replaceVertDelims);
replaceNested(ar, testOpenAngled, testCloseAngled, replaceAngledDelims);
//lyxerr << "\nDelims to: " << ar << endl; //lyxerr << "\nDelims to: " << ar << endl;
} }
@ -622,18 +675,6 @@ void extractFunctions(MathData & ar, ExternalMath kind)
// search integrals // search integrals
// //
bool testSymbol(MathAtom const & at, docstring const & name)
{
return at->asSymbolInset() && at->asSymbolInset()->name() == name;
}
bool testSymbol(MathAtom const & at, char const * const name)
{
return testSymbol(at, from_ascii(name));
}
bool testIntSymbol(MathAtom const & at) bool testIntSymbol(MathAtom const & at)
{ {
return testSymbol(at, from_ascii("int")); return testSymbol(at, from_ascii("int"));