use std::regex instead of boost::regex when available

This commit is contained in:
Wolfgang Thaller 2014-09-17 02:11:26 +02:00
parent ff0586d7f7
commit d83818476d
3 changed files with 41 additions and 18 deletions

View File

@ -18,9 +18,25 @@
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "--std=c++0x")
find_package(Boost COMPONENTS regex)
set(USE_BOOST_REGEX FALSE CACHE BOOL "Force use of boost for regular expressions")
if(CMAKE_COMPILER_IS_GNUCXX)
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.9)
set(USE_BOOST_REGEX TRUE)
message(STATUS "forcing use of boost::regex")
endif()
endif()
if(USE_BOOST_REGEX)
add_definitions(-DUSE_BOOST_REGEX)
find_package(Boost COMPONENTS regex)
endif()
add_executable(asfilter asfilter.cc)
target_link_libraries(asfilter ${Boost_LIBRARIES})
if(USE_BOOST_REGEX)
target_link_libraries(asfilter ${Boost_LIBRARIES})
endif()
install(TARGETS asfilter RUNTIME DESTINATION bin)

View File

@ -25,10 +25,17 @@
#include <functional>
#include <errno.h>
#include <fstream>
#include <boost/regex.hpp>
using namespace std::placeholders;
#ifdef USE_BOOST_REGEX
#include <boost/regex.hpp>
namespace rx = boost;
#else
#include <regex>
namespace rx = std;
#endif
int main(int argc, char *argv[])
{
std::vector<std::string> argv2;
@ -50,7 +57,7 @@ int main(int argc, char *argv[])
{
inputFileName = p;
p = tempFileName;
std::cerr << "Temp file: " << tempFileName << std::endl;
//std::cerr << "Temp file: " << tempFileName << std::endl;
}
}
@ -59,11 +66,11 @@ int main(int argc, char *argv[])
std::ofstream out(tempFileName);
std::string wordS = "[0-9a-f][0-9a-f][0-9a-f][0-9a-f]";
boost::regex jsr("\tjsr __magic_inline_(" + wordS + "(_" + wordS + ")*)");
boost::regex word(wordS);
//boost::regex size("\t\\.size\t([a-zA-Z0-9_]+), \\.-([a-zA-Z0-9_]+)");
boost::regex globl("\t\\.globl\t([a-zA-Z0-9_]+)");
boost::regex rts("\trts");
rx::regex jsr("\tjsr __magic_inline_(" + wordS + "(_" + wordS + ")*)");
rx::regex word(wordS);
//std::regex size("\t\\.size\t([a-zA-Z0-9_]+), \\.-([a-zA-Z0-9_]+)");
rx::regex globl("\t\\.globl\t([a-zA-Z0-9_]+)");
rx::regex rts("\trts");
std::string function_name = "__unknown";
while(in)
@ -73,30 +80,30 @@ int main(int argc, char *argv[])
if(!in)
break;
boost::smatch match;
if(boost::regex_match(line, match, jsr))
rx::smatch match;
if(rx::regex_match(line, match, jsr))
{
const boost::sregex_token_iterator end;
for (boost::sregex_token_iterator p(line.cbegin(), line.cend(), word);
const rx::sregex_token_iterator end;
for (rx::sregex_token_iterator p(line.cbegin(), line.cend(), word);
p != end;
++p)
{
out << "\tdc.w 0x" << *p << std::endl;
}
}
/*else if(boost::regex_match(line, match, size) && match[1] == match[2])
/*else if(rx::regex_match(line, match, size) && match[1] == match[2])
{
out << "\tdc.b 0x8e\n";
out << "\t.string \"" << match[1] << "\"\n";
out << "\t.align 2\n";
out << line << std::endl;
}*/
else if(boost::regex_match(line, match, globl))
else if(rx::regex_match(line, match, globl))
{
out << line << std::endl;
function_name = match[1];
}
/*else if(boost::regex_match(line, rts))
/*else if(rx::regex_match(line, rts))
{
out << line << std::endl;
out << "\tdc.b 0x8e\n";

View File

@ -13,8 +13,8 @@ Prerequisites
-------------
- Linux or Mac OS X
- boost, if using gcc 4.8 or earlier to compile on Linux
- CMake 2.8
- boost
- Glasgow Haskell Compiler (GHC)
- GCC dependencies: GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
- Apple Universal Interfaces (tested with version 3.1 - see below)
@ -22,7 +22,7 @@ Prerequisites
For Ubuntu Linux, the following should help a bit:
sudo apt-get install cmake ghc libboost-dev libgmp-dev libmpfr-dev libmpc-dev
sudo apt-get install cmake ghc libgmp-dev libmpfr-dev libmpc-dev
On a Mac, get the homebrew package manager and: