Switch to std::regex by default

This commit is contained in:
Ilari Liusvaara 2015-02-07 15:32:34 +02:00
parent 54cbe456b4
commit 44aa95cc57
5 changed files with 40 additions and 17 deletions

View file

@ -20,7 +20,8 @@ ifdef HOST_BOOST_NEEDS_MT
HOST_BOOST_POSTFIX=-mt
endif
LDFLAGS = -pthread -lboost_iostreams$(BOOST_LIB_POSTFIX) -lboost_filesystem$(BOOST_LIB_POSTFIX) -lboost_system$(BOOST_LIB_POSTFIX) -lboost_regex$(BOOST_LIB_POSTFIX) -lz $(USER_LDFLAGS)
LDFLAGS = -pthread -lboost_iostreams$(BOOST_LIB_POSTFIX) -lboost_filesystem$(BOOST_LIB_POSTFIX) -lboost_system$(BOOST_LIB_POSTFIX) -lz $(USER_LDFLAGS)
HOSTHELPER_LDFLAGS =
ifeq ($(THREADS), NATIVE)
CFLAGS += -DNATIVE_THREADS
@ -33,6 +34,14 @@ $(error "Bad value for THREADS (expected NATIVE or BOOST)")
endif
endif
ifeq ($(REGEX), BOOST)
CFLAGS += -DUSE_BOOST_REGEX
LDFLAGS += -lboost_regex$(BOOST_LIB_POSTFIX)
HOSTHELPER_LDFLAGS += -lboost_regex$(HOST_BOOST_POSTFIX)
endif
HOSTHELPER_LDFLAGS += -lboost_system$(HOST_BOOST_POSTFIX)
ifdef NEED_LIBICONV
LDFLAGS += -liconv
endif

View file

@ -66,6 +66,12 @@ FONT_SRC=unifontfull-5.1.20080820.hex
# - Default value is 'lua'.
LUA=lua
# Regex package to use.
# Currently supported:
# - NATIVE: std::thread
# - BOOST: boost_thread
REGEX=NATIVE
# Threading package to use.
# Currently supported:
# - NATIVE: std::thread

View file

@ -10,10 +10,10 @@ __all__.files: $(JSON_OBJECTS) inverselist.$(OBJECT_SUFFIX)
touch $(ALLFLAGS)
mkstubs$(DOT_EXECUTABLE_SUFFIX): mkstubs.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall
mkstubsi$(DOT_EXECUTABLE_SUFFIX): mkstubsi.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall
inverselist.cpp: $(JSON_FILES) mkstubsi$(DOT_EXECUTABLE_SUFFIX)
./mkstubsi$(DOT_EXECUTABLE_SUFFIX) $^

View file

@ -9,7 +9,7 @@ __all__.files: $(CORES_FILES)
cat $(CORES_FLAGS) >$(ALLFLAGS)
make-ports$(DOT_EXECUTABLE_SUFFIX): make-ports.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/portctrl-parse.cpp ../library/portctrl-data.cpp ../library/sha256.cpp ../library/assembler.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp ../library/binarystream.cpp ../library/integer-pool.cpp
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall -DNO_ASM_GENERATION
$(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall -DNO_ASM_GENERATION
bsnes-legacy/$(ALLFILES): forcelook make-ports$(DOT_EXECUTABLE_SUFFIX)
$(MAKE) -C bsnes-legacy

View file

@ -3,9 +3,17 @@
#include "threads.hpp"
#include "eatarg.hpp"
#include <cctype>
#include <boost/regex.hpp>
#include "map-pointer.hpp"
#ifdef USE_BOOST_REGEX
#include <boost/regex.hpp>
namespace regex_ns = boost;
#else
#include <regex>
namespace regex_ns = std;
#endif
std::string strip_CR(const std::string& str)
{
std::string x = str;
@ -88,11 +96,11 @@ regex_results regex(const std::string& regexp, const std::string& str, const cha
{
static threads::lock m;
threads::alock h(m);
static std::map<std::string, map_pointer<boost::regex>> regexps;
static std::map<std::string, map_pointer<regex_ns::regex>> regexps;
if(!regexps.count(regexp)) {
boost::regex* y = NULL;
regex_ns::regex* y = NULL;
try {
y = new boost::regex(regexp, boost::regex::extended & ~boost::regex::collate);
y = new regex_ns::regex(regexp, regex_ns::regex::extended & ~regex_ns::regex::collate);
regexps[regexp] = y;
} catch(std::bad_alloc& e) {
delete y;
@ -102,8 +110,8 @@ regex_results regex(const std::string& regexp, const std::string& str, const cha
}
}
boost::smatch matches;
bool x = boost::regex_match(str.begin(), str.end(), matches, *(regexps[regexp]));
regex_ns::smatch matches;
bool x = regex_ns::regex_match(str.begin(), str.end(), matches, *(regexps[regexp]));
if(x) {
std::vector<std::string> res;
std::vector<std::pair<size_t, size_t>> mch;
@ -123,7 +131,7 @@ bool regex_match(const std::string& regexp, const std::string& str, enum regex_m
throw(std::bad_alloc, std::runtime_error)
{
static threads::lock m;
static std::map<std::string, map_pointer<boost::regex>> regexps;
static std::map<std::string, map_pointer<regex_ns::regex>> regexps;
static std::map<std::pair<regex_match_mode, std::string> , std::pair<std::string, bool>> transform_cache;
std::string _regexp;
bool icase = false;
@ -176,12 +184,12 @@ transformed:
transform_cache[key] = std::make_pair(_regexp, icase);
if(!regexps.count(regexp)) {
boost::regex* y = NULL;
auto flags = boost::regex::extended & ~boost::regex::collate;
flags |= boost::regex::nosubs;
if(icase) flags |= boost::regex::icase;
regex_ns::regex* y = NULL;
auto flags = regex_ns::regex::extended & ~regex_ns::regex::collate;
flags |= regex_ns::regex::nosubs;
if(icase) flags |= regex_ns::regex::icase;
try {
y = new boost::regex(_regexp, flags);
y = new regex_ns::regex(_regexp, flags);
regexps[_regexp] = y;
} catch(std::bad_alloc& e) {
delete y;
@ -190,7 +198,7 @@ transformed:
throw std::runtime_error(e.what());
}
}
return boost::regex_match(str.begin(), str.end(), *(regexps[_regexp]));
return regex_ns::regex_match(str.begin(), str.end(), *(regexps[_regexp]));
}
namespace