mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +00:00
Findadv: Use '\n' as delimiter for end of data with same features
This allows to use '.' in regex without matching also wrong data. Also added modified patch from ajd (see #11241).
This commit is contained in:
parent
47455ad65e
commit
5c83ad37d0
@ -948,8 +948,9 @@ class Border {
|
|||||||
|
|
||||||
#define MAXOPENED 30
|
#define MAXOPENED 30
|
||||||
class Intervall {
|
class Intervall {
|
||||||
|
bool isPatternString;
|
||||||
public:
|
public:
|
||||||
Intervall() : ignoreidx(-1), actualdeptindex(0) {};
|
Intervall(bool isPattern) : isPatternString(isPattern), ignoreidx(-1), actualdeptindex(0) {};
|
||||||
string par;
|
string par;
|
||||||
int ignoreidx;
|
int ignoreidx;
|
||||||
int depts[MAXOPENED];
|
int depts[MAXOPENED];
|
||||||
@ -1213,7 +1214,6 @@ class LatexInfo {
|
|||||||
private:
|
private:
|
||||||
int entidx;
|
int entidx;
|
||||||
Entries entries;
|
Entries entries;
|
||||||
KeyInfo analyze(string key);
|
|
||||||
Intervall interval;
|
Intervall interval;
|
||||||
void buildKeys(bool);
|
void buildKeys(bool);
|
||||||
void buildEntries(bool);
|
void buildEntries(bool);
|
||||||
@ -1223,7 +1223,7 @@ class LatexInfo {
|
|||||||
IgnoreFormats f;
|
IgnoreFormats f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LatexInfo(string par, bool isPatternString) {
|
LatexInfo(string par, bool isPatternString) : interval(isPatternString) {
|
||||||
interval.par = par;
|
interval.par = par;
|
||||||
buildKeys(isPatternString);
|
buildKeys(isPatternString);
|
||||||
entries = vector<KeyInfo>();
|
entries = vector<KeyInfo>();
|
||||||
@ -1404,6 +1404,7 @@ void LatexInfo::buildEntries(bool isPatternString)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Ignore language if there is math somewhere in pattern-string
|
||||||
if (isPatternString) {
|
if (isPatternString) {
|
||||||
if (! mi.empty()) {
|
if (! mi.empty()) {
|
||||||
// Disable language
|
// Disable language
|
||||||
@ -1497,7 +1498,6 @@ void LatexInfo::buildEntries(bool isPatternString)
|
|||||||
}
|
}
|
||||||
else if (found.parenthesiscount == 2) {
|
else if (found.parenthesiscount == 2) {
|
||||||
found.head = sub.str(0) + "{";
|
found.head = sub.str(0) + "{";
|
||||||
found._tokensize = found.head.length();
|
|
||||||
}
|
}
|
||||||
found._tokensize = found.head.length();
|
found._tokensize = found.head.length();
|
||||||
found._dataStart = found._tokenstart + found.head.length();
|
found._dataStart = found._tokenstart + found.head.length();
|
||||||
@ -1533,7 +1533,7 @@ void LatexInfo::buildKeys(bool isPatternString)
|
|||||||
static bool keysBuilt = false;
|
static bool keysBuilt = false;
|
||||||
if (keysBuilt && !isPatternString) return;
|
if (keysBuilt && !isPatternString) return;
|
||||||
|
|
||||||
// Know statdard keys with 1 parameter.
|
// Know standard keys with 1 parameter.
|
||||||
// Split is done, if not at start of region
|
// Split is done, if not at start of region
|
||||||
makeKey("textsf|textss|texttt", KeyInfo(KeyInfo::isStandard, 1, f.getFamily()), isPatternString);
|
makeKey("textsf|textss|texttt", KeyInfo(KeyInfo::isStandard, 1, f.getFamily()), isPatternString);
|
||||||
makeKey("textbf", KeyInfo(KeyInfo::isStandard, 1, f.getSeries()), isPatternString);
|
makeKey("textbf", KeyInfo(KeyInfo::isStandard, 1, f.getSeries()), isPatternString);
|
||||||
@ -1563,7 +1563,7 @@ void LatexInfo::buildKeys(bool isPatternString)
|
|||||||
|
|
||||||
// Known macros to remove (including their parameter)
|
// Known macros to remove (including their parameter)
|
||||||
// No split
|
// No split
|
||||||
makeKey("inputencoding|shortcut", KeyInfo(KeyInfo::doRemove, 1, false), isPatternString);
|
makeKey("inputencoding|shortcut|label|ref", KeyInfo(KeyInfo::doRemove, 1, false), isPatternString);
|
||||||
|
|
||||||
// Macros to remove, but let the parameter survive
|
// Macros to remove, but let the parameter survive
|
||||||
// No split
|
// No split
|
||||||
@ -1576,14 +1576,14 @@ void LatexInfo::buildKeys(bool isPatternString)
|
|||||||
makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, true), isPatternString);
|
makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, true), isPatternString);
|
||||||
|
|
||||||
// Survives, like known character
|
// Survives, like known character
|
||||||
makeKey("lyx", KeyInfo(KeyInfo::isIgnored, 0, false), isPatternString);
|
makeKey("lyx|latex|tex", KeyInfo(KeyInfo::isIgnored, 0, false), isPatternString);
|
||||||
makeKey("item", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
|
makeKey("item", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
|
||||||
|
|
||||||
makeKey("begin|end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
makeKey("begin|end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
||||||
makeKey("[|]", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
makeKey("[|]", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
||||||
makeKey("$", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
makeKey("$", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
|
||||||
|
|
||||||
makeKey("par|uldepth|ULdepth", KeyInfo(KeyInfo::doRemove, 0, true), isPatternString);
|
makeKey("par|uldepth|ULdepth|protect", KeyInfo(KeyInfo::doRemove, 0, true), isPatternString);
|
||||||
|
|
||||||
if (isPatternString) {
|
if (isPatternString) {
|
||||||
// Allow the first searched string to rebuild the keys too
|
// Allow the first searched string to rebuild the keys too
|
||||||
@ -1682,6 +1682,8 @@ void Intervall::output(ostringstream &os, int lastpos)
|
|||||||
for (int i = actualdeptindex; i > 0; --i) {
|
for (int i = actualdeptindex; i > 0; --i) {
|
||||||
os << "}";
|
os << "}";
|
||||||
}
|
}
|
||||||
|
if (! isPatternString)
|
||||||
|
os << "\n";
|
||||||
handleParentheses(lastpos, true); /* extra closings '}' allowed here */
|
handleParentheses(lastpos, true); /* extra closings '}' allowed here */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2083,6 +2085,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
|
|||||||
while ( regex_replace(par_as_string, par_as_string, "(.*)\\\\}$", "$1")) {
|
while ( regex_replace(par_as_string, par_as_string, "(.*)\\\\}$", "$1")) {
|
||||||
open_braces++;
|
open_braces++;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// save '\.'
|
// save '\.'
|
||||||
regex_replace(par_as_string, par_as_string, "\\\\\\.", "_xxbdotxx_");
|
regex_replace(par_as_string, par_as_string, "\\\\\\.", "_xxbdotxx_");
|
||||||
// handle '.' -> '[^]', replace later as '[^\}\{\\]'
|
// handle '.' -> '[^]', replace later as '[^\}\{\\]'
|
||||||
@ -2093,6 +2096,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
|
|||||||
regex_replace(par_as_string, par_as_string, "_xxbrrxx_", "]");
|
regex_replace(par_as_string, par_as_string, "_xxbrrxx_", "]");
|
||||||
// restore '\.'
|
// restore '\.'
|
||||||
regex_replace(par_as_string, par_as_string, "_xxbdotxx_", "\\.");
|
regex_replace(par_as_string, par_as_string, "_xxbdotxx_", "\\.");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
|
LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
|
||||||
LYXERR(Debug::FIND, "Open braces: " << open_braces);
|
LYXERR(Debug::FIND, "Open braces: " << open_braces);
|
||||||
@ -2305,16 +2309,17 @@ docstring stringifyFromCursor(DocIterator const & cur, int len)
|
|||||||
AS_STR_INSETS | AS_STR_SKIPDELETE | AS_STR_PLAINTEXT,
|
AS_STR_INSETS | AS_STR_SKIPDELETE | AS_STR_PLAINTEXT,
|
||||||
&runparams);
|
&runparams);
|
||||||
} else if (cur.inMathed()) {
|
} else if (cur.inMathed()) {
|
||||||
docstring s;
|
|
||||||
CursorSlice cs = cur.top();
|
CursorSlice cs = cur.top();
|
||||||
MathData md = cs.cell();
|
MathData md = cs.cell();
|
||||||
MathData::const_iterator it_end =
|
MathData::const_iterator it_end =
|
||||||
(( len == -1 || cs.pos() + len > int(md.size()))
|
(( len == -1 || cs.pos() + len > int(md.size()))
|
||||||
? md.end()
|
? md.end()
|
||||||
: md.begin() + cs.pos() + len );
|
: md.begin() + cs.pos() + len );
|
||||||
|
MathData md2;
|
||||||
for (MathData::const_iterator it = md.begin() + cs.pos();
|
for (MathData::const_iterator it = md.begin() + cs.pos();
|
||||||
it != it_end; ++it)
|
it != it_end; ++it)
|
||||||
s = s + asString(*it);
|
md2.push_back(*it);
|
||||||
|
docstring s = asString(md2);
|
||||||
LYXERR(Debug::FIND, "Stringified math: '" << s << "'");
|
LYXERR(Debug::FIND, "Stringified math: '" << s << "'");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -2371,10 +2376,12 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
|
|||||||
((len == -1 || cs.pos() + len > int(md.size()))
|
((len == -1 || cs.pos() + len > int(md.size()))
|
||||||
? md.end()
|
? md.end()
|
||||||
: md.begin() + cs.pos() + len);
|
: md.begin() + cs.pos() + len);
|
||||||
|
MathData md2;
|
||||||
for (MathData::const_iterator it = md.begin() + cs.pos();
|
for (MathData::const_iterator it = md.begin() + cs.pos();
|
||||||
it != it_end; ++it)
|
it != it_end; ++it)
|
||||||
ods << asString(*it);
|
md2.push_back(*it);
|
||||||
|
|
||||||
|
ods << asString(md2);
|
||||||
// Retrieve the math environment type, and add '$' or '$]'
|
// Retrieve the math environment type, and add '$' or '$]'
|
||||||
// or others (\end{equation}) accordingly
|
// or others (\end{equation}) accordingly
|
||||||
for (int s = cur.depth() - 1; s >= 0; --s) {
|
for (int s = cur.depth() - 1; s >= 0; --s) {
|
||||||
|
Loading…
Reference in New Issue
Block a user