Switch to unified view

a/src/utils/strmatcher.cpp b/src/utils/strmatcher.cpp
...
...
17
17
18
#include "autoconfig.h"
18
#include "autoconfig.h"
19
19
20
#include <stdio.h>
20
#include <stdio.h>
21
#include <sys/types.h>
21
#include <sys/types.h>
22
#ifdef _WIN32
23
#include <regex>
24
#else
22
#include <regex.h>
25
#include <regex.h>
26
#endif
23
#include <fnmatch.h>
27
#include <fnmatch.h>
24
28
25
#include <string>
29
#include <string>
26
using std::string;
27
30
28
#include "cstr.h"
31
#include "cstr.h"
29
#include "debuglog.h"
32
#include "debuglog.h"
33
#include "pathut.h"
30
#include "strmatcher.h"
34
#include "strmatcher.h"
31
#include "pathut.h"
35
36
using namespace std;
32
37
33
bool StrWildMatcher::match(const string& val) const
38
bool StrWildMatcher::match(const string& val) const
34
{
39
{
35
    LOGDEB2(("StrWildMatcher::match: [%s] against [%s]\n", 
40
    LOGDEB2(("StrWildMatcher::match: [%s] against [%s]\n", 
36
         m_sexp.c_str(), val.c_str()));
41
         m_sexp.c_str(), val.c_str()));
...
...
58
}
63
}
59
64
60
bool StrRegexpMatcher::setExp(const string& exp)
65
bool StrRegexpMatcher::setExp(const string& exp)
61
{
66
{
62
    if (m_compiled) {
67
    if (m_compiled) {
68
#ifdef _WIN32
69
        delete (regex*)m_compiled;
70
#else
63
    regfree((regex_t*)m_compiled);
71
    regfree((regex_t*)m_compiled);
64
    delete (regex_t*)m_compiled;
72
    delete (regex_t*)m_compiled;
73
#endif
65
    }
74
    }
75
    m_compiled = 0;
76
    
77
#ifdef _WIN32
78
    try {
79
        m_compiled = new regex(exp, std::regex_constants::nosubs | 
80
                               std::regex_constants::extended);
81
    } catch (...) {
82
        m_reason = string("StrRegexpMatcher:regcomp failed for ")
83
      + exp + string("syntax error ?");
84
        return false;
85
    }
86
#else
66
    m_compiled = new regex_t;
87
    m_compiled = new regex_t;
67
    if ((m_errcode = 
88
    if ((m_errcode = 
68
     regcomp((regex_t*)m_compiled, exp.c_str(), REG_EXTENDED|REG_NOSUB))) {
89
     regcomp((regex_t*)m_compiled, exp.c_str(), REG_EXTENDED|REG_NOSUB))) {
69
    char errbuf[200];
90
    char errbuf[200];
70
    regerror(m_errcode, (regex_t*)m_compiled, errbuf, 199);
91
    regerror(m_errcode, (regex_t*)m_compiled, errbuf, 199);
71
    m_reason = string("StrRegexpMatcher:regcomp failed for ")
92
    m_reason = string("StrRegexpMatcher:regcomp failed for ")
72
        + exp + string(errbuf);
93
        + exp + string(errbuf);
73
    return false;
94
    return false;
74
    }
95
    }
96
#endif
75
    m_sexp = exp;
97
    m_sexp = exp;
76
    return true;
98
    return true;
77
}
99
}
78
100
79
StrRegexpMatcher::~StrRegexpMatcher()
101
StrRegexpMatcher::~StrRegexpMatcher()
80
{
102
{
81
    if (m_compiled) {
103
    if (m_compiled) {
104
#ifdef _WIN32
105
        delete (regex *)m_compiled;
106
#else
82
    regfree((regex_t*)m_compiled);
107
    regfree((regex_t*)m_compiled);
83
    delete (regex_t*)m_compiled;
108
    delete (regex_t*)m_compiled;
109
#endif
84
    }
110
    }
85
}
111
}
86
112
87
bool StrRegexpMatcher::match(const string& val) const
113
bool StrRegexpMatcher::match(const string& val) const
88
{
114
{
89
    if (m_errcode) 
115
    if (m_errcode) 
90
    return false;
116
    return false;
117
#ifdef _WIN32
118
    return regex_match(val, *((regex *)m_compiled));
119
#else
91
    return regexec((regex_t*)m_compiled, val.c_str(), 0, 0, 0) != REG_NOMATCH;
120
    return regexec((regex_t*)m_compiled, val.c_str(), 0, 0, 0) != REG_NOMATCH;
121
#endif
92
}
122
}
93
123
94
string::size_type StrRegexpMatcher::baseprefixlen() const
124
string::size_type StrRegexpMatcher::baseprefixlen() const
95
{
125
{
96
    return m_sexp.find_first_of(cstr_regSpecStChars);
126
    return m_sexp.find_first_of(cstr_regSpecStChars);