Use internal PCRE based implementation of regular expressions instead of std C++ regex library.

C++ regex library proven to be unusable for gcc 4.8 and earlier version, so
reimplement code using PCRE library in order to build workable version of
unit_test executable for CentOS 7, RHEL 7, Ubuntu 14 and SUSE Linux 12.
This commit is contained in:
Alexey Zelkin 2016-06-16 13:49:17 +00:00 committed by Felipe Zimmerle
parent 21777aec41
commit 647019a804
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 8 additions and 7 deletions

View File

@ -43,6 +43,7 @@ class SMatch {
public:
SMatch() : size_(0) { }
size_t size() { return size_; }
std::string str() { return match; }
int size_;
std::string match;
};

View File

@ -21,11 +21,11 @@
#include <string>
#include <iostream>
#include <iterator>
#include <regex>
#include <string>
#include "common/colors.h"
#include "src/utils.h"
#include "src/utils/regex.h"
namespace modsecurity_test {
@ -44,7 +44,6 @@ std::string string_to_hex(const std::string& input) {
return output;
}
void replaceAll(std::string *s, const std::string &search,
const char replace) {
for (size_t pos = 0; ; pos += 0) {
@ -59,18 +58,19 @@ void replaceAll(std::string *s, const std::string &search,
void json2bin(std::string *str) {
std::regex re("\\\\x([a-z0-9A-Z]{2})");
std::regex re2("\\\\u([a-z0-9A-Z]{4})");
std::smatch match;
modsecurity::Utils::Regex re("\\\\x([a-z0-9A-Z]{2})");
modsecurity::Utils::Regex re2("\\\\u([a-z0-9A-Z]{4})");
modsecurity::Utils::SMatch match;
while (std::regex_search(*str, match, re) && match.size() > 1) {
while (modsecurity::Utils::regex_search(*str, &match, re) && match.size() > 0) {
unsigned int p;
std::string toBeReplaced = match.str();
toBeReplaced.erase(0, 2);
sscanf(toBeReplaced.c_str(), "%x", &p);
replaceAll(str, match.str(), p);
}
while (std::regex_search(*str, match, re2) && match.size() > 1) {
while (modsecurity::Utils::regex_search(*str, &match, re2) && match.size() > 0) {
unsigned int p;
std::string toBeReplaced = match.str();
toBeReplaced.erase(0, 2);