Include standard <regex>

This commit is contained in:
Yuriy Skalko 2020-11-29 01:05:24 +02:00
parent 54ccd275f1
commit 7779316e6c
20 changed files with 70 additions and 120 deletions

View File

@ -32,10 +32,10 @@
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/regex.h"
#include "support/textutils.h"
#include <map>
#include <regex>
#include <set>
using namespace std;
@ -383,8 +383,8 @@ docstring convertLaTeXCommands(docstring const & str)
// {\v a} to \v{a} (see #9340).
// FIXME: This is a sort of mini-tex2lyx.
// Use the real tex2lyx instead!
static lyx::regex const tma_reg("^\\{\\\\[bcCdfGhHkrtuUv]\\s\\w\\}");
if (lyx::regex_search(to_utf8(val), tma_reg)) {
static regex const tma_reg("^\\{\\\\[bcCdfGhHkrtuUv]\\s\\w\\}");
if (regex_search(to_utf8(val), tma_reg)) {
val = val.substr(1);
val.replace(2, 1, from_ascii("{"));
continue;
@ -411,8 +411,8 @@ docstring convertLaTeXCommands(docstring const & str)
// look for that and change it, if necessary.
// FIXME: This is a sort of mini-tex2lyx.
// Use the real tex2lyx instead!
static lyx::regex const reg("^\\\\\\W\\w");
if (lyx::regex_search(to_utf8(val), reg)) {
static regex const reg("^\\\\\\W\\w");
if (regex_search(to_utf8(val), reg)) {
val.insert(3, from_ascii("}"));
val.insert(2, from_ascii("{"));
}

View File

@ -36,9 +36,8 @@
#include "support/Systemcall.h"
#include "support/os.h"
#include "support/regex.h"
#include <fstream>
#include <regex>
#include <stack>

View File

@ -40,9 +40,9 @@
#include "support/docstring.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/regex.h"
#include <algorithm>
#include <regex>
using namespace std;

View File

@ -19,11 +19,10 @@
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lassert.h"
#include "support/regex.h"
#include "support/TempFile.h"
#include <fstream>
#include <regex>
using namespace std;
using namespace lyx::support;

View File

@ -72,13 +72,13 @@
#include "support/lassert.h"
#include "support/limited_stack.h"
#include "support/lstrings.h"
#include "support/regex.h"
#include "mathed/InsetMathHull.h"
#include "mathed/InsetMathMacroTemplate.h"
#include "lyxfind.h"
#include <clocale>
#include <regex>
#include <sstream>
using namespace std;

View File

@ -26,11 +26,11 @@
#include "support/lstrings.h"
#include "support/PathChanger.h"
#include "support/Systemcall.h"
#include "support/regex.h"
#include "support/TempFile.h"
#include <fstream>
#include <iomanip>
#include <regex>
#include <sstream>
using namespace std;

View File

@ -45,9 +45,8 @@
#undef KeyPress
#include "support/regex.h"
#include <algorithm>
#include <regex>
#include <string>
#include <vector>
@ -987,21 +986,21 @@ static docstring escape_special_chars(docstring const & expr)
{
// Search for all chars '.|*?+(){}[^$]\'
// Note that '[', ']', and '\' must be escaped.
static const lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
static const regex reg("[.|*?+(){}^$\\[\\]\\\\]");
// $& is an ECMAScript format expression that expands to all
// of the current match
// To prefix a matched expression with a single literal backslash, we
// need to escape it for the C++ compiler and use:
// FIXME: UNICODE
return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\$&")));
return from_utf8(regex_replace(to_utf8(expr), reg, string("\\$&")));
}
vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
vector<docstring> const & keys_to_search, bool only_keys,
docstring const & search_expression, docstring const & field,
bool case_sensitive, bool regex)
bool case_sensitive, bool re)
{
vector<docstring> foundKeys;
@ -1009,17 +1008,17 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
if (expr.empty())
return foundKeys;
if (!regex)
if (!re)
// We must escape special chars in the search_expr so that
// it is treated as a simple string by lyx::regex.
// it is treated as a simple string by regex.
expr = escape_special_chars(expr);
lyx::regex reg_exp;
regex reg_exp;
try {
reg_exp.assign(to_utf8(expr), case_sensitive ?
lyx::regex_constants::ECMAScript : lyx::regex_constants::icase);
} catch (lyx::regex_error const & e) {
// lyx::regex throws an exception if the regular expression is not
regex_constants::ECMAScript : regex_constants::icase);
} catch (regex_error const & e) {
// regex throws an exception if the regular expression is not
// valid.
LYXERR(Debug::GUI, e.what());
return vector<docstring>();
@ -1045,10 +1044,10 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
continue;
try {
if (lyx::regex_search(sdata, reg_exp))
if (regex_search(sdata, reg_exp))
foundKeys.push_back(*it);
}
catch (lyx::regex_error const & e) {
catch (regex_error const & e) {
LYXERR(Debug::GUI, e.what());
return vector<docstring>();
}

View File

@ -58,8 +58,7 @@
// for FileFilter.
// FIXME: Remove
#include "support/regex.h"
#include <regex>
using namespace std;
using namespace lyx::support;
@ -496,10 +495,10 @@ static string const convert_brace_glob(string const & glob)
{
// Matches " *.{abc,def,ghi}", storing "*." as group 1 and
// "abc,def,ghi" as group 2, while allowing spaces in group 2.
static lyx::regex const glob_re(" *([^ {]*)\\{([^}]+)\\}");
static regex const glob_re(" *([^ {]*)\\{([^}]+)\\}");
// Matches "abc" and "abc,", storing "abc" as group 1,
// while ignoring surrounding spaces.
static lyx::regex const block_re(" *([^ ,}]+) *,? *");
static regex const block_re(" *([^ ,}]+) *,? *");
string pattern;
@ -624,14 +623,14 @@ FileFilterList::FileFilterList(docstring const & qt_style_filter)
// Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)"
// into individual filters.
static lyx::regex const separator_re(";;");
static regex const separator_re(";;");
string::const_iterator it = filter.begin();
string::const_iterator const end = filter.end();
while (true) {
match_results<string::const_iterator> what;
if (!lyx::regex_search(it, end, what, separator_re)) {
if (!regex_search(it, end, what, separator_re)) {
parse_filter(string(it, end));
break;
}
@ -650,10 +649,10 @@ void FileFilterList::parse_filter(string const & filter)
{
// Matches "TeX documents (plain) (*.tex)",
// storing "TeX documents (plain) " as group 1 and "*.tex" as group 2.
static lyx::regex const filter_re("(.*)\\(([^()]+)\\) *$");
static regex const filter_re("(.*)\\(([^()]+)\\) *$");
match_results<string::const_iterator> what;
if (!lyx::regex_search(filter, what, filter_re)) {
if (!regex_search(filter, what, filter_re)) {
// Just a glob, no description.
filters_.push_back(Filter(docstring(), trim(filter)));
} else {

View File

@ -2,8 +2,7 @@
#include <iostream>
#include <map>
#include "support/regex.h"
#include <regex>
using namespace std;
@ -16,13 +15,13 @@ string const escape_special_chars(string const & expr)
{
// Search for all chars '.|*?+(){}[^$]\'
// Note that '[', ']', and '\' must be escaped.
lyx::regex reg("[.|*?+(){}^$\\[\\]\\\\]");
regex reg("[.|*?+(){}^$\\[\\]\\\\]");
// $& is a ECMAScript format expression that expands to all
// of the current match
// To prefix a matched expression with a single literal backslash, we
// need to escape it for the C++ compiler and use:
return lyx::regex_replace(expr, reg, "\\$&");
return regex_replace(expr, reg, "\\$&");
}
@ -49,11 +48,11 @@ public:
// Attempts to find a match for the current RE
// somewhere in data.
return lyx::regex_search(data, regex_);
return regex_search(data, regex_);
}
private:
InfoMap const map_;
mutable lyx::regex regex_;
mutable regex regex_;
};
@ -77,7 +76,7 @@ void test_RegexMatch()
cout << rm("hello") << endl;
cout << rm("hei") << endl;
}
catch (lyx::regex_error & regerr) {
catch (regex_error & regerr) {
cout << regerr.what() << endl;
}
}

View File

@ -29,7 +29,8 @@
#include "support/docstream.h"
#include "support/filetools.h"
#include "support/FileName.h"
#include "support/regex.h"
#include <regex>
using namespace std;
using namespace lyx::support;
@ -58,13 +59,13 @@ string const readBB_from_PSFile(FileName const & file)
return string();
}
static lyx::regex bbox_re("^%%BoundingBox:\\s*([-]*[[:digit:]]+)"
static regex bbox_re("^%%BoundingBox:\\s*([-]*[[:digit:]]+)"
"\\s+([-]*[[:digit:]]+)\\s+([-]*[[:digit:]]+)\\s+([-]*[[:digit:]]+)");
ifstream is(file_.toFilesystemEncoding().c_str());
while (is) {
string s;
getline(is,s);
lyx::smatch what;
smatch what;
if (regex_match(s, what, bbox_re)) {
// Our callers expect the tokens in the string
// separated by single spaces.

View File

@ -18,9 +18,8 @@
#include "support/lyxlib.h" // float_equal
#include "support/Translator.h"
#include "support/regex.h"
#include <cmath> // abs
#include <regex>
#include <sstream>
using namespace std;
@ -282,8 +281,8 @@ string const sanitizeLatexOption(string const & input)
// Strip any leading commas
// "[,,,,foo..." -> "foo..." ("foo..." may be empty)
string output;
lyx::smatch what;
static lyx::regex const front("^( *\\[,*)(.*)$");
smatch what;
static regex const front("^( *\\[,*)(.*)$");
if (!regex_match(it, end, what, front)) {
lyxerr << "Unable to sanitize LaTeX \"Option\": "
@ -295,7 +294,7 @@ string const sanitizeLatexOption(string const & input)
// Replace any consecutive commas with a single one
// "foo,,,,bar" -> "foo,bar"
// with iterator now pointing to 'b'
static lyx::regex const commas("([^,]*)(,,*)(.*)$");
static regex const commas("([^,]*)(,,*)(.*)$");
for (; it != end;) {
if (!regex_match(it, end, what, commas)) {
output += string(it, end);
@ -307,7 +306,7 @@ string const sanitizeLatexOption(string const & input)
// Strip any trailing commas
// "...foo,,,]" -> "...foo" ("...foo,,," may be empty)
static lyx::regex const back("^(.*[^,])?,*\\] *$");
static regex const back("^(.*[^,])?,*\\] *$");
if (!regex_match(output, what, back)) {
lyxerr << "Unable to sanitize LaTeX \"Option\": "
<< output << '\n';

View File

@ -43,7 +43,6 @@
#include "support/ExceptionMessage.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
#include "support/regex.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/os.h"
@ -52,6 +51,7 @@
#include <limits>
#include <map>
#include <regex>
#include <utility>
#include <iostream>
@ -1188,8 +1188,8 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
string html = to_utf8(bibinfo.getInfo(entry.key(), buffer(), ci));
regex tagRegex("<span class=\"bib-([^\"]*)\">([^<]*)</span>");
smatch match;
auto tagIt = lyx::sregex_iterator(html.cbegin(), html.cend(), tagRegex, regex_constants::match_default);
auto tagEnd = lyx::sregex_iterator();
auto tagIt = sregex_iterator(html.cbegin(), html.cend(), tagRegex, regex_constants::match_default);
auto tagEnd = sregex_iterator();
map<string, string> delayedTags;
// Read all tags from HTML and convert those that have a 1:1 matching.

View File

@ -44,8 +44,7 @@
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "support/regex.h"
#include <regex>
#include <sstream>
using namespace std;

View File

@ -46,10 +46,10 @@
#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;
@ -773,10 +773,10 @@ string escape_for_regex(string s, bool match_latex)
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();
@ -881,9 +881,9 @@ private:
// 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
@ -955,11 +955,11 @@ static size_t identifyLeading(string const & s)
// @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);
@ -2688,13 +2688,13 @@ static int identifyClosing(string & t)
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;
}
@ -2825,10 +2825,10 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
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);
}
}

View File

@ -100,7 +100,6 @@ liblyxsupport_a_SOURCES = \
pmprof.h \
qstring_helpers.cpp \
qstring_helpers.h \
regex.h \
signals.h \
socktools.cpp \
socktools.h \

View File

@ -42,7 +42,6 @@
#include <QDir>
#include "support/lassert.h"
#include "support/regex.h"
#include <fcntl.h>
#ifdef HAVE_MAGIC_H
@ -59,6 +58,7 @@
#include <utility>
#include <fstream>
#include <regex>
#include <sstream>
#include <vector>

View File

@ -19,10 +19,11 @@
#include "support/debug.h"
#include "support/filetools.h"
#include "support/qstring_helpers.h"
#include "support/regex.h"
#include <QDir>
#include <regex>
#if defined(__CYGWIN__)
#include "support/os_cygwin.cpp"
#elif defined(_WIN32)

View File

@ -1,43 +0,0 @@
// -*- C++ -*-
/**
* \file regexp.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Peter Kümmel
*
* Full author contact details are available in file CREDITS.
*/
#ifndef LYX_REGEXP_H
#define LYX_REGEXP_H
#include <regex>
namespace lyx {
using std::regex;
using std::regex_match;
using std::regex_replace;
using std::regex_search;
using std::sregex_iterator;
using std::smatch;
using std::basic_regex;
using std::regex_error;
using std::match_results;
namespace regex_constants
{
using namespace std::regex_constants;
using std::regex_constants::match_flag_type;
} // namespace regex_constants
} // namespace lyx
// Match Begin and End of String when using ECMAScript (default std::regex)
#define REGEX_BOS "^"
#define REGEX_EOS "$"
#endif // LYX_REGEXP_H

View File

@ -1,9 +1,9 @@
#include <config.h>
#include "../support/debug.h"
#include "../support/regex.h"
#include <iostream>
#include <regex>
using namespace lyx;

View File

@ -27,10 +27,9 @@
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/regex.h"
#include <algorithm>
#include <iostream>
#include <regex>
using namespace std;
using namespace lyx::support;