diff --git a/development/cmake/CMakeLists.txt b/development/cmake/CMakeLists.txt index 1fdc20f6b3..2237d4856d 100644 --- a/development/cmake/CMakeLists.txt +++ b/development/cmake/CMakeLists.txt @@ -479,7 +479,7 @@ if(UseExternalBoost) endif() else() message(STATUS "----- Using internal boost. To build with installed version use -DUseExternalBoost:BOOL=ON") - set(Lyx_Boost_Libraries boost_signals boost_regex) + set(Lyx_Boost_Libraries boost_signals ${BOOST_REGEX_LIB}) add_definitions(-DBOOST_USER_CONFIG="") include_directories(${TOP_SRC_DIR}/boost) add_subdirectory(boost) diff --git a/development/cmake/boost/libs/CMakeLists.txt b/development/cmake/boost/libs/CMakeLists.txt index 508947a615..8430db812c 100644 --- a/development/cmake/boost/libs/CMakeLists.txt +++ b/development/cmake/boost/libs/CMakeLists.txt @@ -6,6 +6,11 @@ project(boost) -add_subdirectory(regex) +if(MSVC10) + message(STATUS "Using TR1 regex") +else() + add_subdirectory(regex) +endif() + add_subdirectory(signals) diff --git a/development/cmake/boost/libs/regex/CMakeLists.txt b/development/cmake/boost/libs/regex/CMakeLists.txt index 0f65b40f81..efd427f3e7 100644 --- a/development/cmake/boost/libs/regex/CMakeLists.txt +++ b/development/cmake/boost/libs/regex/CMakeLists.txt @@ -21,3 +21,5 @@ lyx_add_path(boost_regex_sources ${TOP_SRC_DIR}/boost/libs/regex/src) add_library(boost_regex STATIC ${boost_regex_sources}) +set(BOOST_REGEX_LIB boost_regex CACHE STRING "Boost regex lib" FORCE) + diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index b88546e7f1..9d10b3359a 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -36,7 +36,7 @@ #include "support/lstrings.h" #include "support/textutils.h" -#include "boost/regex.hpp" +#include "support/regex.h" #include @@ -175,8 +175,8 @@ docstring convertLaTeXCommands(docstring const & str) // unicodesymbols has things in the form: \"{u}, // whereas we may see things like: \"u. So we'll // look for that and change it, if necessary. - static boost::regex const reg("^\\\\\\W\\w"); - if (boost::regex_search(to_utf8(val), reg)) { + static lyx::regex const reg("^\\\\\\W\\w"); + if (lyx::regex_search(to_utf8(val), reg)) { val.insert(3, from_ascii("}")); val.insert(2, from_ascii("{")); } diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp index f4d98155aa..3d70bc14cb 100644 --- a/src/LaTeX.cpp +++ b/src/LaTeX.cpp @@ -29,12 +29,10 @@ #include "support/Systemcall.h" #include "support/os.h" -#include +#include "support/regex.h" #include -using boost::regex; -using boost::smatch; using namespace std; using namespace lyx::support; @@ -952,7 +950,7 @@ void LaTeX::deplog(DepTable & head) string lastline; while (ifs) { // Ok, the scanning of files here is not sufficient. - // Sometimes files are named by "File: xxx" only + // Sometimes files are named by "File: xxx" only // So I think we should use some regexps to find files instead. // Note: all file names and paths might contains spaces. bool found_file = false; diff --git a/src/Layout.cpp b/src/Layout.cpp index 6dfc0f5dcf..e556fad0f0 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -23,7 +23,7 @@ #include "support/lassert.h" #include "support/lstrings.h" -#include +#include "support/regex.h" using namespace std; using namespace lyx::support; @@ -873,11 +873,11 @@ docstring const i18npreamble(Language const * lang, docstring const & templ) LASSERT(false, /**/); #else // FIXME UNICODE - // boost::regex is not unicode-safe. + // lyx::regex is not unicode-safe. // Should use QRegExp or (boost::u32regex, but that requires ICU) - static boost::regex const reg("_\\(([^\\)]+)\\)"); - boost::smatch sub; - while (boost::regex_search(preamble, sub, reg)) { + static regex const reg("_\\(([^\\)]+)\\)"); + smatch sub; + while (regex_search(preamble, sub, reg)) { string const key = sub.str(1); string translated; if (isAscii(key)) diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp index 8891969faa..6f80c95796 100644 --- a/src/LayoutFile.cpp +++ b/src/LayoutFile.cpp @@ -28,7 +28,7 @@ #include "support/lstrings.h" #include "support/bind.h" -#include +#include "support/regex.h" #include @@ -38,8 +38,6 @@ using namespace lyx::support; namespace lyx { -using boost::regex; -using boost::smatch; LayoutFile::LayoutFile(string const & fn, string const & cln, string const & desc, string const & prereq, diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp index 10caca5930..390b3ce4e5 100644 --- a/src/VCBackend.cpp +++ b/src/VCBackend.cpp @@ -26,17 +26,14 @@ #include "support/lstrings.h" #include "support/Path.h" #include "support/Systemcall.h" - -#include +#include "support/regex.h" #include using namespace std; using namespace lyx::support; -using boost::regex; -using boost::regex_match; -using boost::smatch; + namespace lyx { diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 4f16ad4998..9afec260fa 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -41,7 +41,7 @@ #undef KeyPress -#include +#include "support/regex.h" #include #include @@ -673,9 +673,9 @@ static docstring escape_special_chars(docstring const & expr) { // Search for all chars '.|*?+(){}[^$]\' // Note that '[' and '\' must be escaped. - // This is a limitation of boost::regex, but all other chars in BREs + // This is a limitation of lyx::regex, but all other chars in BREs // are assumed literal. - static const boost::regex reg("[].|*?+(){}^$\\[\\\\]"); + static const lyx::regex reg("[].|*?+(){}^$\\[\\\\]"); // $& is a perl-like expression that expands to all // of the current match @@ -683,7 +683,7 @@ static docstring escape_special_chars(docstring const & expr) // boost to treat it as a literal. // Thus, to prefix a matched expression with '\', we use: // FIXME: UNICODE - return from_utf8(boost::regex_replace(to_utf8(expr), reg, "\\\\$&")); + return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&"))); } @@ -700,15 +700,15 @@ vector GuiCitation::searchKeys(BiblioInfo const & bi, if (!regex) // We must escape special chars in the search_expr so that - // it is treated as a simple string by boost::regex. + // it is treated as a simple string by lyx::regex. expr = escape_special_chars(expr); - boost::regex reg_exp; + lyx::regex reg_exp; try { reg_exp.assign(to_utf8(expr), case_sensitive ? - boost::regex_constants::normal : boost::regex_constants::icase); - } catch (boost::regex_error & e) { - // boost::regex throws an exception if the regular expression is not + lyx::regex_constants::ECMAScript : lyx::regex_constants::icase); + } catch (lyx::regex_error & e) { + // lyx::regex throws an exception if the regular expression is not // valid. LYXERR(Debug::GUI, e.what()); return vector(); @@ -734,10 +734,10 @@ vector GuiCitation::searchKeys(BiblioInfo const & bi, continue; try { - if (boost::regex_search(data, reg_exp)) + if (lyx::regex_search(data, reg_exp)) foundKeys.push_back(*it); } - catch (boost::regex_error & e) { + catch (lyx::regex_error & e) { LYXERR(Debug::GUI, e.what()); return vector(); } diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index b3a2a55122..7f4c5d8fda 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -50,7 +50,7 @@ // for FileFilter. // FIXME: Remove -#include +#include "support/regex.h" #include @@ -338,17 +338,17 @@ static string const convert_brace_glob(string const & glob) { // Matches " *.{abc,def,ghi}", storing "*." as group 1 and // "abc,def,ghi" as group 2. - static boost::regex const glob_re(" *([^ {]*)\\{([^ }]+)\\}"); + static lyx::regex const glob_re(" *([^ {]*)\\{([^ }]+)\\}"); // Matches "abc" and "abc,", storing "abc" as group 1. - static boost::regex const block_re("([^,}]+),?"); + static lyx::regex const block_re("([^,}]+),?"); string pattern; string::const_iterator it = glob.begin(); string::const_iterator const end = glob.end(); while (true) { - boost::match_results what; - if (!boost::regex_search(it, end, what, glob_re)) { + match_results what; + if (!regex_search(it, end, what, glob_re)) { // Ensure that no information is lost. pattern += string(it, end); break; @@ -365,7 +365,7 @@ static string const convert_brace_glob(string const & glob) // Split the ','-separated chunks of tail so that // $head{$chunk1,$chunk2} becomes "$head$chunk1 $head$chunk2". string const fmt = " " + head + "$1"; - pattern += boost::regex_merge(tail, block_re, fmt); + pattern += regex_replace(tail, block_re, fmt); // Increment the iterator to the end of the match. it += distance(it, what[0].second); @@ -474,14 +474,14 @@ FileFilterList::FileFilterList(docstring const & qt_style_filter) // Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)" // into individual filters. - static boost::regex const separator_re(";;"); + static lyx::regex const separator_re(";;"); string::const_iterator it = filter.begin(); string::const_iterator const end = filter.end(); while (true) { - boost::match_results what; + match_results what; - if (!boost::regex_search(it, end, what, separator_re)) { + if (!lyx::regex_search(it, end, what, separator_re)) { parse_filter(string(it, end)); break; } @@ -500,10 +500,10 @@ void FileFilterList::parse_filter(string const & filter) { // Matches "TeX documents (*.tex)", // storing "TeX documents " as group 1 and "*.tex" as group 2. - static boost::regex const filter_re("([^(]*)\\(([^)]+)\\) *$"); + static lyx::regex const filter_re("([^(]*)\\(([^)]+)\\) *$"); - boost::match_results what; - if (!boost::regex_search(filter, what, filter_re)) { + match_results what; + if (!lyx::regex_search(filter, what, filter_re)) { // Just a glob, no description. filters_.push_back(Filter(docstring(), trim(filter))); } else { diff --git a/src/insets/ExternalTransforms.cpp b/src/insets/ExternalTransforms.cpp index 270a7c83b0..8a29f38961 100644 --- a/src/insets/ExternalTransforms.cpp +++ b/src/insets/ExternalTransforms.cpp @@ -18,7 +18,7 @@ #include "support/lyxlib.h" // float_equal #include "support/Translator.h" -#include +#include "support/regex.h" #include // abs #include @@ -279,10 +279,10 @@ string const sanitizeLatexOption(string const & input) // Strip any leading commas // "[,,,,foo..." -> "foo..." ("foo..." may be empty) string output; - boost::smatch what; - static boost::regex const front("^( *[[],*)(.*)$"); + lyx::smatch what; + static lyx::regex const front("^( *[[],*)(.*)$"); - regex_match(it, end, what, front, boost::match_partial); + regex_match(it, end, what, front, regex_constants::match_partial); if (!what[0].matched) { lyxerr << "Unable to sanitize LaTeX \"Option\": " << input << '\n'; @@ -293,9 +293,9 @@ 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 boost::regex const commas("([^,]*)(,,*)(.*)$"); + static lyx::regex const commas("([^,]*)(,,*)(.*)$"); for (; it != end;) { - regex_match(it, end, what, commas, boost::match_partial); + regex_match(it, end, what, commas, regex_constants::match_partial); if (!what[0].matched) { output += string(it, end); break; @@ -306,7 +306,7 @@ string const sanitizeLatexOption(string const & input) // Strip any trailing commas // "...foo,,,]" -> "...foo" ("...foo,,," may be empty) - static boost::regex const back("^(.*[^,])?,*[]] *$"); + static lyx::regex const back("^(.*[^,])?,*[]] *$"); regex_match(output, what, back); if (!what[0].matched) { lyxerr << "Unable to sanitize LaTeX \"Option\": " diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index bbd2b53aeb..2bb843d104 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -38,7 +38,7 @@ #include "frontends/alert.h" #include "frontends/Application.h" -#include +#include "support/regex.h" #include @@ -47,7 +47,6 @@ using namespace lyx::support; namespace lyx { -using boost::regex; char const lstinline_delimiters[] = "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 82c8728656..d713cd1dc3 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -47,7 +47,7 @@ #include "support/lassert.h" #include "support/lstrings.h" -#include +#include "support/regex.h" #include using namespace std; @@ -559,14 +559,14 @@ string escape_for_regex(string s) return s; } -/// Wrapper for boost::regex_replace with simpler interface +/// Wrapper for lyx::regex_replace with simpler interface bool regex_replace(string const & s, string & t, string const & searchstr, string const & replacestr) { - boost::regex e(searchstr); + lyx::regex e(searchstr); ostringstream oss; ostream_iterator it(oss); - boost::regex_replace(it, s.begin(), s.end(), e, replacestr); + lyx::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(); @@ -661,9 +661,9 @@ private: // normalized string to search string par_as_string; // regular expression to use for searching - boost::regex regexp; + lyx::regex regexp; // same as regexp, but prefixed with a ".*" - boost::regex regexp2; + lyx::regex regexp2; // unmatched open braces in the search string/regexp int open_braces; // number of (.*?) subexpressions added at end of search regexp for closing @@ -722,9 +722,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & LYXERR(Debug::FIND, "Close .*? : " << close_wildcards); LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string); // If entered regexp must match at begin of searched string buffer - regexp = boost::regex(string("\\`") + par_as_string); + regexp = lyx::regex(string("\\`") + par_as_string); // If entered regexp may match wherever in searched string buffer - regexp2 = boost::regex(string("\\`.*") + par_as_string); + regexp2 = lyx::regex(string("\\`.*") + par_as_string); } } @@ -747,11 +747,11 @@ int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) con } else { // Try all possible regexp matches, //until one that verifies the braces match test is found - boost::regex const *p_regexp = at_begin ? ®exp : ®exp2; - boost::sregex_iterator re_it(str.begin(), str.end(), *p_regexp); - boost::sregex_iterator re_it_end; + regex const *p_regexp = at_begin ? ®exp : ®exp2; + sregex_iterator re_it(str.begin(), str.end(), *p_regexp); + sregex_iterator re_it_end; for (; re_it != re_it_end; ++re_it) { - boost::match_results const & m = *re_it; + match_results const & m = *re_it; // Check braces on the segment that matched the entire regexp expression, // plus the last subexpression, if a (.*?) was inserted in the constructor. if (! braces_match(m[0].first, m[0].second, open_braces)) @@ -1222,7 +1222,7 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt) else match_len = findBackwardsAdv(cur, matchAdv); } catch (...) { - // This may only be raised by boost::regex() + // This may only be raised by lyx::regex() bv->message(_("Invalid regular expression!")); return false; } diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index db65c6a710..b0b9d169a0 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -36,7 +36,7 @@ #include #include "support/lassert.h" -#include +#include "support/regex.h" #include @@ -537,9 +537,9 @@ string const replaceEnvironmentPath(string const & path) // $\{[A-Za-z_][A-Za-z_0-9]*\} static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)"; - static boost::regex envvar_br_re("(.*)" + envvar_br + "(.*)"); - static boost::regex envvar_re("(.*)" + envvar + "(.*)"); - boost::smatch what; + static regex envvar_br_re("(.*)" + envvar_br + "(.*)"); + static regex envvar_re("(.*)" + envvar + "(.*)"); + smatch what; string result; string remaining = path; while (1) { @@ -921,13 +921,13 @@ string const readBB_from_PSFile(FileName const & file) return string(); } - static boost::regex bbox_re( + static lyx::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); - boost::smatch what; + lyx::smatch what; if (regex_match(s, what, bbox_re)) { // Our callers expect the tokens in the string // separated by single spaces. diff --git a/src/support/regex.h b/src/support/regex.h new file mode 100644 index 0000000000..0826c9724c --- /dev/null +++ b/src/support/regex.h @@ -0,0 +1,63 @@ +// -*- 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 "checktr1.h" + + +#define LYX_REGEX_TO_LYX(X) \ + using X::regex; \ + using X::smatch; \ + using X::regex_replace; \ + using X::basic_regex; \ + using X::regex_error; \ + using X::regex_search; \ + using X::sregex_iterator; \ + using X::match_results; \ + \ + namespace regex_constants \ + { \ + using namespace X::regex_constants; \ + using X::regex_constants::match_flag_type; \ + } \ + + + +// TODO: only tested with msvc10 +#if defined(LYX_USE_TR1) && defined(_MSC_VER) + +#ifdef _MSC_VER +#include +#define match_partial _Match_partial // why is match_partial not public? +#else +#include +#endif + +namespace lyx +{ + LYX_REGEX_TO_LYX(std::tr1); +} + +#else + +#include "boost/regex.hpp" + +namespace lyx +{ + LYX_REGEX_TO_LYX(boost); +} + +#endif + + +#endif diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index bd495abc36..aabba0009c 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -25,7 +25,7 @@ #include "support/filetools.h" #include "support/lstrings.h" -#include +#include "support/regex.h" #include #include @@ -36,8 +36,7 @@ using namespace std; using namespace lyx::support; -using boost::regex; -using boost::smatch; + namespace lyx {