Switch to std::regex by default
This commit is contained in:
parent
54cbe456b4
commit
44aa95cc57
5 changed files with 40 additions and 17 deletions
11
Makefile
11
Makefile
|
@ -20,7 +20,8 @@ ifdef HOST_BOOST_NEEDS_MT
|
||||||
HOST_BOOST_POSTFIX=-mt
|
HOST_BOOST_POSTFIX=-mt
|
||||||
endif
|
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)
|
ifeq ($(THREADS), NATIVE)
|
||||||
CFLAGS += -DNATIVE_THREADS
|
CFLAGS += -DNATIVE_THREADS
|
||||||
|
@ -33,6 +34,14 @@ $(error "Bad value for THREADS (expected NATIVE or BOOST)")
|
||||||
endif
|
endif
|
||||||
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
|
ifdef NEED_LIBICONV
|
||||||
LDFLAGS += -liconv
|
LDFLAGS += -liconv
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -66,6 +66,12 @@ FONT_SRC=unifontfull-5.1.20080820.hex
|
||||||
# - Default value is 'lua'.
|
# - Default value is 'lua'.
|
||||||
LUA=lua
|
LUA=lua
|
||||||
|
|
||||||
|
# Regex package to use.
|
||||||
|
# Currently supported:
|
||||||
|
# - NATIVE: std::thread
|
||||||
|
# - BOOST: boost_thread
|
||||||
|
REGEX=NATIVE
|
||||||
|
|
||||||
# Threading package to use.
|
# Threading package to use.
|
||||||
# Currently supported:
|
# Currently supported:
|
||||||
# - NATIVE: std::thread
|
# - NATIVE: std::thread
|
||||||
|
|
|
@ -10,10 +10,10 @@ __all__.files: $(JSON_OBJECTS) inverselist.$(OBJECT_SUFFIX)
|
||||||
touch $(ALLFLAGS)
|
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
|
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
|
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)
|
inverselist.cpp: $(JSON_FILES) mkstubsi$(DOT_EXECUTABLE_SUFFIX)
|
||||||
./mkstubsi$(DOT_EXECUTABLE_SUFFIX) $^
|
./mkstubsi$(DOT_EXECUTABLE_SUFFIX) $^
|
||||||
|
|
|
@ -9,7 +9,7 @@ __all__.files: $(CORES_FILES)
|
||||||
cat $(CORES_FLAGS) >$(ALLFLAGS)
|
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
|
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)
|
bsnes-legacy/$(ALLFILES): forcelook make-ports$(DOT_EXECUTABLE_SUFFIX)
|
||||||
$(MAKE) -C bsnes-legacy
|
$(MAKE) -C bsnes-legacy
|
||||||
|
|
|
@ -3,9 +3,17 @@
|
||||||
#include "threads.hpp"
|
#include "threads.hpp"
|
||||||
#include "eatarg.hpp"
|
#include "eatarg.hpp"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <boost/regex.hpp>
|
|
||||||
#include "map-pointer.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 strip_CR(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string x = 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;
|
static threads::lock m;
|
||||||
threads::alock h(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)) {
|
if(!regexps.count(regexp)) {
|
||||||
boost::regex* y = NULL;
|
regex_ns::regex* y = NULL;
|
||||||
try {
|
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;
|
regexps[regexp] = y;
|
||||||
} catch(std::bad_alloc& e) {
|
} catch(std::bad_alloc& e) {
|
||||||
delete y;
|
delete y;
|
||||||
|
@ -102,8 +110,8 @@ regex_results regex(const std::string& regexp, const std::string& str, const cha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::smatch matches;
|
regex_ns::smatch matches;
|
||||||
bool x = boost::regex_match(str.begin(), str.end(), matches, *(regexps[regexp]));
|
bool x = regex_ns::regex_match(str.begin(), str.end(), matches, *(regexps[regexp]));
|
||||||
if(x) {
|
if(x) {
|
||||||
std::vector<std::string> res;
|
std::vector<std::string> res;
|
||||||
std::vector<std::pair<size_t, size_t>> mch;
|
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)
|
throw(std::bad_alloc, std::runtime_error)
|
||||||
{
|
{
|
||||||
static threads::lock m;
|
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;
|
static std::map<std::pair<regex_match_mode, std::string> , std::pair<std::string, bool>> transform_cache;
|
||||||
std::string _regexp;
|
std::string _regexp;
|
||||||
bool icase = false;
|
bool icase = false;
|
||||||
|
@ -176,12 +184,12 @@ transformed:
|
||||||
transform_cache[key] = std::make_pair(_regexp, icase);
|
transform_cache[key] = std::make_pair(_regexp, icase);
|
||||||
|
|
||||||
if(!regexps.count(regexp)) {
|
if(!regexps.count(regexp)) {
|
||||||
boost::regex* y = NULL;
|
regex_ns::regex* y = NULL;
|
||||||
auto flags = boost::regex::extended & ~boost::regex::collate;
|
auto flags = regex_ns::regex::extended & ~regex_ns::regex::collate;
|
||||||
flags |= boost::regex::nosubs;
|
flags |= regex_ns::regex::nosubs;
|
||||||
if(icase) flags |= boost::regex::icase;
|
if(icase) flags |= regex_ns::regex::icase;
|
||||||
try {
|
try {
|
||||||
y = new boost::regex(_regexp, flags);
|
y = new regex_ns::regex(_regexp, flags);
|
||||||
regexps[_regexp] = y;
|
regexps[_regexp] = y;
|
||||||
} catch(std::bad_alloc& e) {
|
} catch(std::bad_alloc& e) {
|
||||||
delete y;
|
delete y;
|
||||||
|
@ -190,7 +198,7 @@ transformed:
|
||||||
throw std::runtime_error(e.what());
|
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
|
namespace
|
||||||
|
|
Loading…
Add table
Reference in a new issue