#include "lyxfind.h"
#include "Buffer.h"
-#include "buffer_funcs.h"
#include "BufferList.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "output_latex.h"
#include "OutputParams.h"
#include "Paragraph.h"
-#include "ParIterator.h"
-#include "TexRow.h"
#include "Text.h"
#include "Encoding.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h"
-
-#include "support/regex.h"
#include "support/textutils.h"
+
#include <map>
+#include <regex>
using namespace std;
using namespace lyx::support;
class IgnoreFormats {
public:
///
- IgnoreFormats()
- : ignoreFamily_(false), ignoreSeries_(false),
- ignoreShape_(false), ignoreUnderline_(false),
- ignoreMarkUp_(false), ignoreStrikeOut_(false),
- ignoreSectioning_(false), ignoreFrontMatter_(false),
- ignoreColor_(false), ignoreLanguage_(false) {}
+ IgnoreFormats() = default;
///
- bool getFamily() { return ignoreFamily_; }
+ bool getFamily() const { return ignoreFamily_; }
///
- bool getSeries() { return ignoreSeries_; }
+ bool getSeries() const { return ignoreSeries_; }
///
- bool getShape() { return ignoreShape_; }
+ bool getShape() const { return ignoreShape_; }
///
- bool getUnderline() { return ignoreUnderline_; }
+ bool getUnderline() const { return ignoreUnderline_; }
///
- bool getMarkUp() { return ignoreMarkUp_; }
+ bool getMarkUp() const { return ignoreMarkUp_; }
///
- bool getStrikeOut() { return ignoreStrikeOut_; }
+ bool getStrikeOut() const { return ignoreStrikeOut_; }
///
- bool getSectioning() { return ignoreSectioning_; }
+ bool getSectioning() const { return ignoreSectioning_; }
///
- bool getFrontMatter() { return ignoreFrontMatter_; }
+ bool getFrontMatter() const { return ignoreFrontMatter_; }
///
- bool getColor() { return ignoreColor_; }
+ bool getColor() const { return ignoreColor_; }
///
- bool getLanguage() { return ignoreLanguage_; }
+ bool getLanguage() const { return ignoreLanguage_; }
///
void setIgnoreFormat(string const & type, bool value);
private:
///
- bool ignoreFamily_;
+ bool ignoreFamily_ = false;
///
- bool ignoreSeries_;
+ bool ignoreSeries_ = false;
///
- bool ignoreShape_;
+ bool ignoreShape_ = false;
///
- bool ignoreUnderline_;
+ bool ignoreUnderline_ = false;
///
- bool ignoreMarkUp_;
+ bool ignoreMarkUp_ = false;
///
- bool ignoreStrikeOut_;
+ bool ignoreStrikeOut_ = false;
///
- bool ignoreSectioning_;
+ bool ignoreSectioning_ = false;
///
- bool ignoreFrontMatter_;
+ bool ignoreFrontMatter_ = false;
///
- bool ignoreColor_;
+ bool ignoreColor_ = false;
///
- bool ignoreLanguage_;
+ bool ignoreLanguage_ = false;
};
bool regex_replace(string const & s, string & t, string const & searchstr,
string const & replacestr)
{
- lyx::regex e(searchstr, regex_constants::ECMAScript);
+ regex e(searchstr, regex_constants::ECMAScript);
ostringstream oss;
ostream_iterator<char, char> it(oss);
- lyx::regex_replace(it, s.begin(), s.end(), e, replacestr);
+ regex_replace(it, s.begin(), s.end(), e, replacestr);
// tolerate t and s be references to the same variable
bool rv = (s != oss.str());
t = oss.str();
// normalized string to search
string par_as_string;
// regular expression to use for searching
- lyx::regex regexp;
+ regex regexp;
// same as regexp, but prefixed with a ".*?"
- lyx::regex regexp2;
+ regex regexp2;
// leading format material as string
string lead_as_string;
// par_as_string after removal of lead_as_string
odocstringstream ods;
otexstream os(ods);
runparams.nice = true;
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = FLAVOR::XETEX;
runparams.linelen = 10000; //lyxrc.plaintext_linelen;
// No side effect of file copying and image conversion
runparams.dryrun = true;
// OutputParams runparams(&buffer.params().encoding());
OutputParams runparams(encodings.fromLyXName("utf8"));
runparams.nice = true;
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = FLAVOR::XETEX;
runparams.linelen = 10000; //lyxrc.plaintext_linelen;
runparams.dryrun = true;
runparams.for_search = true;
// @TODO Support \item[text]
// Kornel: Added textsl, textsf, textit, texttt and noun
// + allow to search for colored text too
- while (regex_replace(t, t, REGEX_BOS "\\\\(((footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge|emph|noun|minisec|text(bf|md|sl|sf|it|tt))|((textcolor|foreignlanguage|latexenvironment)\\{[a-z]+\\*?\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{", "")
- || regex_replace(t, t, REGEX_BOS "\\$", "")
- || regex_replace(t, t, REGEX_BOS "\\\\\\[", "")
- || regex_replace(t, t, REGEX_BOS " ?\\\\item\\{[a-z]+\\}", "")
- || regex_replace(t, t, REGEX_BOS "\\\\begin\\{[a-zA-Z_]*\\*?\\}", ""))
+ while (regex_replace(t, t, "^\\\\(((footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge|emph|noun|minisec|text(bf|md|sl|sf|it|tt))|((textcolor|foreignlanguage|latexenvironment)\\{[a-z]+\\*?\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{", "")
+ || regex_replace(t, t, "^\\$", "")
+ || regex_replace(t, t, "^\\\\\\[", "")
+ || regex_replace(t, t, "^ ?\\\\item\\{[a-z]+\\}", "")
+ || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\}", ""))
;
LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
return s.find(t);
* so that they can be ignored */
endArguments
};
- KeyInfo()
- : keytype(invalid),
- head(""),
- _tokensize(-1),
- _tokenstart(-1),
- _dataStart(-1),
- _dataEnd(-1),
- parenthesiscount(1),
- disabled(false),
- used(false)
- {};
+ KeyInfo() = default;
KeyInfo(KeyType type, int parcount, bool disable)
: keytype(type),
- _tokensize(-1),
- _tokenstart(-1),
- _dataStart(-1),
- _dataEnd(-1),
parenthesiscount(parcount),
- disabled(disable),
- used(false) {};
- KeyType keytype;
+ disabled(disable) {}
+ KeyType keytype = invalid;
string head;
- int _tokensize;
- int _tokenstart;
- int _dataStart;
- int _dataEnd;
- int parenthesiscount;
- bool disabled;
- bool used; /* by pattern */
+ int _tokensize = -1;
+ int _tokenstart = -1;
+ int _dataStart = -1;
+ int _dataEnd = -1;
+ int parenthesiscount = 1;
+ bool disabled = false;
+ bool used = false; /* by pattern */
};
class Border {
int depts[MAXOPENED];
int closes[MAXOPENED];
int actualdeptindex;
- int previousNotIgnored(int);
- int nextNotIgnored(int);
+ int previousNotIgnored(int) const;
+ int nextNotIgnored(int) const;
void handleOpenP(int i);
void handleCloseP(int i, bool closingAllowed);
void resetOpenedP(int openPos);
void addIntervall(int upper);
void addIntervall(int low, int upper); /* if explicit */
void removeAccents();
- void setForDefaultLang(KeyInfo const & defLang);
+ void setForDefaultLang(KeyInfo const & defLang) const;
int findclosing(int start, int end, char up, char down, int repeat);
void handleParentheses(int lastpos, bool closingAllowed);
bool hasTitle;
int langcount; // Number of disabled language specs up to current position in actual interval
- int isOpeningPar(int pos);
+ int isOpeningPar(int pos) const;
string titleValue;
void output(ostringstream &os, int lastpos);
// string show(int lastpos);
vector<Border> Intervall::borders = vector<Border>(30);
-int Intervall::isOpeningPar(int pos)
+int Intervall::isOpeningPar(int pos) const
{
if ((pos < 0) || (size_t(pos) >= par.size()))
return 0;
return 1;
}
-void Intervall::setForDefaultLang(KeyInfo const & defLang)
+void Intervall::setForDefaultLang(KeyInfo const & defLang) const
{
// Enable the use of first token again
if (ignoreidx >= 0) {
accents["imath"] = "ı";
accents["i"] = "ı";
accents["jmath"] = "ȷ";
+ accents["cdot"] = "·";
accents["lyxmathsym{ß}"] = "ß";
accents["text{ß}"] = "ß";
accents["ddot{\\imath}"] = "ï";
{
if (accents.empty())
buildAccentsMap();
- static regex const accre("\\\\(([\\S]|grave|breve|lyxmathsym|text|ddot|dot|acute|dacute|mathring|check|hat|bar|tilde|subdot|ogonek|cedilla|subring|textsubring|subhat|textsubcircum|subtilde|textsubtilde|dgrave|textdoublegrave|rcap|textroundcap|slashed)\\{[^\\{\\}]+\\}|(i|imath|jmath)(?![a-zA-Z]))");
+ static regex const accre("\\\\(([\\S]|grave|breve|lyxmathsym|text|ddot|dot|acute|dacute|mathring|check|hat|bar|tilde|subdot|ogonek|cedilla|subring|textsubring|subhat|textsubcircum|subtilde|textsubtilde|dgrave|textdoublegrave|rcap|textroundcap|slashed)\\{[^\\{\\}]+\\}|(i|imath|jmath|cdot)(?![a-zA-Z]))");
smatch sub;
for (sregex_iterator itacc(par.begin(), par.end(), accre), end; itacc != end; ++itacc) {
sub = *itacc;
for (size_t i = 0; i < val.size(); i++) {
par[pos+i] = val[i];
}
- addIntervall(pos+val.size(), pos + sub.str(0).size());
+ // Remove possibly following space too
+ if (par[pos+sub.str(0).size()] == ' ')
+ addIntervall(pos+val.size(), pos + sub.str(0).size()+1);
+ else
+ addIntervall(pos+val.size(), pos + sub.str(0).size());
for (size_t i = pos+val.size(); i < pos + sub.str(0).size(); i++) {
// remove traces of any remaining chars
par[i] = ' ';
closes[1] = -1;
}
-int Intervall::previousNotIgnored(int start)
+int Intervall::previousNotIgnored(int start) const
{
int idx = 0; /* int intervalls */
for (idx = ignoreidx; idx >= 0; --idx) {
return start;
}
-int Intervall::nextNotIgnored(int start)
+int Intervall::nextNotIgnored(int start) const
{
int idx = 0; /* int intervalls */
for (idx = 0; idx <= ignoreidx; idx++) {
else
return false;
};
- int find(int start, KeyInfo::KeyType keytype) {
+ int find(int start, KeyInfo::KeyType keytype) const {
if (start < 0)
return -1;
int tmpIdx = start;
else
return entries_[keyinfo];
};
- void setForDefaultLang(KeyInfo &defLang) {interval_.setForDefaultLang(defLang);};
+ void setForDefaultLang(KeyInfo const & defLang) {interval_.setForDefaultLang(defLang);};
void addIntervall(int low, int up) { interval_.addIntervall(low, up); };
};
m.mathSize = end - start;
entries_.push_back(m);
}
- bool empty() { return entries_.empty(); };
- size_t getEndPos() {
+ bool empty() const { return entries_.empty(); };
+ size_t getEndPos() const {
if (entries_.empty() || (actualIdx_ >= entries_.size())) {
return 0;
}
return entries_[actualIdx_].mathEnd;
}
- size_t getStartPos() {
+ size_t getStartPos() const {
if (entries_.empty() || (actualIdx_ >= entries_.size())) {
return 100000; /* definitely enough? */
}
actualIdx_ = 0;
return getStartPos();
}
- size_t getSize() {
+ size_t getSize() const {
if (entries_.empty() || (actualIdx_ >= entries_.size())) {
return size_t(0);
}
int open_braces = 0;
do {
LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'");
- if (regex_replace(t, t, "(.*[^\\\\])\\$" REGEX_EOS, "$1"))
+ if (regex_replace(t, t, "(.*[^\\\\])\\$$", "$1"))
continue;
- if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]" REGEX_EOS, "$1"))
+ if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]$", "$1"))
continue;
- if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}" REGEX_EOS, "$1"))
+ if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}$", "$1"))
continue;
- if (regex_replace(t, t, "(.*[^\\\\])\\}" REGEX_EOS, "$1")) {
+ if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1")) {
++open_braces;
continue;
}
regexp2_str = "(" + lead_as_regexp + ").*?" + par_as_string;
}
LYXERR(Debug::FIND, "Setting regexp to : '" << regexp_str << "'");
- regexp = lyx::regex(regexp_str);
+ regexp = regex(regexp_str);
LYXERR(Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'");
- regexp2 = lyx::regex(regexp2_str);
+ regexp2 = regex(regexp2_str);
}
}
// OutputParams runparams(&cur.buffer()->params().encoding());
OutputParams runparams(encodings.fromLyXName("utf8"));
runparams.nice = true;
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = FLAVOR::XETEX;
runparams.linelen = 10000; //lyxrc.plaintext_linelen;
// No side effect of file copying and image conversion
runparams.dryrun = true;
//OutputParams runparams(&buf.params().encoding());
OutputParams runparams(encodings.fromLyXName("utf8"));
runparams.nice = false;
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = FLAVOR::XETEX;
runparams.linelen = 8000; //lyxrc.plaintext_linelen;
// No side effect of file copying and image conversion
runparams.dryrun = true;
// OutputParams runparams(&repl_buffer.params().encoding());
OutputParams runparams(encodings.fromLyXName("utf8"));
runparams.nice = false;
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = FLAVOR::XETEX;
runparams.linelen = 8000; //lyxrc.plaintext_linelen;
runparams.dryrun = true;
TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams);