[LyX/master] Always use std::regex

Yuriy Skalko yuriy.skalko at gmail.com
Fri Nov 27 10:10:20 UTC 2020


commit f3ec89cfa15feae8aa3185413eda55f28cc6551e
Author: Yuriy Skalko <yuriy.skalko at gmail.com>
Date:   Sat Nov 21 20:11:23 2020 +0200

    Always use std::regex
    
    Since now minimum supported GCC is 4.9.
---
 3rdparty/Makefile.am               |    3 --
 3rdparty/boost/libs/CMakeLists.txt |    8 +-----
 CMakeLists.txt                     |   52 ++++-------------------------------
 config/lyxinclude.m4               |   41 ----------------------------
 development/cmake/config.h.cmake   |    2 -
 src/frontends/qt/GuiCitation.cpp   |    9 ------
 src/frontends/tests/biblio.cpp     |    8 -----
 src/support/regex.h                |   45 +++++++++++--------------------
 8 files changed, 23 insertions(+), 145 deletions(-)

diff --git a/3rdparty/Makefile.am b/3rdparty/Makefile.am
index e21e1cb..ec12adb 100644
--- a/3rdparty/Makefile.am
+++ b/3rdparty/Makefile.am
@@ -3,11 +3,8 @@ include $(top_srcdir)/config/common.am
 DIST_SUBDIRS = boost dtl hunspell mythes libiconv zlib
 
 if USE_INCLUDED_BOOST
-if LYX_USE_STD_REGEX
-else
 BOOST = boost
 endif
-endif
 
 if USE_INCLUDED_HUNSPELL
 HUNSPELL = hunspell
diff --git a/3rdparty/boost/libs/CMakeLists.txt b/3rdparty/boost/libs/CMakeLists.txt
index d2fdd7f..84da81e 100644
--- a/3rdparty/boost/libs/CMakeLists.txt
+++ b/3rdparty/boost/libs/CMakeLists.txt
@@ -6,10 +6,4 @@
 
 project(boost)
 
-
-if(LYX_USE_STD_REGEX)
-	message(STATUS "Using std regex")
-else()
-	add_subdirectory(regex) 
-endif()
-
+message(STATUS "Using std regex")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b35f2f5..02a1b30 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -380,13 +380,7 @@ unset(LYX_GCC11_MODE)
 if(UNIX OR MINGW)
 	if (CMAKE_CXX_COMPILER_ID MATCHES "^([cC]lang|AppleClang)$")
 	  # ignore the GCC_VERSION for clang
-	  # and use the resulting CXX11_STD_REGEX found in FindCXX11Compiler.cmake
 	  message(STATUS "Using clang")
-	  if(CXX11_STD_REGEX)
-	    set(LYX_USE_STD_REGEX 1)
-	  else()
-	    set(LYX_USE_STD_REGEX 0)
-	  endif()
 	else()
 	  execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpfullversion OUTPUT_VARIABLE GCC_VERSION ERROR_VARIABLE _error RESULT_VARIABLE _err OUTPUT_STRIP_TRAILING_WHITESPACE)
 	  #message(STATUS "dumpfullversion: error = ${_error}, result = ${_err}")
@@ -399,7 +393,6 @@ if(UNIX OR MINGW)
 	  if(GCC_VERSION VERSION_LESS 4.9)
 		message(FATAL_ERROR "gcc >= 4.9 is required.")
 	  endif()
-	  set(LYX_USE_STD_REGEX 1)
 	endif()
 	set(LYX_GCC11_MODE "${CXX11_FLAG}")
 else()
@@ -407,7 +400,6 @@ else()
 		# Drop support for msvc versions prior to 1900 (Visual Studio 2015)
 		message(FATAL_ERROR "Visual Studio >= 2015 is required.")
 	endif()
-	set(LYX_USE_STD_REGEX 1)
 endif()
 
 if(LYX_3RDPARTY_BUILD)
@@ -941,40 +933,12 @@ if(NOT LYX_EXTERNAL_DTL)
   add_subdirectory(3rdparty/dtl)
 endif()
 
-if(LYX_USE_STD_REGEX)
-  # Set only include path.
-  # Use internal boost, which is known to exist
-  # we don't need any libraries
-  set(Lyx_Boost_Libraries)
-  add_definitions(-DBOOST_USER_CONFIG=<config.h>)
-  include_directories(${TOP_SRC_DIR}/3rdparty/boost)
-else()
-  # Using boost-regex
-  if(LYX_EXTERNAL_BOOST)
-    message(STATUS "Searching for external boost")
-    find_package(Boost COMPONENTS regex)
-    if(Boost_FOUND)
-      message(STATUS "Boost found")
-      message(STATUS "Boost-libs = ${Boost_LIBRARIES}")
-      set(Lyx_Boost_Libraries ${Boost_LIBRARIES})
-      if (LYX_STDLIB_DEBUG OR LYX_DEBUG_GLIBC OR LYX_DEBUG_GLIBC_PEDANTIC)
-	# Comment from 	Jean-Marc Lasgouttes:
-	# In general, system boost libraries are incompatible with
-	# the use of stdlib-debug in libstdc++. See ticket #9736 for
-	# details.
-	message(FATAL_ERROR "Compiling LyX with stdlib-debug and system boost libraries may lead to crashes. Consider using '-DLYX_STDLIB_DEBUG=OFF -DLYX_DEBUG_GLIBC=OFF -DLYX_DEBUG_GLIBC_PEDANTIC=OFF' or using '-DLYX_EXTERNAL_BOOST=OFF'")
-      endif()
-    else()
-      message(FATAL_ERROR "Boost not found" ${Boost_ERROR_REASON})
-    endif()
-  else()
-    # Using included boost
-    set(Lyx_Boost_Libraries boost_regex)
-    add_definitions(-DBOOST_USER_CONFIG=<config.h>)
-    include_directories(${TOP_SRC_DIR}/3rdparty/boost)
-    add_subdirectory(3rdparty/boost "${TOP_BINARY_DIR}/3rdparty/boost")
-  endif()
-endif()
+# Set only include path.
+# Use internal boost, which is known to exist
+# we don't need any libraries
+set(Lyx_Boost_Libraries)
+add_definitions(-DBOOST_USER_CONFIG=<config.h>)
+include_directories(${TOP_SRC_DIR}/3rdparty/boost)
 
 if(WIN32)
 	if(LYX_CONSOLE)
@@ -1175,10 +1139,6 @@ if(QTVERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*")
 	MATH(EXPR QT4_VERSION "(${CMAKE_MATCH_1}<<16)|(${CMAKE_MATCH_2}<<8)|${CMAKE_MATCH_3}")
 endif()
 
-if (NOT HAVE_REGEX)
-	set(LYX_USE_STD_REGEX 0)
-endif()
-
 
 set (cmd ${CMAKE_CTEST_COMMAND})
 if (MSVC)
diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4
index 268c501..46b5617 100644
--- a/config/lyxinclude.m4
+++ b/config/lyxinclude.m4
@@ -213,46 +213,6 @@ AC_DEFUN([LYX_CXX_CXX11_FLAGS],
 ])
 
 
-dnl Usage: LYX_CXX_USE_REGEX
-dnl decide whether we want to use std::regex and set the
-dnl LYX_USE_STD_REGEX macro and conditional accordingly.
-AC_DEFUN([LYX_CXX_USE_REGEX],
-[AC_ARG_ENABLE(std-regex,
-  AS_HELP_STRING([--enable-std-regex],[use std::regex instead of boost::regex (default is autodetected)]),
-  [lyx_std_regex=$enableval],
-  [AC_MSG_CHECKING([for correct regex implementation])
-   save_CPPFLAGS=$CPPFLAGS
-   CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
-   save_CXXFLAGS=$CXXFLAGS
-   CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS"
-   # The following code snippet has been taken taken from example in
-   #   http://stackoverflow.com/questions/8561850/compile-stdregex-iterator-with-gcc
-   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
-	#include <regex>
-	#include <iostream>
-
-	#include <string.h>
-
-	typedef std::regex_iterator<const char *> Myiter;
-     ]], [[
-	const char *pat = "axayaz";
-	Myiter::regex_type rx("a");
-	Myiter next(pat, pat + strlen(pat), rx);
-	Myiter end;
-   ]])],[lyx_std_regex=yes],[lyx_std_regex=no])
-   CXXFLAGS=$save_CXXFLAGS
-   CPPFLAGS=$save_CPPFLAGS
-   AC_MSG_RESULT([$lyx_std_regex])
- ])
-
- if test $lyx_std_regex = yes ; then
-  lyx_flags="$lyx_flags std-regex"
-  AC_DEFINE([LYX_USE_STD_REGEX], 1, [define to 1 if std::regex should be preferred to boost::regex])
- fi
- AM_CONDITIONAL([LYX_USE_STD_REGEX], test $lyx_std_regex = yes)
-])
-
-
 dnl Usage: LYX_CXX_USE_CALL_ONCE
 dnl check whether we can use std::call_once and set the
 dnl LYX_USE_STD_CALL_ONCE macro and conditional accordingly.
@@ -319,7 +279,6 @@ LYX_PROG_CLANG
 LYX_CXX_CXX11_FLAGS($enable_cxx_mode)
 LYX_LIB_STDCXX
 LYX_LIB_STDCXX_CXX11_ABI
-LYX_CXX_USE_REGEX
 LYX_CXX_USE_CALL_ONCE
 AC_LANG_POP(C++)
 
diff --git a/development/cmake/config.h.cmake b/development/cmake/config.h.cmake
index 3512416..15bceaa 100644
--- a/development/cmake/config.h.cmake
+++ b/development/cmake/config.h.cmake
@@ -50,8 +50,6 @@
 
 #cmakedefine LYX_MERGE_FILES 1
 
-#cmakedefine LYX_USE_STD_REGEX 1
-
 // Define if callstack can be printed
 #cmakedefine LYX_CALLSTACK_PRINTING 1
 
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index c66a6d3..7a402ed 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -991,19 +991,10 @@ static docstring escape_special_chars(docstring const & expr)
 
 	// $& is an ECMAScript format expression that expands to all
 	// of the current match
-#ifdef LYX_USE_STD_REGEX
 	// 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("\\$&")));
-#else
-	// A backslash in the format string starts an escape sequence in boost.
-	// Thus, to prefix a matched expression with a single literal backslash,
-	// we need to give two backslashes to the regex engine, and escape both
-	// for the C++ compiler and use:
-	// FIXME: UNICODE
-	return from_utf8(lyx::regex_replace(to_utf8(expr), reg, string("\\\\$&")));
-#endif
 }
 
 
diff --git a/src/frontends/tests/biblio.cpp b/src/frontends/tests/biblio.cpp
index 97ae4a9..3696598 100644
--- a/src/frontends/tests/biblio.cpp
+++ b/src/frontends/tests/biblio.cpp
@@ -20,17 +20,9 @@ string const escape_special_chars(string const & expr)
 
 	// $& is a ECMAScript format expression that expands to all
 	// of the current match
-#ifdef LYX_USE_STD_REGEX
 	// 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, "\\$&");
-#else
-	// A backslash in the format string starts an escape sequence in boost.
-	// Thus, to prefix a matched expression with a single literal backslash,
-	// we need to give two backslashes to the regex engine, and escape both
-	// for the C++ compiler and use:
-	return lyx::regex_replace(expr, reg, "\\\\$&");
-#endif
 }
 
 
diff --git a/src/support/regex.h b/src/support/regex.h
index 9649870..491044c 100644
--- a/src/support/regex.h
+++ b/src/support/regex.h
@@ -12,45 +12,32 @@
 #ifndef LYX_REGEXP_H
 #define LYX_REGEXP_H
 
-#ifdef LYX_USE_STD_REGEX
-#  include <regex>
-// <regex> in gcc is unusable in versions less than 4.9.0
-// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
-#  define LR_NS std
-#else
-#  include <boost/regex.hpp>
-#  define LR_NS boost
-#endif
+#include <regex>
 
 namespace lyx {
-using LR_NS::regex;
-using LR_NS::regex_match;
-using LR_NS::regex_replace;
-using LR_NS::regex_search;
-using LR_NS::sregex_iterator;
-using LR_NS::smatch;
-using LR_NS::basic_regex;
-using LR_NS::regex_error;
-using LR_NS::match_results;
+
+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 LR_NS::regex_constants;
-using LR_NS::regex_constants::match_flag_type;
+
+using namespace std::regex_constants;
+using std::regex_constants::match_flag_type;
+
 } // namespace regex_constants
 
 } // namespace lyx
 
-#undef LR_NS
-
-#ifdef LYX_USE_STD_REGEX
 // Match Begin and End of String when using ECMAScript (default std::regex)
 #define REGEX_BOS "^"
 #define REGEX_EOS "$"
-#else
-// Match Begin and End of String when using Perl RE (default boost::regex)
-#define REGEX_BOS "\\`"
-#define REGEX_EOS "\\'"
-#endif
 
-#endif
+#endif // LYX_REGEXP_H


More information about the lyx-cvs mailing list