Add option for choosing between std::regex and pcrecpp

This commit is contained in:
Tindy X 2019-12-28 03:05:54 +08:00
parent fe9a4c06ad
commit 2703435815
No known key found for this signature in database
GPG Key ID: C6AD413169968D58
2 changed files with 19 additions and 6 deletions

View File

@ -7,6 +7,8 @@ ENDIF()
SET(CMAKE_CXX_STANDARD 17)
ADD_DEFINITIONS(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result)
OPTION(USING_STD_REGEX "Use std::regex from C++ library instead of PCRECPP" OFF)
IF(MACOS)
ADD_DEFINITIONS(-D_MACOS)
ENDIF()
@ -56,10 +58,14 @@ LINK_DIRECTORIES(${YAML_CPP_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(subconverter ${YAML_CPP_LIBRARY})
FIND_PACKAGE(PCRECPP REQUIRED)
INCLUDE_DIRECTORIES(${PCRECPP_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(subconverter ${PCRECPP_LIBRARIES})
ADD_DEFINITIONS(-DPCRE_STATIC)
IF(USING_STD_REGEX STREQUAL "ON")
ADD_DEFINITIONS(-DUSE_STD_REGEX)
ELSE()
FIND_PACKAGE(PCRECPP REQUIRED)
INCLUDE_DIRECTORIES(${PCRECPP_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(subconverter ${PCRECPP_LIBRARIES})
ADD_DEFINITIONS(-DPCRE_STATIC)
ENDIF()
IF(WIN32)
TARGET_LINK_LIBRARIES(subconverter wsock32 ws2_32)

View File

@ -7,7 +7,12 @@
//#include <filesystem>
#include <unistd.h>
#ifdef USE_STD_REGEX
#include <regex>
#else
#include <pcrecpp.h>
#endif // USE_STD_REGEX
#include <rapidjson/document.h>
#include <openssl/md5.h>
@ -447,7 +452,7 @@ std::string replace_all_distinct(std::string str, std::string old_value, std::st
return str;
}
/*
#ifdef USE_STD_REGEX
bool regValid(std::string &reg)
{
try
@ -501,7 +506,8 @@ bool regMatch(std::string src, std::string match)
return false;
}
}
*/
#else
bool regValid(std::string &reg)
{
@ -560,6 +566,7 @@ bool regMatch(std::string src, std::string match)
return false;
}
}
#endif // USE_STD_REGEX
std::string speedCalc(double speed)
{